[Mlir-commits] [mlir] [mlir][scf] Fix trip count signedness and overflow in SCF Utils (PR #178782)
Matthias Springer
llvmlistbot at llvm.org
Fri Jan 30 09:30:31 PST 2026
================
@@ -1563,22 +1589,30 @@ bool mlir::isPerfectlyNestedForLoops(
return true;
}
-llvm::SmallVector<int64_t>
+llvm::SmallVector<uint64_t>
mlir::getConstLoopTripCounts(mlir::LoopLikeOpInterface loopOp) {
std::optional<SmallVector<OpFoldResult>> loBnds = loopOp.getLoopLowerBounds();
std::optional<SmallVector<OpFoldResult>> upBnds = loopOp.getLoopUpperBounds();
std::optional<SmallVector<OpFoldResult>> steps = loopOp.getLoopSteps();
if (!loBnds || !upBnds || !steps)
return {};
- // TODO(#178506): The result should be SmallVector<uint64_t> and use uint64_t
- // for trip counts.
- llvm::SmallVector<int64_t> tripCounts;
+
+ // Determine signedness from the loop operation if possible.
+ // For scf::ForOp, use the loop's comparison signedness via getUnsignedCmp().
+ // Otherwise, default to signed (most MLIR integer types are signed).
+ bool isSigned = true;
+ if (auto forOp = dyn_cast<scf::ForOp>(loopOp.getOperation()))
----------------
matthias-springer wrote:
I wouldn't hard-code `scf.for` here. The right way is likely to add an `isSigned` interface method to the `LoopLikeOpInterface` (in a separate PR; keeping the TODO is also fine).
https://github.com/llvm/llvm-project/pull/178782
More information about the Mlir-commits
mailing list