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

[SCEV] Use loop guards when checking that RHS >= Start #75039

Merged
merged 1 commit into from
Dec 12, 2023
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
6 changes: 5 additions & 1 deletion llvm/lib/Analysis/ScalarEvolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12910,7 +12910,11 @@ ScalarEvolution::howManyLessThans(const SCEV *LHS, const SCEV *RHS,
if (!BECount) {
auto canProveRHSGreaterThanEqualStart = [&]() {
auto CondGE = IsSigned ? ICmpInst::ICMP_SGE : ICmpInst::ICMP_UGE;
if (isLoopEntryGuardedByCond(L, CondGE, OrigRHS, OrigStart))
const SCEV *GuardedRHS = applyLoopGuards(OrigRHS, L);
const SCEV *GuardedStart = applyLoopGuards(OrigStart, L);

if (isLoopEntryGuardedByCond(L, CondGE, OrigRHS, OrigStart) ||
isKnownPredicate(CondGE, GuardedRHS, GuardedStart))
return true;

// (RHS > Start - 1) implies RHS >= Start.
Expand Down
6 changes: 3 additions & 3 deletions llvm/test/Analysis/ScalarEvolution/trip-count.ll
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ leave:
define void @non_zero_from_loop_guard(i16 %n) {
; CHECK-LABEL: 'non_zero_from_loop_guard'
; CHECK-NEXT: Determining loop execution counts for: @non_zero_from_loop_guard
; CHECK-NEXT: Loop %loop: backedge-taken count is (-1 + (1 umax (%n /u 2)))<nsw>
; CHECK-NEXT: Loop %loop: backedge-taken count is (-1 + (%n /u 2))<nsw>
; CHECK-NEXT: Loop %loop: constant max backedge-taken count is 32766
; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is (-1 + (1 umax (%n /u 2)))<nsw>
; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is (-1 + (1 umax (%n /u 2)))<nsw>
; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is (-1 + (%n /u 2))<nsw>
; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is (-1 + (%n /u 2))<nsw>
; CHECK-NEXT: Predicates:
; CHECK-NEXT: Loop %loop: Trip multiple is 1
;
Expand Down