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

Matthias Springer llvmlistbot at llvm.org
Sat Jan 31 00:51:05 PST 2026


================
@@ -1610,15 +1605,16 @@ FailureOr<scf::ParallelOp> mlir::parallelLoopUnrollByFactors(
 
   // Make sure that the unroll factors divide the iteration space evenly
   // TODO: Support unrolling loops with dynamic iteration spaces.
-  const llvm::SmallVector<int64_t> tripCounts = getConstLoopTripCounts(op);
+  const llvm::SmallVector<llvm::APInt> tripCounts = getConstLoopTripCounts(op);
   if (tripCounts.empty())
     return rewriter.notifyMatchFailure(
         op, "Failed to compute constant trip counts for the loop. Note that "
             "dynamic loop sizes are not supported.");
 
   for (unsigned dimIdx = firstLoopDimIdx; dimIdx < numLoops; dimIdx++) {
     const uint64_t unrollFactor = unrollFactors[dimIdx - firstLoopDimIdx];
-    if (tripCounts[dimIdx] % unrollFactor)
+    const uint64_t tripCount = tripCounts[dimIdx].getZExtValue();
+    if (tripCount % unrollFactor != 0)
----------------
matthias-springer wrote:

nit: `tripCounts[dimIdx].urem(unrollFactor) != 0`

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


More information about the Mlir-commits mailing list