[Mlir-commits] [mlir] [mlir][scf] Fix trip count signedness and overflow in SCF Utils (PR #178782)

Jhalak Patel llvmlistbot at llvm.org
Thu Jan 29 15:58:04 PST 2026


================
@@ -504,9 +516,13 @@ LogicalResult mlir::loopUnrollFull(scf::ForOp forOp) {
   const APInt &tripCount = *mayBeConstantTripCount;
   if (tripCount.isZero())
     return success();
-  if (tripCount.getZExtValue() == 1)
+  // Check for overflow before extracting trip count.
+  if (tripCount.getActiveBits() > 64)
----------------
jhalakpatel wrote:

It is not clear to me if this makes code less readable. Do we need to be this defensive?

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


More information about the Mlir-commits mailing list