AST generator: select unroll lower bound introducing fewest integer divisions
commita3975036c375bcc21f27c95a6bd9c08d28d3fa35
authorSven Verdoolaege <skimo@kotnet.org>
Sat, 20 Dec 2014 10:50:01 +0000 (20 11:50 +0100)
committerSven Verdoolaege <skimo@kotnet.org>
Wed, 24 Dec 2014 09:36:56 +0000 (24 10:36 +0100)
tree4f684b0863423850bb7e2187cbb960fd7b9278db
parentaaad77e9f712bb4786a611989c43700104e25098
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>
isl_ast_codegen.c
test_inputs/codegen/unroll11.c [new file with mode: 0644]
test_inputs/codegen/unroll11.in [new file with mode: 0644]