Skip to content
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

[cherrypick][SCEV] Do not attempt to collect loop guards for loops without predecessor. #9876

Merged
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
2 changes: 2 additions & 0 deletions llvm/lib/Analysis/ScalarEvolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15096,6 +15096,8 @@ ScalarEvolution::LoopGuards::collect(const Loop *L, ScalarEvolution &SE) {
BasicBlock *Header = L->getHeader();
BasicBlock *Pred = L->getLoopPredecessor();
LoopGuards Guards(SE);
if (!Pred)
return Guards;
SmallPtrSet<const BasicBlock *, 8> VisitedBlocks;
collectFromBlock(SE, Guards, Header, Pred, VisitedBlocks);
return Guards;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,3 +336,31 @@ exit:
ret void

}

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

bb:
br i1 1, label %exit, label %header

header:
%0 = phi i32 [ %1, %body ], [ 0, %bb ], [ 0, %entry ]
br label %body

body:
%1 = add i32 %0, 1
%2 = icmp ult i32 %1, 0
br i1 %2, label %header, label %exit

exit:
ret void
}