fix many input tracking bugs.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@90915 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2009-12-09 00:56:14 +00:00
parent c0d91b75f0
commit 6200e53f55
2 changed files with 40 additions and 40 deletions

View File

@@ -106,10 +106,13 @@ private:
BasicBlock *PredBB, const DominatorTree &DT, BasicBlock *PredBB, const DominatorTree &DT,
SmallVectorImpl<Instruction*> &NewInsts); SmallVectorImpl<Instruction*> &NewInsts);
/// ReplaceInstWithValue - Remove any instruction inputs in the InstInputs /// AddAsInput - If the specified value is an instruction, add it as an input.
/// array that are due to the specified instruction that is about to be Value *AddAsInput(Value *V) {
/// removed from the address, and add any corresponding to V. This returns V. // If V is an instruction, it is now an input.
Value *ReplaceInstWithValue(Instruction *I, Value *V); if (Instruction *VI = dyn_cast<Instruction>(V))
InstInputs.push_back(VI);
return V;
}
}; };

View File

@@ -110,8 +110,11 @@ bool PHITransAddr::IsPotentiallyPHITranslatable() const {
} }
static void RemoveInstInputs(Instruction *I, static void RemoveInstInputs(Value *V,
SmallVectorImpl<Instruction*> &InstInputs) { SmallVectorImpl<Instruction*> &InstInputs) {
Instruction *I = dyn_cast<Instruction>(V);
if (I == 0) return;
// If the instruction is in the InstInputs list, remove it. // If the instruction is in the InstInputs list, remove it.
SmallVectorImpl<Instruction*>::iterator Entry = SmallVectorImpl<Instruction*>::iterator Entry =
std::find(InstInputs.begin(), InstInputs.end(), I); std::find(InstInputs.begin(), InstInputs.end(), I);
@@ -120,34 +123,15 @@ static void RemoveInstInputs(Instruction *I,
return; return;
} }
// Otherwise, it must have instruction inputs itself. Zap them recursively. assert(!isa<PHINode>(I) && "Error, removing something that isn't an input");
bool HadInstInputs = false;
for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i) {
if (Instruction *Op = dyn_cast<Instruction>(I->getOperand(i))) {
RemoveInstInputs(Op, InstInputs);
HadInstInputs = true;
}
}
// This instruction had to have operands in the instinputs list or it should
// have been in the list itself. If not, the list is broken.
assert(HadInstInputs && "InstInputs list inconsistent!");
}
/// ReplaceInstWithValue - Remove any instruction inputs in the InstInputs
/// array that are due to the specified instruction that is about to be
/// removed from the address, and add any corresponding to V. This returns V.
Value *PHITransAddr::ReplaceInstWithValue(Instruction *I, Value *V) {
// Remove the old instruction from InstInputs.
RemoveInstInputs(I, InstInputs);
// If V is an instruction, it is now an input. // Otherwise, it must have instruction inputs itself. Zap them recursively.
if (Instruction *VI = dyn_cast<Instruction>(V)) for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i) {
InstInputs.push_back(VI); if (Instruction *Op = dyn_cast<Instruction>(I->getOperand(i)))
return V; RemoveInstInputs(Op, InstInputs);
}
} }
Value *PHITransAddr::PHITranslateSubExpr(Value *V, BasicBlock *CurBB, Value *PHITransAddr::PHITranslateSubExpr(Value *V, BasicBlock *CurBB,
BasicBlock *PredBB) { BasicBlock *PredBB) {
// 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.
@@ -168,18 +152,18 @@ Value *PHITransAddr::PHITranslateSubExpr(Value *V, BasicBlock *CurBB,
// If 'Inst' is defined in this block and is an input that needs to be phi // If 'Inst' is defined in this block and is an input that needs to be phi
// translated, we need to incorporate the value into the expression or fail. // translated, we need to incorporate the value into the expression or fail.
// In either case, the instruction itself isn't an input any longer.
InstInputs.erase(std::find(InstInputs.begin(), InstInputs.end(), Inst));
// If this is a PHI, go ahead and translate it. // If this is a PHI, go ahead and translate it.
if (PHINode *PN = dyn_cast<PHINode>(Inst)) if (PHINode *PN = dyn_cast<PHINode>(Inst))
return ReplaceInstWithValue(PN, PN->getIncomingValueForBlock(PredBB)); return AddAsInput(PN->getIncomingValueForBlock(PredBB));
// If this is a non-phi value, and it is analyzable, we can incorporate it // If this is a non-phi value, and it is analyzable, we can incorporate it
// into the expression by making all instruction operands be inputs. // into the expression by making all instruction operands be inputs.
if (!CanPHITrans(Inst)) if (!CanPHITrans(Inst))
return 0; return 0;
// The instruction itself isn't an input any longer.
InstInputs.erase(std::find(InstInputs.begin(), InstInputs.end(), Inst));
// All instruction operands are now inputs (and of course, they may also be // All instruction operands are now inputs (and of course, they may also be
// defined in this block, so they may need to be phi translated themselves. // defined in this block, so they may need to be phi translated themselves.
for (unsigned i = 0, e = Inst->getNumOperands(); i != e; ++i) for (unsigned i = 0, e = Inst->getNumOperands(); i != e; ++i)
@@ -201,8 +185,7 @@ Value *PHITransAddr::PHITranslateSubExpr(Value *V, BasicBlock *CurBB,
// Constants are trivial to find. // Constants are trivial to find.
if (Constant *C = dyn_cast<Constant>(PHIIn)) if (Constant *C = dyn_cast<Constant>(PHIIn))
return ReplaceInstWithValue(BC, ConstantExpr::getBitCast(C, return AddAsInput(ConstantExpr::getBitCast(C, BC->getType()));
BC->getType()));
// Otherwise we have to see if a bitcasted version of the incoming pointer // Otherwise we have to see if a bitcasted version of the incoming pointer
// is available. If so, we can use it, otherwise we have to fail. // is available. If so, we can use it, otherwise we have to fail.
@@ -232,8 +215,12 @@ Value *PHITransAddr::PHITranslateSubExpr(Value *V, BasicBlock *CurBB,
return GEP; return GEP;
// Simplify the GEP to handle 'gep x, 0' -> x etc. // Simplify the GEP to handle 'gep x, 0' -> x etc.
if (Value *V = SimplifyGEPInst(&GEPOps[0], GEPOps.size(), TD)) if (Value *V = SimplifyGEPInst(&GEPOps[0], GEPOps.size(), TD)) {
return ReplaceInstWithValue(GEP, V); for (unsigned i = 0, e = GEPOps.size(); i != e; ++i)
RemoveInstInputs(GEPOps[i], InstInputs);
return AddAsInput(V);
}
// Scan to see if we have this GEP available. // Scan to see if we have this GEP available.
Value *APHIOp = GEPOps[0]; Value *APHIOp = GEPOps[0];
@@ -274,11 +261,21 @@ Value *PHITransAddr::PHITranslateSubExpr(Value *V, BasicBlock *CurBB,
LHS = BOp->getOperand(0); LHS = BOp->getOperand(0);
RHS = ConstantExpr::getAdd(RHS, CI); RHS = ConstantExpr::getAdd(RHS, CI);
isNSW = isNUW = false; isNSW = isNUW = false;
// If the old 'LHS' was an input, add the new 'LHS' as an input.
if (std::count(InstInputs.begin(), InstInputs.end(), BOp)) {
RemoveInstInputs(BOp, InstInputs);
AddAsInput(LHS);
}
} }
// See if the add simplifies away. // See if the add simplifies away.
if (Value *Res = SimplifyAddInst(LHS, RHS, isNSW, isNUW, TD)) if (Value *Res = SimplifyAddInst(LHS, RHS, isNSW, isNUW, TD)) {
return ReplaceInstWithValue(Inst, Res); // If we simplified the operands, the LHS is no longer an input, but Res
// is.
RemoveInstInputs(LHS, InstInputs);
return AddAsInput(Res);
}
// Otherwise, see if we have this add available somewhere. // Otherwise, see if we have this add available somewhere.
for (Value::use_iterator UI = LHS->use_begin(), E = LHS->use_end(); for (Value::use_iterator UI = LHS->use_begin(), E = LHS->use_end();