[llvm] 418604f - [SCEV] Recognize `cond ? i1 x : i1 1` as `~umin_seq cond, ~x`

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 10 06:47:12 PST 2022


Author: Roman Lebedev
Date: 2022-02-10T17:42:55+03:00
New Revision: 418604fd90a2344066256bed1a9fb47085473546

URL: https://github.com/llvm/llvm-project/commit/418604fd90a2344066256bed1a9fb47085473546
DIFF: https://github.com/llvm/llvm-project/commit/418604fd90a2344066256bed1a9fb47085473546.diff

LOG: [SCEV] Recognize `cond ? i1 x : i1 1` as `~umin_seq cond, ~x`

By definition, `umin_seq` has the exact same
poison stopping properties the original `select` had:
https://alive2.llvm.org/ce/z/aqe9GK

Added: 
    

Modified: 
    llvm/lib/Analysis/ScalarEvolution.cpp
    llvm/test/Analysis/ScalarEvolution/logical-operations.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 5252fab1ea9c..6cd60a9c3a0a 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -6008,6 +6008,13 @@ const SCEV *ScalarEvolution::createNodeForSelectOrPHIViaUMinSeq(
                                     /*Sequential=*/true));
   }
 
+  // i1 cond ? i1 x : i1 1  -->  ~umin_seq cond, ~x
+  if (auto *FalseConst = dyn_cast<ConstantInt>(FalseVal)) {
+    if (FalseConst->isOne())
+      return getNotSCEV(getUMinExpr(getSCEV(Cond), getNotSCEV(getSCEV(TrueVal)),
+                                    /*Sequential=*/true));
+  }
+
   return getUnknown(V);
 }
 

diff  --git a/llvm/test/Analysis/ScalarEvolution/logical-operations.ll b/llvm/test/Analysis/ScalarEvolution/logical-operations.ll
index c43f93e7a1a6..19f91c9ebbfc 100644
--- a/llvm/test/Analysis/ScalarEvolution/logical-operations.ll
+++ b/llvm/test/Analysis/ScalarEvolution/logical-operations.ll
@@ -169,7 +169,7 @@ define i1 @select_x_or_true(i1 %c, i1 %x) {
 ; CHECK-LABEL: 'select_x_or_true'
 ; CHECK-NEXT:  Classifying expressions for: @select_x_or_true
 ; CHECK-NEXT:    %r = select i1 %c, i1 %x, i1 true
-; CHECK-NEXT:    --> %r U: full-set S: full-set
+; CHECK-NEXT:    --> (true + (%c umin_seq (true + %x))) U: full-set S: full-set
 ; CHECK-NEXT:  Determining loop execution counts for: @select_x_or_true
 ;
   %r = select i1 %c, i1 %x, i1 true


        


More information about the llvm-commits mailing list