[PATCH] D85189: [SCEV] ] If RHS >= Start, simplify (Start smax RHS) to RHS for trip counts.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 11 05:21:24 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG3483c28c5bc1: [SCEV] ] If RHS >= Start, simplify (Start smax RHS) to RHS for trip counts. (authored by fhahn).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85189/new/

https://reviews.llvm.org/D85189

Files:
  llvm/lib/Analysis/ScalarEvolution.cpp
  llvm/test/Analysis/ScalarEvolution/smin-smax-folds.ll


Index: llvm/test/Analysis/ScalarEvolution/smin-smax-folds.ll
===================================================================
--- llvm/test/Analysis/ScalarEvolution/smin-smax-folds.ll
+++ llvm/test/Analysis/ScalarEvolution/smin-smax-folds.ll
@@ -98,13 +98,13 @@
 ; CHECK-LABEL:  'smax_simplify_with_guard'
 ; CHECK-NEXT:  Classifying expressions for: @smax_simplify_with_guard
 ; CHECK-NEXT:    %k.0.i26 = phi i32 [ %start, %loop.ph ], [ %inc.i, %loop ]
-; CHECK-NEXT:    -->  {%start,+,1}<nsw><%loop> U: full-set S: full-set      Exits: (%start smax %n)     LoopDispositions: { %loop: Computable }
+; CHECK-NEXT:    -->  {%start,+,1}<nsw><%loop> U: full-set S: full-set      Exits: %n     LoopDispositions: { %loop: Computable }
 ; CHECK-NEXT:    %inc.i = add nsw i32 %k.0.i26, 1
-; CHECK-NEXT:    -->  {(1 + %start),+,1}<nw><%loop> U: full-set S: full-set     Exits: (1 + (%start smax %n))       LoopDispositions: { %loop: Computable }
+; CHECK-NEXT:    -->  {(1 + %start),+,1}<nw><%loop> U: full-set S: full-set     Exits: (1 + %n)       LoopDispositions: { %loop: Computable }
 ; CHECK-NEXT:  Determining loop execution counts for: @smax_simplify_with_guard
-; CHECK-NEXT:  Loop %loop: backedge-taken count is ((-1 * %start) + (%start smax %n))
+; CHECK-NEXT:  Loop %loop: backedge-taken count is ((-1 * %start) + %n)
 ; CHECK-NEXT:  Loop %loop: max backedge-taken count is -1
-; CHECK-NEXT:  Loop %loop: Predicated backedge-taken count is ((-1 * %start) + (%start smax %n))
+; CHECK-NEXT:  Loop %loop: Predicated backedge-taken count is ((-1 * %start) +  %n)
 ; CHECK-NEXT:   Predicates:
 ; CHECK:       Loop %loop: Trip multiple is 1
 entry:
Index: llvm/lib/Analysis/ScalarEvolution.cpp
===================================================================
--- llvm/lib/Analysis/ScalarEvolution.cpp
+++ llvm/lib/Analysis/ScalarEvolution.cpp
@@ -10561,7 +10561,13 @@
   if (isLoopEntryGuardedByCond(L, Cond, getMinusSCEV(Start, Stride), RHS))
     BECount = BECountIfBackedgeTaken;
   else {
-    End = IsSigned ? getSMaxExpr(RHS, Start) : getUMaxExpr(RHS, Start);
+    // If we know that RHS >= Start in the context of loop, then we know that
+    // max(RHS, Start) = RHS at this point.
+    if (isLoopEntryGuardedByCond(
+            L, IsSigned ? ICmpInst::ICMP_SGE : ICmpInst::ICMP_UGE, RHS, Start))
+      End = RHS;
+    else
+      End = IsSigned ? getSMaxExpr(RHS, Start) : getUMaxExpr(RHS, Start);
     BECount = computeBECount(getMinusSCEV(End, Start), Stride, false);
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85189.284671.patch
Type: text/x-patch
Size: 2493 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200811/dd389d28/attachment.bin>


More information about the llvm-commits mailing list