[llvm] [SECV] Try to push the op into ZExt: A + zext (-A + B) -> zext (B) (PR #151227)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 31 02:47:37 PDT 2025


================
@@ -2682,6 +2682,21 @@ const SCEV *ScalarEvolution::getAddExpr(SmallVectorImpl<const SCEV *> &Ops,
         return getAddExpr(NewOps, PreservedFlags);
       }
     }
+
+    // Try to push the constant operand into a ZExt: A + zext (-A + B) -> zext
+    // (B), if trunc (A) + -A + B  does not unsigned-wrap.
+    if (auto *ZExt = dyn_cast<SCEVZeroExtendExpr>(Ops[1])) {
+      const SCEV *B = ZExt->getOperand(0);
+      const SCEV *NarrowA = getTruncateExpr(A, B->getType());
----------------
nikic wrote:

Check `isa<SCEVAddExpr>(B)` before computing `getTruncateExpr`?

https://github.com/llvm/llvm-project/pull/151227


More information about the llvm-commits mailing list