[Mlir-commits] [mlir] [mlir][scf] Fix trip count signedness and overflow in SCF Utils (PR #178782)
Jhalak Patel
llvmlistbot at llvm.org
Fri Jan 30 10:03:24 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()))
----------------
jhalakpatel wrote:
Good idea. We can follow that up in a separate PR.
https://github.com/llvm/llvm-project/pull/178782
More information about the Mlir-commits
mailing list