[llvm-commits] [llvm] r89992 - in /llvm/trunk: include/llvm/Analysis/MemoryDependenceAnalysis.h lib/Analysis/MemoryDependenceAnalysis.cpp lib/Transforms/Scalar/GVN.cpp test/Transforms/GVN/rle-phi-translate.ll
Chris Lattner
sabre at nondot.org
Thu Nov 26 22:31:14 PST 2009
Author: lattner
Date: Fri Nov 27 00:31:14 2009
New Revision: 89992
URL: http://llvm.org/viewvc/llvm-project?rev=89992&view=rev
Log:
Fix phi translation in load PRE to agree with the phi
translation done by memdep, and reenable gep translation
again.
Modified:
llvm/trunk/include/llvm/Analysis/MemoryDependenceAnalysis.h
llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp
llvm/trunk/lib/Transforms/Scalar/GVN.cpp
llvm/trunk/test/Transforms/GVN/rle-phi-translate.ll
Modified: llvm/trunk/include/llvm/Analysis/MemoryDependenceAnalysis.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/MemoryDependenceAnalysis.h?rev=89992&r1=89991&r2=89992&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/MemoryDependenceAnalysis.h (original)
+++ llvm/trunk/include/llvm/Analysis/MemoryDependenceAnalysis.h Fri Nov 27 00:31:14 2009
@@ -244,6 +244,13 @@
BasicBlock *BB,
SmallVectorImpl<NonLocalDepEntry> &Result);
+ /// PHITranslatePointer - Find an available version of the specified value
+ /// PHI translated across the specified edge. If MemDep isn't able to
+ /// satisfy this request, it returns null.
+ Value *PHITranslatePointer(Value *V,
+ BasicBlock *CurBB, BasicBlock *PredBB,
+ const TargetData *TD) const;
+
/// removeInstruction - Remove an instruction from the dependence analysis,
/// updating the dependence of instructions that previously depended on it.
void removeInstruction(Instruction *InstToRemove);
Modified: llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp?rev=89992&r1=89991&r2=89992&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp Fri Nov 27 00:31:14 2009
@@ -700,7 +700,6 @@
// We can translate a GEP that uses a PHI in the current block for at least
// one of its operands.
- if (0)
if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(Inst)) {
for (unsigned i = 0, e = GEP->getNumOperands(); i != e; ++i)
if (PHINode *PN = dyn_cast<PHINode>(GEP->getOperand(i)))
@@ -718,8 +717,15 @@
/// PHITranslateForPred - Given a computation that satisfied the
/// isPHITranslatable predicate, see if we can translate the computation into
/// the specified predecessor block. If so, return that value.
-static Value *PHITranslateForPred(Instruction *Inst, BasicBlock *Pred,
- const TargetData *TD) {
+Value *MemoryDependenceAnalysis::
+PHITranslatePointer(Value *InVal, BasicBlock *CurBB, BasicBlock *Pred,
+ const TargetData *TD) const {
+ // If the input value is not an instruction, or if it is not defined in CurBB,
+ // then we don't need to phi translate it.
+ Instruction *Inst = dyn_cast<Instruction>(InVal);
+ if (Inst == 0 || Inst->getParent() != CurBB)
+ return InVal;
+
if (PHINode *PN = dyn_cast<PHINode>(Inst))
return PN->getIncomingValueForBlock(Pred);
@@ -931,7 +937,7 @@
for (BasicBlock **PI = PredCache->GetPreds(BB); *PI; ++PI) {
BasicBlock *Pred = *PI;
- Value *PredPtr = PHITranslateForPred(PtrInst, Pred, TD);
+ Value *PredPtr = PHITranslatePointer(PtrInst, BB, Pred, TD);
// If PHI translation fails, bail out.
if (PredPtr == 0)
Modified: llvm/trunk/lib/Transforms/Scalar/GVN.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/GVN.cpp?rev=89992&r1=89991&r2=89992&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/GVN.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/GVN.cpp Fri Nov 27 00:31:14 2009
@@ -1427,13 +1427,19 @@
// If the loaded pointer is PHI node defined in this block, do PHI translation
// to get its value in the predecessor.
- Value *LoadPtr = LI->getOperand(0)->DoPHITranslation(LoadBB, UnavailablePred);
+ Value *LoadPtr = MD->PHITranslatePointer(LI->getOperand(0),
+ LoadBB, UnavailablePred, TD);
+ if (LoadPtr == 0) {
+ DEBUG(errs() << "COULDN'T PRE LOAD BECAUSE PTR CAN'T BE PHI TRANSLATED: "
+ << *LI->getOperand(0) << '\n' << *LI << "\n");
+ return false;
+ }
// Make sure the value is live in the predecessor. If it was defined by a
// non-PHI instruction in this block, we don't know how to recompute it above.
if (Instruction *LPInst = dyn_cast<Instruction>(LoadPtr))
if (!DT->dominates(LPInst->getParent(), UnavailablePred)) {
- DEBUG(errs() << "COULDN'T PRE LOAD BECAUSE PTR IS UNAVAILABLE IN PRED: "
+ DEBUG(errs() << "COULDN'T PRE LOAD BECAUSE PTR DOES NOT DOMINATE PRED: "
<< *LPInst << '\n' << *LI << "\n");
return false;
}
Modified: llvm/trunk/test/Transforms/GVN/rle-phi-translate.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GVN/rle-phi-translate.ll?rev=89992&r1=89991&r2=89992&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/GVN/rle-phi-translate.ll (original)
+++ llvm/trunk/test/Transforms/GVN/rle-phi-translate.ll Fri Nov 27 00:31:14 2009
@@ -80,9 +80,9 @@
%i = phi i32 [ 7, %bb1 ], [ 17, %bb ]
%d1 = getelementptr i32* %d, i32 %i
%dv = load i32* %d1
-; HECK: %dv = phi i32 [ 82, %bb1 ], [ 4, %bb ]
-; HECK-NOT: load
-; HECK: ret i32 %dv
+; CHECK: %dv = phi i32 [ 82, %bb1 ], [ 4, %bb ]
+; CHECK-NOT: load
+; CHECK: ret i32 %dv
ret i32 %dv
}
@@ -106,9 +106,9 @@
%i = phi i32 [ 7, %bb1 ], [ 0, %bb ]
%d1 = getelementptr i32* %d, i32 %i
%dv = load i32* %d1
-; HECK: %dv = phi i32 [ 82, %bb1 ], [ 4, %bb ]
-; HECK-NOT: load
-; HECK: ret i32 %dv
+; CHECK: %dv = phi i32 [ 82, %bb1 ], [ 4, %bb ]
+; CHECK-NOT: load
+; CHECK: ret i32 %dv
ret i32 %dv
}
More information about the llvm-commits
mailing list