[llvm] [SCEV] Distribute zext across (C + Rest) in LoopGuards rewriter (PR #210719)
Aleksandr Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 7 08:27:45 PDT 2026
================
@@ -16424,6 +16424,30 @@ const SCEV *ScalarEvolution::LoopGuards::rewrite(const SCEV *Expr) const {
Bitwidth = Bitwidth / 2;
}
+ // Pull a leading constant out of the zext:
+ // zext(C + X) -> zext(X) - zext(-C), if X >=u -C.
+ const SCEVAddExpr *Add;
+ const APInt *C;
+ if (match(Op, m_scev_Add(Add)) &&
----------------
aleks-tmb wrote:
Thanks for the pointer. I tried the “rewrite Op first, then match (C + X)” approach. On your IR, it produces byte-identical opt output compared to the current code for -passes=loop-unroll (with and without -unroll-runtime), -passes='loop-mssa(indvars,loop-unroll)', and default<O2>.
For the two-operand -C + X case with plain ULE/UGE clamp guards, visit(Op) still returns an Add with the same leading constant, so the match fires and the distribution proceeds identically.
Could you share the exact opt invocation and the expected unrolled output? I’d like to make sure the fix targets the actual regression.
https://github.com/llvm/llvm-project/pull/210719
More information about the llvm-commits
mailing list