Skip to content

[SCEV] Make sure starting block is marked as visited when recursively collecting loop guards. #120749

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions llvm/lib/Analysis/ScalarEvolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15754,6 +15754,7 @@ void ScalarEvolution::LoopGuards::collectFromBlock(
// original header.
// TODO: share this logic with isLoopEntryGuardedByCond.
unsigned NumCollectedConditions = 0;
VisitedBlocks.insert(Block);
std::pair<const BasicBlock *, const BasicBlock *> Pair(Pred, Block);
for (; Pair.first;
Pair = SE.getPredecessorWithUniqueSuccessorForBB(Pair.first)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,3 +310,29 @@ inner.header:
exit:
ret void
}

; Checks correct traversal for loops without a unique predecessor
; outside the loop.
define void @pr120615() {
; CHECK-LABEL: pr120615
; CHECK-NEXT: Determining loop execution counts for: @pr120615
; CHECK-NEXT: Loop %header: backedge-taken count is i32 0
; CHECK-NEXT: Loop %header: constant max backedge-taken count is i32 0
; CHECK-NEXT: Loop %header: symbolic max backedge-taken count is i32 0
; CHECK-NEXT: Loop %header: Trip multiple is 1
entry:
br label %header

bb:
br label %header

header:
%0 = phi i32 [ %1, %header ], [ 0, %bb ], [ 0, %entry ]
%1 = add i32 %0, 1
%icmp = icmp slt i32 %0, 0
br i1 %icmp, label %header, label %exit

exit:
ret void

}
Loading