AST generator: select unroll lower bound introducing fewest integer divisions
In some exceptional cases, there may be multiple lower bounds that can
be used for unrolling and that result in the same number of iterations.
For example, for the new test case, there are currently two such bounds
and one of them results in
{
if (t1 >= 126)
S(0, t1 - 384);
S(0, t1 - 256);
if (t1 >= 126)
S(1, t1 - 384);
S(1, t1 - 256);
}
while the other results in
{
if (t1 >= 126 || (t1 == 125 && t2 == 256))
S(0, t1 >= 126 ? t1 - 384 : -131);
if (t1 + 130 >= t2)
S(0, t1 - 256);
if (t1 >= 126 || (t1 == 125 && t2 == 256))
S(1, t1 >= 126 ? t1 - 384 : -131);
if (t1 + 130 >= t2)
S(1, t1 - 256);
}
In principle, it should be possible to obtain a single quasi-affine
expression (without disjunction) in the second case, but even if we did,
it would contain an integer division, so we would still prefer the first case.
In general, if the number of resulting iterations is the same,
we pick the lower bound with the least number of resulting
integer divisions.
Reported-by: Tobias Grosser <tobias@grosser.es>
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>