[llvm] r270924 - [LoopUnrollAnalyzer] Fix a crash in analyzeLoopUnrollCost.
Michael Zolotukhin via llvm-commits
llvm-commits at lists.llvm.org
Thu May 26 14:42:51 PDT 2016
Author: mzolotukhin
Date: Thu May 26 16:42:51 2016
New Revision: 270924
URL: http://llvm.org/viewvc/llvm-project?rev=270924&view=rev
Log:
[LoopUnrollAnalyzer] Fix a crash in analyzeLoopUnrollCost.
Condition might be simplified to a Constant, but it doesn't have to be
ConstantInt, so we should dyn_cast, instead of cast.
This fixes PR27886.
Modified:
llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp
llvm/trunk/test/Transforms/LoopUnroll/full-unroll-crashers.ll
Modified: llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp?rev=270924&r1=270923&r2=270924&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp Thu May 26 16:42:51 2016
@@ -464,41 +464,37 @@ analyzeLoopUnrollCost(const Loop *L, uns
// Add in the live successors by first checking whether we have terminator
// that may be simplified based on the values simplified by this call.
+ BasicBlock *KnownSucc = nullptr;
if (BranchInst *BI = dyn_cast<BranchInst>(TI)) {
if (BI->isConditional()) {
if (Constant *SimpleCond =
SimplifiedValues.lookup(BI->getCondition())) {
- 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);
- else
- ExitWorklist.insert({BB, Succ});
- continue;
+ KnownSucc = BI->getSuccessor(0);
+ else if (ConstantInt *SimpleCondVal =
+ dyn_cast<ConstantInt>(SimpleCond))
+ KnownSucc = BI->getSuccessor(SimpleCondVal->isZero() ? 1 : 0);
}
}
} else if (SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
if (Constant *SimpleCond =
SimplifiedValues.lookup(SI->getCondition())) {
- BasicBlock *Succ = nullptr;
// Just take the first successor if condition is undef
if (isa<UndefValue>(SimpleCond))
- Succ = SI->getSuccessor(0);
- else
- Succ = SI->findCaseValue(cast<ConstantInt>(SimpleCond))
- .getCaseSuccessor();
- if (L->contains(Succ))
- BBWorklist.insert(Succ);
- else
- ExitWorklist.insert({BB, Succ});
- continue;
+ KnownSucc = SI->getSuccessor(0);
+ else if (ConstantInt *SimpleCondVal =
+ dyn_cast<ConstantInt>(SimpleCond))
+ KnownSucc = SI->findCaseValue(SimpleCondVal).getCaseSuccessor();
}
}
+ if (KnownSucc) {
+ if (L->contains(KnownSucc))
+ BBWorklist.insert(KnownSucc);
+ else
+ ExitWorklist.insert({BB, KnownSucc});
+ continue;
+ }
// Add BB's successors to the worklist.
for (BasicBlock *Succ : successors(BB))
Modified: llvm/trunk/test/Transforms/LoopUnroll/full-unroll-crashers.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopUnroll/full-unroll-crashers.ll?rev=270924&r1=270923&r2=270924&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/LoopUnroll/full-unroll-crashers.ll (original)
+++ llvm/trunk/test/Transforms/LoopUnroll/full-unroll-crashers.ll Thu May 26 16:42:51 2016
@@ -137,3 +137,33 @@ for.body:
exit:
ret void
}
+
+ at i = external global i32, align 4
+
+define void @folded_not_to_constantint() {
+entry:
+ br label %for.body
+
+for.body:
+ %iv = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
+ %m = phi i32* [ @i, %entry ], [ %m, %for.inc ]
+ br i1 undef, label %if.else, label %if.then
+
+if.then:
+ unreachable
+
+if.else:
+ %cmp = icmp ult i32* %m, null
+ br i1 %cmp, label %cond.false, label %for.inc
+
+cond.false:
+ unreachable
+
+for.inc:
+ %inc = add nuw nsw i32 %iv, 1
+ %cmp2 = icmp ult i32 %inc, 10
+ br i1 %cmp2, label %for.body, label %for.end
+
+for.end:
+ ret void
+}
More information about the llvm-commits
mailing list