Skip to content

Commit f035351

Browse files
authored
[SCEV] Make sure starting block is marked as visited when recursively collecting loop guards. (llvm#120749)
When `collectFromBlock` is called without a predecessor (in particular for loops that don't have a unique predecessor outside the loop) we never start climbing the predecessor chain, and thus don't mark the starting block as visited. Fixes llvm#120615.
1 parent e3fe41c commit f035351

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15765,6 +15765,7 @@ void ScalarEvolution::LoopGuards::collectFromBlock(
1576515765
// original header.
1576615766
// TODO: share this logic with isLoopEntryGuardedByCond.
1576715767
unsigned NumCollectedConditions = 0;
15768+
VisitedBlocks.insert(Block);
1576815769
std::pair<const BasicBlock *, const BasicBlock *> Pair(Pred, Block);
1576915770
for (; Pair.first;
1577015771
Pair = SE.getPredecessorWithUniqueSuccessorForBB(Pair.first)) {

llvm/test/Analysis/ScalarEvolution/backedge-taken-count-guard-info-with-multiple-predecessors.ll

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,3 +310,29 @@ inner.header:
310310
exit:
311311
ret void
312312
}
313+
314+
; Checks correct traversal for loops without a unique predecessor
315+
; outside the loop.
316+
define void @pr120615() {
317+
; CHECK-LABEL: pr120615
318+
; CHECK-NEXT: Determining loop execution counts for: @pr120615
319+
; CHECK-NEXT: Loop %header: backedge-taken count is i32 0
320+
; CHECK-NEXT: Loop %header: constant max backedge-taken count is i32 0
321+
; CHECK-NEXT: Loop %header: symbolic max backedge-taken count is i32 0
322+
; CHECK-NEXT: Loop %header: Trip multiple is 1
323+
entry:
324+
br label %header
325+
326+
bb:
327+
br label %header
328+
329+
header:
330+
%0 = phi i32 [ %1, %header ], [ 0, %bb ], [ 0, %entry ]
331+
%1 = add i32 %0, 1
332+
%icmp = icmp slt i32 %0, 0
333+
br i1 %icmp, label %header, label %exit
334+
335+
exit:
336+
ret void
337+
338+
}

0 commit comments

Comments
 (0)