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

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sat Oct 31 20:53:35 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);
----------------
sun-jacobi wrote:

Fixed.

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


More information about the Mlir-commits mailing list