[llvm] [SCEV] Fold zext(C+A)<nsw> -> (sext(C) + zext(A))<nsw> if possible. (PR #142599)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 5 08:13:21 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.
----------------
nikic wrote:
The core issue here seems to be that pushing sext through add nsw is a non-reversible transform. You can convert sext of add nsw to add nsw of sext, but you generally can't go from add nsw of sext to sext of add.
But given that SCEV does that in general, it probably makes sense to still do it here as well.
https://github.com/llvm/llvm-project/pull/142599
More information about the llvm-commits
mailing list