summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
diff options
context:
space:
mode:
authorJuergen Ributzka <juergen@apple.com>2014-02-08 00:20:45 +0000
committerJuergen Ributzka <juergen@apple.com>2014-02-08 00:20:45 +0000
commit4c8a02521d5068182021417e83481bfcd191ef93 (patch)
tree634cc4cc8bdde4adf575ca8300ac2b5c72e095f9 /llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
parent4393aa7efb0829f463911f783d87e8a9f039ffbd (diff)
downloadbcm5719-llvm-4c8a02521d5068182021417e83481bfcd191ef93.tar.gz
bcm5719-llvm-4c8a02521d5068182021417e83481bfcd191ef93.zip
[Constant Hoisting] Don't update the use list while traversing it - DOH!
This fix first traverses the whole use list of the constant expression and keeps track of the instructions that need to be updated. Then perform the fixup afterwards. llvm-svn: 201008
Diffstat (limited to 'llvm/lib/Transforms/Scalar/ConstantHoisting.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/ConstantHoisting.cpp21
1 files changed, 16 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp b/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
index c4cf85f9526..28a31a97025 100644
--- a/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
+++ b/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
@@ -350,14 +350,19 @@ void ConstantHoisting::EmitBaseConstants(Function &F, User *U,
}
assert(isa<ConstantExpr>(U) && "Expected a ConstantExpr.");
ConstantExpr *CE = cast<ConstantExpr>(U);
+ SmallVector<std::pair<Instruction *, Instruction *>, 8> WorkList;
+ DEBUG(dbgs() << "Visit ConstantExpr " << *CE << '\n');
for (Value::use_iterator UU = CE->use_begin(), E = CE->use_end();
UU != E; ++UU) {
+ DEBUG(dbgs() << "Check user "; UU->print(dbgs()); dbgs() << '\n');
// We only handel instructions here and won't walk down a ConstantExpr chain
// to replace all ConstExpr with instructions.
if (Instruction *I = dyn_cast<Instruction>(*UU)) {
// Only update constant expressions in the current function.
- if (I->getParent()->getParent() != &F)
+ if (I->getParent()->getParent() != &F) {
+ DEBUG(dbgs() << "Not in the same function - skip.\n");
continue;
+ }
Instruction *Mat = Base;
Instruction *InsertBefore = getMatInsertPt(I, DT);
@@ -380,12 +385,18 @@ void ConstantHoisting::EmitBaseConstants(Function &F, User *U,
// Use the same debug location as the instruction we are about to update.
ICE->setDebugLoc(I->getDebugLoc());
- DEBUG(dbgs() << "Create instruction: " << *ICE << '\n');
- DEBUG(dbgs() << "Update: " << *I << '\n');
- I->replaceUsesOfWith(CE, ICE);
- DEBUG(dbgs() << "To: " << *I << '\n');
+ WorkList.push_back(std::make_pair(I, ICE));
+ } else {
+ DEBUG(dbgs() << "Not an instruction - skip.\n");
}
}
+ SmallVectorImpl<std::pair<Instruction *, Instruction *> >::iterator I, E;
+ for (I = WorkList.begin(), E = WorkList.end(); I != E; ++I) {
+ DEBUG(dbgs() << "Create instruction: " << *I->second << '\n');
+ DEBUG(dbgs() << "Update: " << *I->first << '\n');
+ I->first->replaceUsesOfWith(CE, I->second);
+ DEBUG(dbgs() << "To: " << *I->first << '\n');
+ }
}
/// \brief Hoist and hide the base constant behind a bitcast and emit
OpenPOWER on IntegriCloud