summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Utils
diff options
context:
space:
mode:
authorPhilip Reames <listmail@philipreames.com>2017-12-01 20:57:19 +0000
committerPhilip Reames <listmail@philipreames.com>2017-12-01 20:57:19 +0000
commit6260cf71d3013124cb0ab901e5de058843fd9bbe (patch)
tree9350828ccfa9295d6a608466d0a195fc7fcf4769 /llvm/lib/Transforms/Utils
parentd8b935e0d36020ae8e62451c6d192c9d1dcc2900 (diff)
downloadbcm5719-llvm-6260cf71d3013124cb0ab901e5de058843fd9bbe.tar.gz
bcm5719-llvm-6260cf71d3013124cb0ab901e5de058843fd9bbe.zip
[IndVars] Fix a bug introduced in r317012
Turns out we can have comparisons which are indirect users of the induction variable that we can make invariant. In this case, there is no loop invariant value contributing and we'd fail an assert. The test case was found by a java fuzzer and reduced. It's a real cornercase. You have to have a static loop which we've already proven only executes once, but haven't broken the backedge on, and an inner phi whose result can be constant folded by SCEV using exit count reasoning but not proven by isKnownPredicate. To my knowledge, only the fuzzer has hit this case. llvm-svn: 319583
Diffstat (limited to 'llvm/lib/Transforms/Utils')
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyIndVar.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
index fce7f8b81ba..96b51396c9b 100644
--- a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
@@ -200,13 +200,23 @@ bool SimplifyIndvar::makeIVComparisonInvariant(ICmpInst *ICmp,
// TODO: Support multiple entry loops? (We currently bail out of these in
// the IndVarSimplify pass)
if (auto *BB = L->getLoopPredecessor()) {
- Value *Incoming = PN->getIncomingValueForBlock(BB);
- const SCEV *IncomingS = SE->getSCEV(Incoming);
- CheapExpansions[IncomingS] = Incoming;
+ const int Idx = PN->getBasicBlockIndex(BB);
+ if (Idx >= 0) {
+ Value *Incoming = PN->getIncomingValue(Idx);
+ const SCEV *IncomingS = SE->getSCEV(Incoming);
+ CheapExpansions[IncomingS] = Incoming;
+ }
}
Value *NewLHS = CheapExpansions[InvariantLHS];
Value *NewRHS = CheapExpansions[InvariantRHS];
+ if (!NewLHS)
+ if (auto *ConstLHS = dyn_cast<SCEVConstant>(InvariantLHS))
+ NewLHS = ConstLHS->getValue();
+ if (!NewRHS)
+ if (auto *ConstRHS = dyn_cast<SCEVConstant>(InvariantRHS))
+ NewRHS = ConstRHS->getValue();
+
if (!NewLHS || !NewRHS)
// We could not find an existing value to replace either LHS or RHS.
// Generating new instructions has subtler tradeoffs, so avoid doing that
OpenPOWER on IntegriCloud