[llvm] c234809 - [SCEV] Recognize `x == 0 ? 0 : umin_seq(..., x, ...) -> umin_seq(x, umin_seq(...))`

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 11 10:58:39 PST 2022


Author: Roman Lebedev
Date: 2022-02-11T21:58:19+03:00
New Revision: c234809ff855b6d850e1133b2c8414fe67de3c18

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

LOG: [SCEV] Recognize `x == 0 ? 0 : umin_seq(..., x, ...)  ->  umin_seq(x, umin_seq(...))`

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 e5a934191e04..b0d5f0ccfbbf 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -5967,14 +5967,18 @@ const SCEV *ScalarEvolution::createNodeForSelectOrPHIInstWithICmpInstCond(
       if (isa<SCEVConstant>(C) && cast<SCEVConstant>(C)->getAPInt().ule(1))
         return getAddExpr(getUMaxExpr(X, C), Y);
     }
-    // x == 0 ? 0 : umin(..., x, ...)  ->  umin_seq(x, umin(...))
+    // x == 0 ? 0 : umin    (..., x, ...)  ->  umin_seq(x, umin    (...))
+    // x == 0 ? 0 : umin_seq(..., x, ...)  ->  umin_seq(x, umin_seq(...))
     if (getTypeSizeInBits(LHS->getType()) == getTypeSizeInBits(I->getType()) &&
         isa<ConstantInt>(RHS) && cast<ConstantInt>(RHS)->isZero() &&
         isa<ConstantInt>(TrueVal) && cast<ConstantInt>(TrueVal)->isZero()) {
       const SCEV *X = getSCEV(LHS);
-      auto *UMin = dyn_cast<SCEVUMinExpr>(getSCEV(FalseVal));
-      if (UMin && is_contained(UMin->operands(), X))
-        return getUMinExpr(X, UMin, /*Sequential=*/true);
+      auto *FalseValExpr = dyn_cast<SCEVNAryExpr>(getSCEV(FalseVal));
+      if (FalseValExpr &&
+          (FalseValExpr->getSCEVType() == scUMinExpr ||
+           FalseValExpr->getSCEVType() == scSequentialUMinExpr) &&
+          is_contained(FalseValExpr->operands(), X))
+        return getUMinExpr(X, FalseValExpr, /*Sequential=*/true);
     }
     break;
   default:

diff  --git a/llvm/test/Analysis/ScalarEvolution/logical-operations.ll b/llvm/test/Analysis/ScalarEvolution/logical-operations.ll
index 1dde49a1a6c4..4456d2eb6a4b 100644
--- a/llvm/test/Analysis/ScalarEvolution/logical-operations.ll
+++ b/llvm/test/Analysis/ScalarEvolution/logical-operations.ll
@@ -587,7 +587,7 @@ define i32 @umin_seq_x_x_y_z(i32 %x, i32 %y, i32 %z) {
 ; CHECK-NEXT:    %r0 = select i1 %x.is.zero, i32 0, i32 %umin
 ; CHECK-NEXT:    --> (%x umin_seq (%y umin %z)) U: full-set S: full-set
 ; CHECK-NEXT:    %r = select i1 %x.is.zero, i32 0, i32 %r0
-; CHECK-NEXT:    --> %r U: full-set S: full-set
+; CHECK-NEXT:    --> (%x umin_seq (%y umin %z)) U: full-set S: full-set
 ; CHECK-NEXT:  Determining loop execution counts for: @umin_seq_x_x_y_z
 ;
   %umin0 = call i32 @llvm.umin(i32 %z, i32 %x)


        


More information about the llvm-commits mailing list