diff options
author | Alan Modra <amodra@bigpond.net.au> | 2002-07-20 00:31:15 +0000 |
---|---|---|
committer | Alan Modra <amodra@gcc.gnu.org> | 2002-07-20 10:01:15 +0930 |
commit | 8b583747adc3a9e670930481b828550fdcc18860 (patch) | |
tree | 94eedd6796f702b3e750b75344a9180da4a76c79 /gcc/doloop.c | |
parent | 0dc36574afc7846defc8751c3e19e4c994e0de4a (diff) | |
download | gcc-8b583747adc3a9e670930481b828550fdcc18860.zip gcc-8b583747adc3a9e670930481b828550fdcc18860.tar.gz gcc-8b583747adc3a9e670930481b828550fdcc18860.tar.bz2 |
re PR rtl-optimization/7130 (miscompiled code for gcc-3.1 on powerpc-unknown-linux-gnu with -funroll-all-loops)
PR optimization/7130
* loop.h (struct loop_info): Add "preconditioned".
* unroll.c (unroll_loop): Set it.
* doloop.c (doloop_modify_runtime): Correct count for unrolled loops.
From-SVN: r55598
Diffstat (limited to 'gcc/doloop.c')
-rw-r--r-- | gcc/doloop.c | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/gcc/doloop.c b/gcc/doloop.c index ee5b788..9bddb92 100644 --- a/gcc/doloop.c +++ b/gcc/doloop.c @@ -552,6 +552,7 @@ doloop_modify_runtime (loop, iterations_max, { const struct loop_info *loop_info = LOOP_INFO (loop); HOST_WIDE_INT abs_inc; + HOST_WIDE_INT abs_loop_inc; int neg_inc; rtx diff; rtx sequence; @@ -595,13 +596,18 @@ doloop_modify_runtime (loop, iterations_max, except in cases where the loop never terminates. So we don't need to use this more costly calculation. - If the loop has been unrolled, then the loop body has been - preconditioned to iterate a multiple of unroll_number times. If - abs_inc is != 1, the full calculation is + If the loop has been unrolled, the full calculation is - t1 = abs_inc * unroll_number; - n = abs (final - initial) / t1; - n += (abs (final - initial) % t1) > t1 - abs_inc; + t1 = abs_inc * unroll_number; increment per loop + n = abs (final - initial) / t1; full loops + n += (abs (final - initial) % t1) != 0; partial loop + + However, in certain cases the unrolled loop will be preconditioned + by emitting copies of the loop body with conditional branches, + so that the unrolled loop is always a full loop and thus needs + no exit tests. In this case we don't want to add the partial + loop count. As above, when t1 is a power of two we don't need to + worry about overflow. The division and modulo operations can be avoided by requiring that the increment is a power of 2 (precondition_loop_p enforces @@ -667,20 +673,22 @@ doloop_modify_runtime (loop, iterations_max, } } - if (abs_inc * loop_info->unroll_number != 1) + abs_loop_inc = abs_inc * loop_info->unroll_number; + if (abs_loop_inc != 1) { int shift_count; - shift_count = exact_log2 (abs_inc * loop_info->unroll_number); + shift_count = exact_log2 (abs_loop_inc); if (shift_count < 0) abort (); - if (abs_inc != 1) + if (!loop_info->preconditioned) diff = expand_simple_binop (GET_MODE (diff), PLUS, - diff, GEN_INT (abs_inc - 1), + diff, GEN_INT (abs_loop_inc - 1), diff, 1, OPTAB_LIB_WIDEN); - /* (abs (final - initial) + abs_inc - 1) / (abs_inc * unroll_number) */ + /* (abs (final - initial) + abs_inc * unroll_number - 1) + / (abs_inc * unroll_number) */ diff = expand_simple_binop (GET_MODE (diff), LSHIFTRT, diff, GEN_INT (shift_count), diff, 1, OPTAB_LIB_WIDEN); |