[Mlir-commits] [mlir] [mlir][affine] Use value bound inference to determine minimum/maximum trip counts in loop analysis (PR #128113)

lonely eagle llvmlistbot at llvm.org
Mon May 5 07:58:01 PDT 2025


linuxlonelyeagle wrote:

> Looking over the PR again, I think there's a different phrasing of the proposed improvement that'll behave better but might require some comments and/or refactoring.
> 
> Suppose we have a loop where the lower bounds are L = {l1, l2, ... lM}, and the upper bounds are U = {u1, u2, ..., uN} and step S . This means that the trip count T is bounded by `min(U) - max(L)) ceildiv S <= T <= (max(U) - min(L)) ceildiv S`.
> 
> Now, for non-constant l_i and u_i, we can sometimes use the value bounds analysis to determine their minima or maxima, and use those in those min/max bounds. That is, if I have `%x` such that I know `0 <= %x <= 63`, than `max({x})` would be `63` and `min({x})` would be `0`.
> 
> So, a transformation I'm convinced of - and one that maybe should be in loop normalization, it's hard to tell, is noting that if the bounds on the trip count are `1 <= T <= 1`, the loop is trivial, and if we have `0 <= T <= 1`, then this loop is just an `affine.if min(U) > max(L)`.
> 
> I think where unrolling comes in is that if T >= n * F for some unrolling factor F, you can unroll n iterations of the loop, and then your lower bound becomes `{l1, 2, ..., ln} - n * F * S` and your upper bound becomes `{u1, u2, ..., uN} - n * F * S`.
> 
> Please poke me if either my math's wrong or I haven't summarized the proposed change correctly
> 
> (This got lost in my tabs, apologies for the late response. I think there's something here, it's just an area where it's important to be rather careful with the details)

I have something very important to do these days. When I'm done with them, I'll move forward on it.Thank you.

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


More information about the Mlir-commits mailing list