Speculatively revert r97010, "Add an argument to PHITranslateValue to specify

the DominatorTree. ...", in hopes of restoring poor old PPC bootstrap.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97027 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Daniel Dunbar 2010-02-24 06:55:22 +00:00
parent e832693acb
commit 8c0c99016b
4 changed files with 50 additions and 37 deletions

View File

@ -66,11 +66,9 @@ public:
bool IsPotentiallyPHITranslatable() const; bool IsPotentiallyPHITranslatable() const;
/// PHITranslateValue - PHI translate the current address up the CFG from /// PHITranslateValue - PHI translate the current address up the CFG from
/// CurBB to Pred, updating our state to reflect any needed changes. If the /// CurBB to Pred, updating our state the reflect any needed changes. This
/// dominator tree DT is non-null, the translated value must dominate /// returns true on failure and sets Addr to null.
/// PredBB. This returns true on failure and sets Addr to null. bool PHITranslateValue(BasicBlock *CurBB, BasicBlock *PredBB);
bool PHITranslateValue(BasicBlock *CurBB, BasicBlock *PredBB,
const DominatorTree *DT);
/// PHITranslateWithInsertion - PHI translate this value into the specified /// PHITranslateWithInsertion - PHI translate this value into the specified
/// predecessor block, inserting a computation of the value if it is /// predecessor block, inserting a computation of the value if it is
@ -90,8 +88,14 @@ public:
/// returns false. /// returns false.
bool Verify() const; bool Verify() const;
private: private:
Value *PHITranslateSubExpr(Value *V, BasicBlock *CurBB, BasicBlock *PredBB, Value *PHITranslateSubExpr(Value *V, BasicBlock *CurBB, BasicBlock *PredBB);
const DominatorTree *DT);
/// GetAvailablePHITranslatedSubExpr - Return the value computed by
/// PHITranslateSubExpr if it dominates PredBB, otherwise return null.
Value *GetAvailablePHITranslatedSubExpr(Value *V,
BasicBlock *CurBB, BasicBlock *PredBB,
const DominatorTree &DT) const;
/// InsertPHITranslatedSubExpr - Insert a computation of the PHI translated /// InsertPHITranslatedSubExpr - Insert a computation of the PHI translated
/// version of 'V' for the edge PredBB->CurBB into the end of the PredBB /// version of 'V' for the edge PredBB->CurBB into the end of the PredBB

View File

