[llvm] c94ec79 - [NFC][SCEV] `createNodeForSelectOrPHIViaUMinSeq()`: use sub instead of add

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 10 14:22:08 PST 2022


Author: Roman Lebedev
Date: 2022-02-11T01:21:45+03:00
New Revision: c94ec7997aaf9cd3c3ae32b3cbfe48da93e7a27f

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

LOG: [NFC][SCEV] `createNodeForSelectOrPHIViaUMinSeq()`: use sub instead of add

For booleans, xor/add/sub are interchangeable:
https://alive2.llvm.org/ce/z/ziav3d

But for larger bitwidths, we'll need sub, so change it now.

Added: 
    

Modified: 
    llvm/lib/Analysis/ScalarEvolution.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 1b0d92066c156..1a31f96c1c24b 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -5994,8 +5994,12 @@ const SCEV *ScalarEvolution::createNodeForSelectOrPHIViaUMinSeq(
       !FalseVal->getType()->isIntegerTy(1))
     return getUnknown(V);
 
-  // i1 cond ? i1 x : i1 C  -->  C + (umin_seq  cond, x + C)
-  // i1 cond ? i1 C : i1 x  -->  C + (umin_seq ~cond, x + C)
+  // i1 cond ? i1 x : i1 C  -->  C + (i1  cond ? (i1 x - i1 C) : i1 0)
+  //                        -->  C + (umin_seq  cond, x - C)
+  //
+  // i1 cond ? i1 C : i1 x  -->  C + (i1  cond ? i1 0 : (i1 x - i1 C))
+  //                        -->  C + (i1 ~cond ? (i1 x - i1 C) : i1 0)
+  //                        -->  C + (umin_seq ~cond, x - C)
   if (isa<ConstantInt>(TrueVal) || isa<ConstantInt>(FalseVal)) {
     const SCEV *CondExpr = getSCEV(Cond);
     const SCEV *TrueExpr = getSCEV(TrueVal);
@@ -6010,7 +6014,7 @@ const SCEV *ScalarEvolution::createNodeForSelectOrPHIViaUMinSeq(
       C = FalseExpr;
     }
     return getAddExpr(
-        C, getUMinExpr(CondExpr, getAddExpr(C, X), /*Sequential=*/true));
+        C, getUMinExpr(CondExpr, getMinusSCEV(X, C), /*Sequential=*/true));
   }
 
   return getUnknown(V);


        


More information about the llvm-commits mailing list