# Incorrect loop unroll using loopUnrollJamUpToFactor() and loopUnrollJamByFactor()

Hello all!
I’m trying to unroll the following loop

``````#map2 = affine_map<(d0) -> (480, d0 * -480 + 2048)>
.... ....
affine.for %arg4 = 0 to 5 {
... ...
affine.for %arg8 = 0 to min #map2(%arg4) {  (*)
``````

with unroll factor value =7 (if I use unroll factor={2,4,8}, everything works well).
After loopUnrollJamUpToFactor() is done, in the output IR I can see the following couple of loops instead of initial single loop (*):

``````#map2 = affine_map<(d0) -> (476, ((d0 * -480 + 2048) floordiv 7) * 7)>
#map13 = affine_map<(d0) -> (480, d0 * -480 + 2048)>
... ...
affine.for %arg8 = 0 to min #map2(%arg4) step 7 {
.... ....
}
affine.for %arg8 = max #map2(%arg4) to min #map13(%arg4) {
.... ....
}
``````

I agree, the first one is correct and its upper bound is min #map2(%arg4),
but why the lower bound of the second loop is max #map2(%arg4) while we have finished by value min #map2(%arg4) in the first loop?
It seems, the lower bound of the second loop should be the same as the upper bound of the 1-st one, i.e. should be min #map2(%arg4)…