@ -861,7 +861,7 @@ getNonLocalPointerDepFromBB(const PHITransAddr &Pointer, uint64_t PointeeSize,
// Get the PHI translated pointer in this predecessor. This can fail if // Get the PHI translated pointer in this predecessor. This can fail if
// not translatable, in which case the getAddr() returns null. // not translatable, in which case the getAddr() returns null.
PHITransAddr PredPointer(Pointer); PHITransAddr PredPointer(Pointer);
PredPointer.PHITranslateValue(BB, Pred, 0); PredPointer.PHITranslateValue(BB, Pred);
Value *PredPtrVal = PredPointer.getAddr(); Value *PredPtrVal = PredPointer.getAddr();

View File

@ -134,8 +134,7 @@ static void RemoveInstInputs(Value *V,
} }
Value *PHITransAddr::PHITranslateSubExpr(Value *V, BasicBlock *CurBB, Value *PHITransAddr::PHITranslateSubExpr(Value *V, BasicBlock *CurBB,
BasicBlock *PredBB, BasicBlock *PredBB) {
const DominatorTree *DT) {
// If this is a non-instruction value, it can't require PHI translation. // If this is a non-instruction value, it can't require PHI translation.
Instruction *Inst = dyn_cast<Instruction>(V); Instruction *Inst = dyn_cast<Instruction>(V);
if (Inst == 0) return V; if (Inst == 0) return V;
@ -178,7 +177,7 @@ Value *PHITransAddr::PHITranslateSubExpr(Value *V, BasicBlock *CurBB,
// operands need to be phi translated, and if so, reconstruct it. // operands need to be phi translated, and if so, reconstruct it.
if (BitCastInst *BC = dyn_cast<BitCastInst>(Inst)) { if (BitCastInst *BC = dyn_cast<BitCastInst>(Inst)) {
Value *PHIIn = PHITranslateSubExpr(BC->getOperand(0), CurBB, PredBB, DT); Value *PHIIn = PHITranslateSubExpr(BC->getOperand(0), CurBB, PredBB);
if (PHIIn == 0) return 0; if (PHIIn == 0) return 0;
if (PHIIn == BC->getOperand(0)) if (PHIIn == BC->getOperand(0))
return BC; return BC;
@ -194,8 +193,7 @@ Value *PHITransAddr::PHITranslateSubExpr(Value *V, BasicBlock *CurBB,
for (Value::use_iterator UI = PHIIn->use_begin(), E = PHIIn->use_end(); for (Value::use_iterator UI = PHIIn->use_begin(), E = PHIIn->use_end();
UI != E; ++UI) { UI != E; ++UI) {
if (BitCastInst *BCI = dyn_cast<BitCastInst>(*UI)) if (BitCastInst *BCI = dyn_cast<BitCastInst>(*UI))
if (BCI->getType() == BC->getType() && if (BCI->getType() == BC->getType())
(!DT || DT->dominates(BCI->getParent(), PredBB)))
return BCI; return BCI;
} }
return 0; return 0;
@ -206,7 +204,7 @@ Value *PHITransAddr::PHITranslateSubExpr(Value *V, BasicBlock *CurBB,
SmallVector<Value*, 8> GEPOps; SmallVector<Value*, 8> GEPOps;
bool AnyChanged = false; bool AnyChanged = false;
for (unsigned i = 0, e = GEP->getNumOperands(); i != e; ++i) { for (unsigned i = 0, e = GEP->getNumOperands(); i != e; ++i) {
Value *GEPOp = PHITranslateSubExpr(GEP->getOperand(i), CurBB, PredBB, DT); Value *GEPOp = PHITranslateSubExpr(GEP->getOperand(i), CurBB, PredBB);
if (GEPOp == 0) return 0; if (GEPOp == 0) return 0;
AnyChanged |= GEPOp != GEP->getOperand(i); AnyChanged |= GEPOp != GEP->getOperand(i);
@ -231,8 +229,7 @@ Value *PHITransAddr::PHITranslateSubExpr(Value *V, BasicBlock *CurBB,
if (GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(*UI)) if (GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(*UI))
if (GEPI->getType() == GEP->getType() && if (GEPI->getType() == GEP->getType() &&
GEPI->getNumOperands() == GEPOps.size() && GEPI->getNumOperands() == GEPOps.size() &&
GEPI->getParent()->getParent() == CurBB->getParent() && GEPI->getParent()->getParent() == CurBB->getParent()) {
(!DT || DT->dominates(GEPI->getParent(), PredBB))) {
bool Mismatch = false; bool Mismatch = false;
for (unsigned i = 0, e = GEPOps.size(); i != e; ++i) for (unsigned i = 0, e = GEPOps.size(); i != e; ++i)
if (GEPI->getOperand(i) != GEPOps[i]) { if (GEPI->getOperand(i) != GEPOps[i]) {
@ -254,7 +251,7 @@ Value *PHITransAddr::PHITranslateSubExpr(Value *V, BasicBlock *CurBB,
bool isNSW = cast<BinaryOperator>(Inst)->hasNoSignedWrap(); bool isNSW = cast<BinaryOperator>(Inst)->hasNoSignedWrap();
bool isNUW = cast<BinaryOperator>(Inst)->hasNoUnsignedWrap(); bool isNUW = cast<BinaryOperator>(Inst)->hasNoUnsignedWrap();
Value *LHS = PHITranslateSubExpr(Inst->getOperand(0), CurBB, PredBB, DT); Value *LHS = PHITranslateSubExpr(Inst->getOperand(0), CurBB, PredBB);
if (LHS == 0) return 0; if (LHS == 0) return 0;
// If the PHI translated LHS is an add of a constant, fold the immediates. // If the PHI translated LHS is an add of a constant, fold the immediates.
@ -290,8 +287,7 @@ Value *PHITransAddr::PHITranslateSubExpr(Value *V, BasicBlock *CurBB,
if (BinaryOperator *BO = dyn_cast<BinaryOperator>(*UI)) if (BinaryOperator *BO = dyn_cast<BinaryOperator>(*UI))
if (BO->getOpcode() == Instruction::Add && if (BO->getOpcode() == Instruction::Add &&
BO->getOperand(0) == LHS && BO->getOperand(1) == RHS && BO->getOperand(0) == LHS && BO->getOperand(1) == RHS &&
BO->getParent()->getParent() == CurBB->getParent() && BO->getParent()->getParent() == CurBB->getParent())
(!DT || DT->dominates(BO->getParent(), PredBB)))
return BO; return BO;
} }
@ -304,25 +300,34 @@ Value *PHITransAddr::PHITranslateSubExpr(Value *V, BasicBlock *CurBB,
/// PHITranslateValue - PHI translate the current address up the CFG from /// PHITranslateValue - PHI translate the current address up the CFG from
/// CurBB to Pred, updating our state to reflect any needed changes. If the /// CurBB to Pred, updating our state the reflect any needed changes. This
/// dominator tree DT is non-null, the translated value must dominate /// returns true on failure and sets Addr to null.
/// PredBB. This returns true on failure and sets Addr to null. bool PHITransAddr::PHITranslateValue(BasicBlock *CurBB, BasicBlock *PredBB) {
bool PHITransAddr::PHITranslateValue(BasicBlock *CurBB, BasicBlock *PredBB,
const DominatorTree *DT) {
assert(Verify() && "Invalid PHITransAddr!"); assert(Verify() && "Invalid PHITransAddr!");
Addr = PHITranslateSubExpr(Addr, CurBB, PredBB, DT); Addr = PHITranslateSubExpr(Addr, CurBB, PredBB);
assert(Verify() && "Invalid PHITransAddr!"); assert(Verify() && "Invalid PHITransAddr!");
if (DT) {
// Make sure the value is live in the predecessor.
if (Instruction *Inst = dyn_cast_or_null<Instruction>(Addr))
if (!DT->dominates(Inst->getParent(), PredBB))
Addr = 0;
}
return Addr == 0; return Addr == 0;
} }
/// GetAvailablePHITranslatedSubExpr - Return the value computed by
/// PHITranslateSubExpr if it dominates PredBB, otherwise return null.
Value *PHITransAddr::
GetAvailablePHITranslatedSubExpr(Value *V, BasicBlock *CurBB,BasicBlock *PredBB,
const DominatorTree &DT) const {
PHITransAddr Tmp(V, TD);
Tmp.PHITranslateValue(CurBB, PredBB);
// See if PHI translation succeeds.
V = Tmp.getAddr();
// Make sure the value is live in the predecessor.
if (Instruction *Inst = dyn_cast_or_null<Instruction>(V))
if (!DT.dominates(Inst->getParent(), PredBB))
return 0;
return V;
}
/// PHITranslateWithInsertion - PHI translate this value into the specified /// PHITranslateWithInsertion - PHI translate this value into the specified
/// predecessor block, inserting a computation of the value if it is /// predecessor block, inserting a computation of the value if it is
/// unavailable. /// unavailable.
@ -360,9 +365,8 @@ InsertPHITranslatedSubExpr(Value *InVal, BasicBlock *CurBB,
SmallVectorImpl<Instruction*> &NewInsts) { SmallVectorImpl<Instruction*> &NewInsts) {
// See if we have a version of this value already available and dominating // See if we have a version of this value already available and dominating
// PredBB. If so, there is no need to insert a new instance of it. // PredBB. If so, there is no need to insert a new instance of it.
PHITransAddr Tmp(InVal, TD); if (Value *Res = GetAvailablePHITranslatedSubExpr(InVal, CurBB, PredBB, DT))
if (!Tmp.PHITranslateValue(CurBB, PredBB, &DT)) return Res;
return Tmp.getAddr();
// If we don't have an available version of this value, it must be an // If we don't have an available version of this value, it must be an
// instruction. // instruction.

View File

@ -1633,8 +1633,13 @@ bool GVN::processNonLocalLoad(LoadInst *LI,
LoadPtr = Address.PHITranslateWithInsertion(LoadBB, UnavailablePred, LoadPtr = Address.PHITranslateWithInsertion(LoadBB, UnavailablePred,
*DT, NewInsts); *DT, NewInsts);
} else { } else {
Address.PHITranslateValue(LoadBB, UnavailablePred, DT); Address.PHITranslateValue(LoadBB, UnavailablePred);
LoadPtr = Address.getAddr(); LoadPtr = Address.getAddr();
// Make sure the value is live in the predecessor.
if (Instruction *Inst = dyn_cast_or_null<Instruction>(LoadPtr))
if (!DT->dominates(Inst->getParent(), UnavailablePred))
LoadPtr = 0;
} }
// If we couldn't find or insert a computation of this phi translated value, // If we couldn't find or insert a computation of this phi translated value,