[Mlir-commits] [mlir] [mlir][scf] Clamp normalized loop sizes where they are combined (PR #223256)
Aviad Cohen
llvmlistbot at llvm.org
Wed Sep 23 00:06:29 PDT 2026
================
@@ -989,6 +989,21 @@ delinearizeInductionVariable(RewriterBase &rewriter, Location loc,
return {delinearizedIvs, preservedUsers};
}
+/// Clamp a normalized loop size at zero. `emitNormalizedLoopBounds` returns
+/// `ceilDiv(ub - lb, step)`, which is negative for an empty loop: combining two
+/// such sizes cancels the signs into a positive extent, and a negative value is
+/// not a legal `affine.delinearize_index` basis.
+static Value clampSizeToNonNegative(RewriterBase &rewriter, Location loc,
+ Value size) {
+ if (auto cst = getConstantIntValue(size))
+ return *cst >= 0 ? size
+ : getValueOrCreateConstantIntOp(rewriter, loc,
+ rewriter.getIndexAttr(0));
----------------
AviadCo wrote:
nit: `rewriter.getIndexAttr(0)` -> `rewriter.getZeroAttr(size.getType())`
https://github.com/llvm/llvm-project/pull/223256
More information about the Mlir-commits
mailing list