summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorJuergen Ributzka <juergen@apple.com>2014-02-08 00:20:49 +0000
committerJuergen Ributzka <juergen@apple.com>2014-02-08 00:20:49 +0000
commit9479b31f9734d24af142a8e25e2f569d460627d8 (patch)
treef1a116d7cbd7250d083d78130666cb229041fcca /llvm/lib/Transforms
parent4c8a02521d5068182021417e83481bfcd191ef93 (diff)
downloadbcm5719-llvm-9479b31f9734d24af142a8e25e2f569d460627d8.tar.gz
bcm5719-llvm-9479b31f9734d24af142a8e25e2f569d460627d8.zip
[Constant Hoisting] Fix insertion point for constant materialization.
The bitcast instruction during constant materialization was not placed correcly in the presence of phi nodes. This commit fixes the insertion point to be in the idom instead. This fixes PR18768 llvm-svn: 201009
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/ConstantHoisting.cpp39
1 files changed, 21 insertions, 18 deletions
diff --git a/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp b/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
index 28a31a97025..0fca617be7e 100644
--- a/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
+++ b/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
@@ -148,6 +148,8 @@ void ConstantHoisting::CollectConstant(User * U, unsigned Opcode,
ConstantCandidate &CC = ConstantMap[C];
CC.CumulativeCost += Cost;
CC.Uses.push_back(U);
+ DEBUG(dbgs() << "Collect constant " << *C << " with cost " << Cost
+ << " from " << *U << '\n');
}
}
@@ -279,6 +281,20 @@ static void CollectBasicBlocks(SmallPtrSet<BasicBlock *, 4> &BBs, Function &F,
BBs.insert(I->getParent());
}
+/// \brief Find the instruction we should insert the constant materialization
+/// before.
+static Instruction *getMatInsertPt(Instruction *I, const DominatorTree *DT) {
+ if (!isa<PHINode>(I) && !isa<LandingPadInst>(I)) // Simple case.
+ return I;
+
+ // We can't insert directly before a phi node or landing pad. Insert before
+ // the terminator of the dominating block.
+ assert(&I->getParent()->getParent()->getEntryBlock() != I->getParent() &&
+ "PHI or landing pad in entry block!");
+ BasicBlock *IDom = DT->getNode(I->getParent())->getIDom()->getBlock();
+ return IDom->getTerminator();
+}
+
/// \brief Find an insertion point that dominates all uses.
Instruction *ConstantHoisting::
FindConstantInsertionPoint(Function &F, const ConstantInfo &CI) const {
@@ -291,10 +307,10 @@ FindConstantInsertionPoint(Function &F, const ConstantInfo &CI) const {
RCI != RCE; ++RCI)
for (SmallVectorImpl<User *>::const_iterator U = RCI->Uses.begin(),
E = RCI->Uses.end(); U != E; ++U)
- CollectBasicBlocks(BBs, F, *U);
+ CollectBasicBlocks(BBs, F, *U);
if (BBs.count(Entry))
- return Entry->getFirstInsertionPt();
+ return getMatInsertPt(&Entry->front(), DT);
while (BBs.size() >= 2) {
BasicBlock *BB, *BB1, *BB2;
@@ -302,27 +318,14 @@ FindConstantInsertionPoint(Function &F, const ConstantInfo &CI) const {
BB2 = *llvm::next(BBs.begin());
BB = DT->findNearestCommonDominator(BB1, BB2);
if (BB == Entry)
- return Entry->getFirstInsertionPt();
+ return getMatInsertPt(&Entry->front(), DT);
BBs.erase(BB1);
BBs.erase(BB2);
BBs.insert(BB);
}
assert((BBs.size() == 1) && "Expected only one element.");
- return (*BBs.begin())->getFirstInsertionPt();
-}
-
-/// \brief Find the instruction we should insert the constant materialization
-/// before.
-static Instruction *getMatInsertPt(Instruction *I, const DominatorTree *DT) {
- if (!isa<PHINode>(I) && !isa<LandingPadInst>(I)) // Simple case.
- return I;
-
- // We can't insert directly before a phi node or landing pad. Insert before
- // the terminator of the dominating block.
- assert(&I->getParent()->getParent()->getEntryBlock() != I->getParent() &&
- "PHI or landing pad in entry block!");
- BasicBlock *IDom = DT->getNode(I->getParent())->getIDom()->getBlock();
- return IDom->getTerminator();
+ Instruction &FirstInst = (*BBs.begin())->front();
+ return getMatInsertPt(&FirstInst, DT);
}
/// \brief Emit materialization code for all rebased constants and update their
OpenPOWER on IntegriCloud