[llvm] 9a322e4 - [NFC][SCEV] `createNodeForSelectOrPHIViaUMinSeq()`: refactor `i1 cond ? i1 C : i1 y` pattern

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


Author: Roman Lebedev
Date: 2022-02-10T17:42:56+03:00
New Revision: 9a322e430f57b9e640c8db403dc443ffcf6d4584

URL: https://github.com/llvm/llvm-project/commit/9a322e430f57b9e640c8db403dc443ffcf6d4584
DIFF: https://github.com/llvm/llvm-project/commit/9a322e430f57b9e640c8db403dc443ffcf6d4584.diff

LOG: [NFC][SCEV] `createNodeForSelectOrPHIViaUMinSeq()`: refactor `i1 cond ? i1 C : i1 y` pattern

https://alive2.llvm.org/ce/z/uRvVtN

Added: 
    

Modified: 
    llvm/lib/Analysis/ScalarEvolution.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index ff38ef4a7c30..52712757b4ae 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -6002,19 +6002,12 @@ const SCEV *ScalarEvolution::createNodeForSelectOrPHIViaUMinSeq(
                                      /*Sequential=*/true));
   }
 
-  // i1 cond ? i1 1 : i1 y  -->  ~umin_seq ~cond, ~y
-  if (auto *TrueConst = dyn_cast<ConstantInt>(TrueVal)) {
-    if (TrueConst->isOne())
-      return getNotSCEV(getUMinExpr(getNotSCEV(getSCEV(Cond)),
-                                    getNotSCEV(getSCEV(FalseVal)),
-                                    /*Sequential=*/true));
-  }
-
-  // i1 cond ? i1 0 : i1 y  -->  umin_seq ~cond, y
-  if (auto *TrueConst = dyn_cast<ConstantInt>(TrueVal)) {
-    if (TrueConst->isZero())
-      return getUMinExpr(getNotSCEV(getSCEV(Cond)), getSCEV(FalseVal),
-                         /*Sequential=*/true);
+  // i1 cond ? i1 C : i1 y  -->  C + (umin_seq ~cond, y + C)
+  if (isa<ConstantInt>(TrueVal)) {
+    const SCEV *C = getSCEV(TrueVal);
+    return getAddExpr(C, getUMinExpr(getNotSCEV(getSCEV(Cond)),
+                                     getAddExpr(C, getSCEV(FalseVal)),
+                                     /*Sequential=*/true));
   }
 
   return getUnknown(V);


        


More information about the llvm-commits mailing list