From 62deff066c5ee4474be80ed2d95aca010e237343 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 27 Nov 2009 06:31:14 +0000 Subject: Fix phi translation in load PRE to agree with the phi translation done by memdep, and reenable gep translation again. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@89992 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/MemoryDependenceAnalysis.cpp | 14 ++++++++++---- lib/Transforms/Scalar/GVN.cpp | 10 ++++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/Analysis/MemoryDependenceAnalysis.cpp b/lib/Analysis/MemoryDependenceAnalysis.cpp index f36a2207d6..bb5b76cef9 100644 --- a/lib/Analysis/MemoryDependenceAnalysis.cpp +++ b/lib/Analysis/MemoryDependenceAnalysis.cpp @@ -700,7 +700,6 @@ static bool isPHITranslatable(Instruction *Inst) { // 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(Inst)) { for (unsigned i = 0, e = GEP->getNumOperands(); i != e; ++i) if (PHINode *PN = dyn_cast(GEP->getOperand(i))) @@ -718,8 +717,15 @@ static bool isPHITranslatable(Instruction *Inst) { /// 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(InVal); + if (Inst == 0 || Inst->getParent() != CurBB) + return InVal; + if (PHINode *PN = dyn_cast(Inst)) return PN->getIncomingValueForBlock(Pred); @@ -931,7 +937,7 @@ getNonLocalPointerDepFromBB(Value *Pointer, uint64_t PointeeSize, 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) diff --git a/lib/Transforms/Scalar/GVN.cpp b/lib/Transforms/Scalar/GVN.cpp index a8f39c1433..e878050364 100644 --- a/lib/Transforms/Scalar/GVN.cpp +++ b/lib/Transforms/Scalar/GVN.cpp @@ -1427,13 +1427,19 @@ bool GVN::processNonLocalLoad(LoadInst *LI, // 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(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; } -- cgit v1.2.3