select "best" lower bound for unrolling
When support for unrolling was added in
7f6868b (add support for
unrolling, Thu May 12 16:22:49 2011 +0200), it was restricted
to loops with only a single lower bound. This was relaxed in
a0c4004 (allow unrolling of loops with multiple lower bounds,
Fri Jun 3 15:04:07 2011 +0200), but the new code would simply
pick the first appropriate lower bound it could find.
Since the iteration domain is sliced in parallel to the lower bound,
different lower bounds may lead to different numbers of iterations.
In some cases this difference can be quite dramatic.
We now pick the lower bound that results in the smallest number
of slices. Note however that some of those slices may be empty,
so this choice does not always guarantee that the smallest
code will be generated.
As an example, for the newly added test case, we now generate
if ((M >= -1) && (M <= 9)) {
if (M >= 0) {
S1(M);
}
S1(M+1);
}
whereas before we would generate
if ((M >= -1) && (M <= 9)) {
if (M <= 0) {
S1(0);
}
if ((M >= 0) && (M <= 1)) {
S1(1);
}
if ((M >= 1) && (M <= 2)) {
S1(2);
}
if ((M >= 2) && (M <= 3)) {
S1(3);
}
if ((M >= 3) && (M <= 4)) {
S1(4);
}
if ((M >= 4) && (M <= 5)) {
S1(5);
}
if ((M >= 5) && (M <= 6)) {
S1(6);
}
if ((M >= 6) && (M <= 7)) {
S1(7);
}
if ((M >= 7) && (M <= 8)) {
S1(8);
}
if (M >= 8) {
S1(9);
}
if (M == 9) {
S1(10);
}
}
Reported-by: Carlos Juega Reimundez <cjuega@fdi.ucm.es>
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
Signed-off-by: Tobias Grosser <tobias@grosser.es>