[llvm-commits] [llvm] r47006 - /llvm/trunk/lib/Transforms/Scalar/GVN.cpp
Eli Friedman
eli.friedman at gmail.com
Tue Feb 12 04:08:19 PST 2008
Author: efriedma
Date: Tue Feb 12 06:08:14 2008
New Revision: 47006
URL: http://llvm.org/viewvc/llvm-project?rev=47006&view=rev
Log:
Fix for bug 1996: optimize out loads of undef. This code basically just
checks for a malloc/alloca immediately followed by a load.
Modified:
llvm/trunk/lib/Transforms/Scalar/GVN.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/GVN.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/GVN.cpp?rev=47006&r1=47005&r2=47006&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/GVN.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/GVN.cpp Tue Feb 12 06:08:14 2008
@@ -1010,7 +1010,34 @@
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;
More information about the llvm-commits
mailing list