[Mlir-commits] [mlir] [MLIR] Add a getStaticTripCount method to LoopLikeOpInterface (PR #158679)

Mehdi Amini llvmlistbot at llvm.org
Tue Sep 16 05:12:21 PDT 2025


================
@@ -201,9 +205,24 @@ foldDynamicOffsetSizeList(SmallVectorImpl<OpFoldResult> &offsetsOrSizes);
 LogicalResult foldDynamicStrideList(SmallVectorImpl<OpFoldResult> &strides);
 
 /// Return the number of iterations for a loop with a lower bound `lb`, upper
-/// bound `ub` and step `step`.
-std::optional<int64_t> constantTripCount(OpFoldResult lb, OpFoldResult ub,
-                                         OpFoldResult step);
+/// bound `ub` and step `step`. The `isSigned` flag indicates whether the loop
+/// comparison between lb and ub is signed or unsigned. A negative step or a
+/// lower bound greater than the upper bound are considered invalid and will
+/// yield a zero trip count.
+/// The `computeUbMinusLb` callback is invoked to compute the difference between
+/// the upper and lower bound when not constant. It can be used by the client
+/// to match the pattern:
----------------
joker-eph wrote:

Actually here we don't hard-code anything, hence the callback!
This was an example to motivate why we take a callback, it illustrates the kind of things the client of the API can do, I'll tweak the wording.

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


More information about the Mlir-commits mailing list