[Mlir-commits] [mlir] [MLIR][SCF] Handle empty loop ranges in mlir::loopUnrollByFactor. (PR #237094)

Matthias Springer llvmlistbot at llvm.org
Sat Oct 31 11:51:22 PDT 2026


================
@@ -513,6 +513,17 @@ FailureOr<UnrolledLoopInfo> mlir::loopUnrollByFactor(
     auto upperBound = forOp.getUpperBound();
     Value diff =
         arith::SubIOp::create(boundsBuilder, loc, upperBound, lowerBound);
+
+    Value zero = arith::ConstantOp::create(
+        boundsBuilder, loc, boundsBuilder.getZeroAttr(diff.getType()));
+    if (forOp.getUnsignedCmp()) {
+      Value nonEmpty =
+          arith::CmpIOp::create(boundsBuilder, loc, arith::CmpIPredicate::ult,
+                                lowerBound, upperBound);
+      diff = arith::SelectOp::create(boundsBuilder, loc, nonEmpty, diff, zero);
+    } else
+      diff = arith::MaxSIOp::create(boundsBuilder, loc, diff, zero);
----------------
matthias-springer wrote:

nit: can you keep the unsigned/signed cases symmetric? I.e. use `max` or `cmpi+select `in both cases.

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


More information about the Mlir-commits mailing list