[llvm] [SCEV] Try to fold ZExt/SExt of AddRec before existing lookup. (PR #208805)

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 15 01:27:05 PDT 2026


================
@@ -1701,6 +1701,18 @@ const SCEV *ScalarEvolution::getZeroExtendExprImpl(const SCEV *Op, Type *Ty,
   if (const SCEVZeroExtendExpr *SZ = dyn_cast<SCEVZeroExtendExpr>(Op))
     return getZeroExtendExpr(SZ->getOperand(), Ty, Depth + 1);
 
+  // If the operand is an affine AddRec with the no-unsigned-wrap flag, the
+  // zero-extension distributes over the recurrence.
+  if (Depth <= MaxCastDepth)
+    if (const auto *AR = dyn_cast<SCEVAddRecExpr>(Op))
+      if (AR->isAffine() && AR->hasNoUnsignedWrap()) {
----------------
artagnon wrote:

Could write this as m_scev_AffineAddRec capturing an m_Loop?

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


More information about the llvm-commits mailing list