Skip to content

Commit

Permalink
[SCEV] getSequentialMinMaxExpr(): relax 2-op umin_seq w/ constant t…
Browse files Browse the repository at this point in the history
…o umin

Currently, `computeExitLimitFromCondFromBinOp()` does that directly.
  • Loading branch information
LebedevRI committed Jan 14, 2022
1 parent f34742d commit 8dcba20
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions llvm/lib/Analysis/ScalarEvolution.cpp
Expand Up @@ -3994,6 +3994,11 @@ ScalarEvolution::getSequentialMinMaxExpr(SCEVTypes Kind,
assert(!Ops.empty() && "Cannot get empty (u|s)(min|max)!");
if (Ops.size() == 1)
return Ops[0];
if (Ops.size() == 2 &&
any_of(Ops, [](const SCEV *Op) { return isa<SCEVConstant>(Op); }))
return getMinMaxExpr(
SCEVSequentialMinMaxExpr::getEquivalentNonSequentialSCEVType(Kind),
Ops);
#ifndef NDEBUG
Type *ETy = getEffectiveSCEVType(Ops[0]->getType());
for (unsigned i = 1, e = Ops.size(); i != e; ++i) {
Expand Down
8 changes: 4 additions & 4 deletions llvm/test/Analysis/ScalarEvolution/exit-count-select-safe.ll
Expand Up @@ -414,17 +414,17 @@ define i32 @logical_and_2ops_and_constant(i32 %n, i32 %m, i32 %k) {
; CHECK-LABEL: 'logical_and_2ops_and_constant'
; CHECK-NEXT: Classifying expressions for: @logical_and_2ops_and_constant
; CHECK-NEXT: %i = phi i32 [ 0, %entry ], [ %i.next, %loop ]
; CHECK-NEXT: --> {0,+,1}<%loop> U: [0,43) S: [0,43) Exits: (%n umin_seq 42) LoopDispositions: { %loop: Computable }
; CHECK-NEXT: --> {0,+,1}<%loop> U: [0,43) S: [0,43) Exits: (42 umin %n) LoopDispositions: { %loop: Computable }
; CHECK-NEXT: %i.next = add i32 %i, 1
; CHECK-NEXT: --> {1,+,1}<%loop> U: [1,44) S: [1,44) Exits: (1 + (%n umin_seq 42))<nuw><nsw> LoopDispositions: { %loop: Computable }
; CHECK-NEXT: --> {1,+,1}<%loop> U: [1,44) S: [1,44) Exits: (1 + (42 umin %n))<nuw><nsw> LoopDispositions: { %loop: Computable }
; CHECK-NEXT: %umin = call i32 @llvm.umin.i32(i32 %n, i32 42)
; CHECK-NEXT: --> (42 umin %n) U: [0,43) S: [0,43) Exits: (42 umin %n) LoopDispositions: { %loop: Invariant }
; CHECK-NEXT: %cond = select i1 %cond_p1, i1 true, i1 %cond_p0
; CHECK-NEXT: --> %cond U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
; CHECK-NEXT: Determining loop execution counts for: @logical_and_2ops_and_constant
; CHECK-NEXT: Loop %loop: backedge-taken count is (%n umin_seq 42)
; CHECK-NEXT: Loop %loop: backedge-taken count is (42 umin %n)
; CHECK-NEXT: Loop %loop: max backedge-taken count is 42
; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is (%n umin_seq 42)
; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is (42 umin %n)
; CHECK-NEXT: Predicates:
; CHECK: Loop %loop: Trip multiple is 1
;
Expand Down

0 comments on commit 8dcba20

Please sign in to comment.