[SCEV] Don't infinitely recurse on unreachable code
llvm-svn: 277848
This commit is contained in:
parent
2a04a99ce6
commit
b0b4e86215
|
@ -4168,7 +4168,9 @@ static bool BrPHIToSelect(DominatorTree &DT, BranchInst *BI, PHINode *Merge,
|
||||||
}
|
}
|
||||||
|
|
||||||
const SCEV *ScalarEvolution::createNodeFromSelectLikePHI(PHINode *PN) {
|
const SCEV *ScalarEvolution::createNodeFromSelectLikePHI(PHINode *PN) {
|
||||||
if (PN->getNumIncomingValues() == 2) {
|
auto IsReachable =
|
||||||
|
[&](BasicBlock *BB) { return DT.isReachableFromEntry(BB); };
|
||||||
|
if (PN->getNumIncomingValues() == 2 && all_of(PN->blocks(), IsReachable)) {
|
||||||
const Loop *L = LI.getLoopFor(PN->getParent());
|
const Loop *L = LI.getLoopFor(PN->getParent());
|
||||||
|
|
||||||
// We don't want to break LCSSA, even in a SCEV expression tree.
|
// We don't want to break LCSSA, even in a SCEV expression tree.
|
||||||
|
|
|
@ -126,3 +126,31 @@ for.cond.0:
|
||||||
|
|
||||||
ret i32 %init
|
ret i32 %init
|
||||||
}
|
}
|
||||||
|
|
||||||
|
define i32 @f6(i32 %x, i32 %y) {
|
||||||
|
; Do the right thing for unreachable code:
|
||||||
|
|
||||||
|
; CHECK-LABEL: Classifying expressions for: @f6
|
||||||
|
entry:
|
||||||
|
%c0 = icmp sgt i32 %y, 0
|
||||||
|
%sum = add i32 %x, %y
|
||||||
|
br i1 %c0, label %merge, label %leave_1
|
||||||
|
|
||||||
|
merge:
|
||||||
|
%v0 = phi i32 [ %sum, %entry ], [ %v1, %unreachable ]
|
||||||
|
%c1 = icmp slt i32 %y, 0
|
||||||
|
br i1 %c1, label %leave_0, label %leave_0_cond
|
||||||
|
|
||||||
|
leave_0_cond:
|
||||||
|
br label %leave_0
|
||||||
|
|
||||||
|
leave_0:
|
||||||
|
%v1 = phi i32 [ %v0, %merge ], [ 0, %leave_0_cond ]
|
||||||
|
ret i32 0
|
||||||
|
|
||||||
|
leave_1:
|
||||||
|
ret i32 0
|
||||||
|
|
||||||
|
unreachable:
|
||||||
|
br label %merge
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue