summaryrefslogtreecommitdiff
path: root/lib/Transforms/Scalar/DeadStoreElimination.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-11-04 23:20:12 +0000
committerChris Lattner <sabre@nondot.org>2009-11-04 23:20:12 +0000
commit40dd12e7080c5df253fd70b468368e3144a43c0c (patch)
treecb6e64bcd70c0e746fddf37eb7e42da2a16ef874 /lib/Transforms/Scalar/DeadStoreElimination.cpp
parentdb1751a9222dbfc62e6d7c2ec0b084d353068931 (diff)
downloadllvm-40dd12e7080c5df253fd70b468368e3144a43c0c.tar.gz
llvm-40dd12e7080c5df253fd70b468368e3144a43c0c.tar.bz2
llvm-40dd12e7080c5df253fd70b468368e3144a43c0c.tar.xz
improve DSE when TargetData is not around, based on work by
Hans Wennborg! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86067 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/DeadStoreElimination.cpp')
-rw-r--r--lib/Transforms/Scalar/DeadStoreElimination.cpp19
1 files changed, 16 insertions, 3 deletions
diff --git a/lib/Transforms/Scalar/DeadStoreElimination.cpp b/lib/Transforms/Scalar/DeadStoreElimination.cpp
index 60b12fd867..90436f4066 100644
--- a/lib/Transforms/Scalar/DeadStoreElimination.cpp
+++ b/lib/Transforms/Scalar/DeadStoreElimination.cpp
@@ -78,6 +78,21 @@ static RegisterPass<DSE> X("dse", "Dead Store Elimination");
FunctionPass *llvm::createDeadStoreEliminationPass() { return new DSE(); }
+/// isValueAtLeastAsBigAs - Return true if V1 is greater than or equal to the
+/// stored size of V2. This returns false if we don't know.
+///
+static bool isValueAtLeastAsBigAs(Value *V1, Value *V2, const TargetData *TD) {
+ const Type *V1Ty = V1->getType(), *V2Ty = V2->getType();
+
+ // Exactly the same type, must have exactly the same size.
+ if (V1Ty == V2Ty) return true;
+
+ // If we don't have target data, we don't know.
+ if (TD == 0) return false;
+
+ return TD->getTypeStoreSize(V1Ty) >= TD->getTypeStoreSize(V2Ty);
+}
+
bool DSE::runOnBasicBlock(BasicBlock &BB) {
MemoryDependenceAnalysis& MD = getAnalysis<MemoryDependenceAnalysis>();
TD = getAnalysisIfAvailable<TargetData>();
@@ -118,9 +133,7 @@ bool DSE::runOnBasicBlock(BasicBlock &BB) {
// If this is a store-store dependence, then the previous store is dead so
// long as this store is at least as big as it.
if (StoreInst *DepStore = dyn_cast<StoreInst>(InstDep.getInst()))
- if (TD &&
- TD->getTypeStoreSize(DepStore->getOperand(0)->getType()) <=
- TD->getTypeStoreSize(SI->getOperand(0)->getType())) {
+ if (isValueAtLeastAsBigAs(SI->getOperand(0), DepStore->getOperand(0),TD)){
// Delete the store and now-dead instructions that feed it.
DeleteDeadInstruction(DepStore);
NumFastStores++;