On Sat, Jan 13, 2024 at 09:08:00PM -0800, Shizhi Tang wrote:
> Hi there,
>
> Is it possible to keep expressions like `x mod y div z` in a set, map or
> aff? For example, I can construct a map with the following string:
>
> {[x] -> [floor((x mod 8) / 2)] : 0 <= x < 64}
>
> When I print it out, it becomes:
>
> { [x] -> [o0] : 0 <= x <= 63 and -1 + x - 2o0 <= 8*floor((x)/8) <= x - 2o0 }
>
> I want an explicit expression of o0, so I convert it into a pw_multi_aff,
> which becomes:
>
> { [x] -> [(4 - 3x - floor((1 + x)/2) + 4*floor((1 + 7x)/8))] : 0 <= x <= 63
> and 8*floor((1 - x)/8) < -x; [x] -> [(0)] : 0 <= x <= 63 and 8*floor((1 -
> x)/8) >= -x }
Which version of isl are you using and how did you perform the conversion?
I get
>>> isl.map("{ [x] -> [o0] : 0 <= x <= 63 and -1 + x - 2o0 <= 8*floor((x)/8) <= x - 2o0 }").as_pw_multi_aff()
isl.pw_multi_aff("{ [x] -> [(floor((x)/2) - 4*floor((x)/8))] : 0 <= x <= 63 }")
> Now it has even two parts. I am wondering whether it is a limitation from
> the form of affine expressions, or a limitation from isl's implementation?
> Is it possible to recover the floor((x mod 8) / 2) form from this map?
The representation of a set/map gets simplified in various ways.
In some cases this means that explicit representations of some dimensions
get lost.
isl can sometimes recover such explicit representations,
but this is based on heuristics, so not guaranteed to be as simple as possible.
If you need to preserve an explicit representation, it's best
not to convert it to a set/map first.
Also note that there is no internal representation for "mod",
so it will get encoded in terms of "floor".
The AST generator, on the other hand, will try and detect "mod" operations,
but this is again based on heuristics.
skimo