summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2008-02-12 12:08:14 +0000
committerEli Friedman <eli.friedman@gmail.com>2008-02-12 12:08:14 +0000
commit716c10c01e9f8105fa2759902ac6d70590cb366a (patch)
tree28f9802bfe84d663917db9c0f51725e08212b859 /llvm/lib/Transforms
parenta7bf7ed4768569c53f78e8e02f82d52f3daefbe4 (diff)
downloadbcm5719-llvm-716c10c01e9f8105fa2759902ac6d70590cb366a.tar.gz
bcm5719-llvm-716c10c01e9f8105fa2759902ac6d70590cb366a.zip
Fix for bug 1996: optimize out loads of undef. This code basically just
checks for a malloc/alloca immediately followed by a load. llvm-svn: 47006
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/GVN.cpp29
1 files changed, 28 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp
index 42d7a939705..69f06909f6c 100644
--- a/llvm/lib/Transforms/Scalar/GVN.cpp
+++ b/llvm/lib/Transforms/Scalar/GVN.cpp
@@ -1010,7 +1010,34 @@ bool GVN::processLoad(LoadInst* L,
dep = MD.getDependency(L, dep);
}
}
-
+
+ if (dep != MemoryDependenceAnalysis::None &&
+ dep != MemoryDependenceAnalysis::NonLocal &&
+ isa<AllocationInst>(dep)) {
+ // Check that this load is actually from the
+ // allocation we found
+ Value* v = L->getOperand(0);
+ while (true) {
+ if (BitCastInst *BC = dyn_cast<BitCastInst>(v))
+ v = BC->getOperand(0);
+ else if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(v))
+ v = GEP->getOperand(0);
+ else
+ break;
+ }
+ if (v == dep) {
+ // If this load depends directly on an allocation, there isn't
+ // anything stored there; therefore, we can optimize this load
+ // to undef.
+ MD.removeInstruction(L);
+
+ L->replaceAllUsesWith(UndefValue::get(L->getType()));
+ toErase.push_back(L);
+ deletedLoad = true;
+ NumGVNLoad++;
+ }
+ }
+
if (!deletedLoad)
last = L;
OpenPOWER on IntegriCloud