diff options
author | Andrew Trick <atrick@apple.com> | 2012-01-14 03:17:23 +0000 |
---|---|---|
committer | Andrew Trick <atrick@apple.com> | 2012-01-14 03:17:23 +0000 |
commit | dd1f22f25d8496b10cfddedb63d674dd39897bb0 (patch) | |
tree | 98df02490fb21506908dd0444ae5273e0916a0ad /lib/Analysis/ScalarEvolutionExpander.cpp | |
parent | da223448043e860d1f997b6a72f35c9d4da7ea29 (diff) |
Fix a corner case hit by redundant phi elimination running after LSR.
Fixes PR11761: bad IR w/ redundant Phi elim
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@148177 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/ScalarEvolutionExpander.cpp')
-rw-r--r-- | lib/Analysis/ScalarEvolutionExpander.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/Analysis/ScalarEvolutionExpander.cpp b/lib/Analysis/ScalarEvolutionExpander.cpp index 8dc8eb68ff..e2f75aa0ea 100644 --- a/lib/Analysis/ScalarEvolutionExpander.cpp +++ b/lib/Analysis/ScalarEvolutionExpander.cpp @@ -1541,6 +1541,13 @@ SCEVExpander::getOrInsertCanonicalInductionVariable(const Loop *L, /// general code-insertion helper. bool SCEVExpander::hoistStep(Instruction *IncV, Instruction *InsertPos, const DominatorTree *DT) { + // Phi nodes are strangely positional but don't follow normal rules for + // instruction dominance. Handle them immediately. + if (isa<PHINode>(InsertPos)) + return isa<PHINode>(IncV); + else if (isa<PHINode>(IncV)) + return false; + if (DT->dominates(IncV, InsertPos)) return true; @@ -1648,7 +1655,10 @@ unsigned SCEVExpander::replaceCongruentIVs(Loop *L, const DominatorTree *DT, << *IsomorphicInc << '\n'); Value *NewInc = OrigInc; if (OrigInc->getType() != IsomorphicInc->getType()) { - IRBuilder<> Builder(OrigInc->getNextNode()); + Instruction *IP = isa<PHINode>(OrigInc) + ? (Instruction*)L->getHeader()->getFirstInsertionPt() + : OrigInc->getNextNode(); + IRBuilder<> Builder(IP); Builder.SetCurrentDebugLocation(IsomorphicInc->getDebugLoc()); NewInc = Builder. CreateTruncOrBitCast(OrigInc, IsomorphicInc->getType(), IVName); |