[llvm] [SCEV] Fold zext(C+A)<nsw> -> (sext(C) + zext(A))<nsw> if possible. (PR #142599)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 3 14:09:34 PDT 2025


================
@@ -1793,6 +1793,18 @@ const SCEV *ScalarEvolution::getZeroExtendExprImpl(const SCEV *Op, Type *Ty,
       return getAddExpr(Ops, SCEV::FlagNUW, Depth + 1);
     }
 
+    const SCEVConstant *C;
+    const SCEV *A;
+    // zext (C + A)<nsw> -> (sext(C) + zext(A))<nsw> if zext (C + A)<nsw> >=s 0
+    // and A >=s V.
----------------
fhahn wrote:

Here are some changes with the generalization: https://github.com/llvm/llvm-project/pull/142599/commits/7f8f9370d9849921580d19c09ec1ff91b1351b65

* in `@add_nsw_zext_fold_results_in_sext` we have a in more complex expansion
* in  `@fold_add_zext_to_sext` we miss some re-use during expansion.

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


More information about the llvm-commits mailing list