Skip to content

Commit a2b7e86

Browse files
committed
fixup! fixup! [SCEV] Fix exit condition for recursive loop guard collection
1 parent a276fdf commit a2b7e86

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15765,10 +15765,11 @@ void ScalarEvolution::LoopGuards::collectFromBlock(
1576515765

1576615766
Terms.emplace_back(LoopEntryPredicate->getCondition(),
1576715767
LoopEntryPredicate->getSuccessor(0) == Pair.second);
15768+
NumCollectedConditions++;
1576815769

1576915770
// If we are recursively collecting guards stop after 2
15770-
// predecessors to limit compile-time impact for now.
15771-
if (Depth > 0 && ++NumCollectedConditions == 2)
15771+
// conditions to limit compile-time impact for now.
15772+
if (Depth > 0 && NumCollectedConditions == 2)
1577215773
break;
1577315774
}
1577415775
// Finally, if we stopped climbing the predecessor chain because

llvm/test/Analysis/ScalarEvolution/pr120442.ll

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,33 @@
22

33
declare void @llvm.assume(i1)
44

5-
define void @pr120442() {
5+
; Checks that the presence of assumptions does not interfere with
6+
; exiting loop guard collection via following loop predecessors.
7+
define void @pr120442(i1 %c.1, i1 %c.2) {
68
; CHECK-LABEL: 'pr120442'
79
; CHECK-NEXT: Determining loop execution counts for: @pr120442
8-
; CHECK-NEXT: Loop %bb2: backedge-taken count is i32 0
9-
; CHECK-NEXT: Loop %bb2: constant max backedge-taken count is i32 0
10-
; CHECK-NEXT: Loop %bb2: symbolic max backedge-taken count is i32 0
11-
; CHECK-NEXT: Loop %bb2: Trip multiple is 1
12-
; CHECK-NEXT: Loop %bb1: <multiple exits> Unpredictable backedge-taken count.
13-
; CHECK-NEXT: Loop %bb1: Unpredictable constant max backedge-taken count.
14-
; CHECK-NEXT: Loop %bb1: Unpredictable symbolic max backedge-taken count.
15-
bb:
16-
call void @llvm.assume(i1 false)
17-
call void @llvm.assume(i1 false)
18-
br label %bb6
10+
; CHECK-NEXT: Loop %inner.header: backedge-taken count is i32 0
11+
; CHECK-NEXT: Loop %inner.header: constant max backedge-taken count is i32 0
12+
; CHECK-NEXT: Loop %inner.header: symbolic max backedge-taken count is i32 0
13+
; CHECK-NEXT: Loop %inner.header: Trip multiple is 1
14+
entry:
15+
call void @llvm.assume(i1 %c.1)
16+
call void @llvm.assume(i1 %c.2)
17+
br label %outer.header
18+
19+
outer.header:
20+
%phi7 = phi i32 [ 0, %bb ], [ 0, %entry ]
21+
br label %inner.header
1922

20-
bb1:
21-
br label %bb2
23+
bb:
24+
br i1 false, label %outer.header, label %bb
2225

23-
bb2:
24-
%phi = phi i32 [ %add, %bb2 ], [ 0, %bb1 ]
26+
inner.header:
27+
%phi = phi i32 [ %add, %inner.header ], [ 0, %outer.header ]
2528
%add = add i32 %phi, 1
2629
%icmp = icmp ugt i32 %add, 0
27-
br i1 %icmp, label %bb1, label %bb2
28-
29-
bb5:
30-
br i1 false, label %bb6, label %bb5
30+
br i1 %icmp, label %exit, label %inner.header
3131

32-
bb6:
33-
%phi7 = phi i32 [ 0, %bb5 ], [ 0, %bb ]
34-
br label %bb1
32+
exit:
33+
ret void
3534
}

0 commit comments

Comments
 (0)