summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorMichael Zolotukhin <mzolotukhin@apple.com>2015-07-29 18:10:29 +0000
committerMichael Zolotukhin <mzolotukhin@apple.com>2015-07-29 18:10:29 +0000
commit3a7d55b623752dbef21258409ec120cd4e70410f (patch)
treea069992798bcfb941c05889edda4cdc7ffcad7f6 /llvm/lib/Transforms
parenta2069d36ce6e44f1202588b41d78f4ed9806c777 (diff)
downloadbcm5719-llvm-3a7d55b623752dbef21258409ec120cd4e70410f.tar.gz
bcm5719-llvm-3a7d55b623752dbef21258409ec120cd4e70410f.zip
[Unroll] Don't crash when simplified branch condition is undef.
llvm-svn: 243544
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
index 159ed201ab3..25b0877a4f4 100644
--- a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
@@ -599,8 +599,13 @@ analyzeLoopUnrollCost(const Loop *L, unsigned TripCount, ScalarEvolution &SE,
if (BI->isConditional()) {
if (Constant *SimpleCond =
SimplifiedValues.lookup(BI->getCondition())) {
- BasicBlock *Succ = BI->getSuccessor(
- cast<ConstantInt>(SimpleCond)->isZero() ? 1 : 0);
+ BasicBlock *Succ = nullptr;
+ // Just take the first successor if condition is undef
+ if (isa<UndefValue>(SimpleCond))
+ Succ = BI->getSuccessor(0);
+ else
+ Succ = BI->getSuccessor(
+ cast<ConstantInt>(SimpleCond)->isZero() ? 1 : 0);
if (L->contains(Succ))
BBWorklist.insert(Succ);
continue;
@@ -609,8 +614,13 @@ analyzeLoopUnrollCost(const Loop *L, unsigned TripCount, ScalarEvolution &SE,
} else if (SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
if (Constant *SimpleCond =
SimplifiedValues.lookup(SI->getCondition())) {
- BasicBlock *Succ =
- SI->getSuccessor(cast<ConstantInt>(SimpleCond)->getSExtValue());
+ BasicBlock *Succ = nullptr;
+ // Just take the first successor if condition is undef
+ if (isa<UndefValue>(SimpleCond))
+ Succ = SI->getSuccessor(0);
+ else
+ Succ =
+ SI->getSuccessor(cast<ConstantInt>(SimpleCond)->getSExtValue());
if (L->contains(Succ))
BBWorklist.insert(Succ);
continue;
OpenPOWER on IntegriCloud