summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/GVN.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-11-28 16:08:18 +0000
committerChris Lattner <sabre@nondot.org>2009-11-28 16:08:18 +0000
commit32140312ca6e6a17733f95554094245b9fad0b46 (patch)
treef6dd90f1b0c9009a18b568769f2c59531a9e3ae2 /llvm/lib/Transforms/Scalar/GVN.cpp
parent930de0aeaf7e13167cdebd200a8cd6ba7b67c1ba (diff)
downloadbcm5719-llvm-32140312ca6e6a17733f95554094245b9fad0b46.tar.gz
bcm5719-llvm-32140312ca6e6a17733f95554094245b9fad0b46.zip
reenable load address insertion in load pre. This allows us to
handle cases like this: void test(int N, double* G) { long j; for (j = 1; j < N - 1; j++) G[j+1] = G[j] + G[j+1]; } where G[1] isn't live into the loop. llvm-svn: 90041
Diffstat (limited to 'llvm/lib/Transforms/Scalar/GVN.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/GVN.cpp30
1 files changed, 19 insertions, 11 deletions
diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp
index 6311491c7d3..6f1c32c004e 100644
--- a/llvm/lib/Transforms/Scalar/GVN.cpp
+++ b/llvm/lib/Transforms/Scalar/GVN.cpp
@@ -1438,16 +1438,19 @@ bool GVN::processNonLocalLoad(LoadInst *LI,
// FIXME: This may insert a computation, but we don't tell scalar GVN
// optimization stuff about it. How do we do this?
SmallVector<Instruction*, 8> NewInsts;
-#if 0
- Value *LoadPtr =
- MD->InsertPHITranslatedPointer(LI->getOperand(0), LoadBB,
- UnavailablePred, TD, *DT, NewInsts);
-#else
- Value *LoadPtr =
- MD->GetAvailablePHITranslatedValue(LI->getOperand(0), LoadBB,
- UnavailablePred, TD, *DT);
-#endif
+ Value *LoadPtr = 0;
+ // If all preds have a single successor, then we know it is safe to insert the
+ // load on the pred (?!?), so we can insert code to materialize the pointer if
+ // it is not available.
+ if (allSingleSucc) {
+ LoadPtr = MD->InsertPHITranslatedPointer(LI->getOperand(0), LoadBB,
+ UnavailablePred, TD, *DT,NewInsts);
+ } else {
+ LoadPtr = MD->GetAvailablePHITranslatedValue(LI->getOperand(0), LoadBB,
+ UnavailablePred, TD, *DT);
+ }
+
// If we couldn't find or insert a computation of this phi translated value,
// we fail PRE.
if (LoadPtr == 0) {
@@ -1467,14 +1470,19 @@ bool GVN::processNonLocalLoad(LoadInst *LI,
// put anywhere; this can be improved, but should be conservatively safe.
if (!allSingleSucc &&
// FIXME: REEVALUTE THIS.
- !isSafeToLoadUnconditionally(LoadPtr, UnavailablePred->getTerminator()))
+ !isSafeToLoadUnconditionally(LoadPtr, UnavailablePred->getTerminator())) {
+ assert(NewInsts.empty() && "Should not have inserted instructions");
return false;
+ }
// Okay, we can eliminate this load by inserting a reload in the predecessor
// and using PHI construction to get the value in the other predecessors, do
// it.
DEBUG(errs() << "GVN REMOVING PRE LOAD: " << *LI << '\n');
-
+ DEBUG(if (!NewInsts.empty())
+ errs() << "INSERTED " << NewInsts.size() << " INSTS: "
+ << *NewInsts.back() << '\n');
+
Value *NewLoad = new LoadInst(LoadPtr, LI->getName()+".pre", false,
LI->getAlignment(),
UnavailablePred->getTerminator());
OpenPOWER on IntegriCloud