From: Eric Botcazou Date: Sat, 21 Dec 2002 20:31:15 +0000 (+0100) Subject: re PR rtl-optimization/8599 (loop unroll bug with -march=k6-3) X-Git-Tag: releases/gcc-3.2.2~161 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5402998384c858ca8e4a34ea12c80a6706852e6b;p=thirdparty%2Fgcc.git re PR rtl-optimization/8599 (loop unroll bug with -march=k6-3) PR optimization/8599 * doloop.c (doloop_modify_runtime): Fix loop count computation for preconditioned unrolled loops. From-SVN: r60393 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 82630b7c41c9..fd31004539e2 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2002-12-21 Eric Botcazou + + PR optimization/8599 + * doloop.c (doloop_modify_runtime): Fix loop count computation + for preconditioned unrolled loops. + 2002-12-21 Eric Botcazou PR optimization/8599 diff --git a/gcc/doloop.c b/gcc/doloop.c index 06d8d5734853..25deb503717e 100644 --- a/gcc/doloop.c +++ b/gcc/doloop.c @@ -598,9 +598,13 @@ doloop_modify_runtime (loop, iterations_max, If the loop has been unrolled, the full calculation is - t1 = abs_inc * unroll_number; increment per loop - n = abs (final - initial) / t1; full loops - n += (abs (final - initial) % t1) != 0; partial loop + t1 = abs_inc * unroll_number; increment per loop + n = (abs (final - initial) + abs_inc - 1) / t1; full loops + n += ((abs (final - initial) + abs_inc - 1) % t1) >= abs_inc; + partial loop + which works out to be equivalent to + + n = (abs (final - initial) + t1 - 1) / t1; However, in certain cases the unrolled loop will be preconditioned by emitting copies of the loop body with conditional branches, @@ -682,13 +686,15 @@ doloop_modify_runtime (loop, iterations_max, if (shift_count < 0) abort (); - if (!loop_info->preconditioned) + if (loop_info->preconditioned) + diff = expand_simple_binop (GET_MODE (diff), PLUS, + diff, GEN_INT (abs_inc - 1), + diff, 1, OPTAB_LIB_WIDEN); + else diff = expand_simple_binop (GET_MODE (diff), PLUS, diff, GEN_INT (abs_loop_inc - 1), diff, 1, OPTAB_LIB_WIDEN); - /* (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);