From bbda30a4aae700f963fd164edbeac4f4688bf2a0 Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Mon, 21 Jul 2003 18:52:38 +0200 Subject: [PATCH] re PR rtl-optimization/11536 ([strength-reduce] -O2 optimalization produces wrong code) PR optimization/11536 * unroll.c (loop_iterations): Do not replace a register holding the final value by its equivalent before the loop if it is not invariant. PR optimization/11536 * gcc.dg/20030721-1.c: New test. From-SVN: r69635 --- gcc/ChangeLog | 7 ++++++ gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/gcc.dg/20030721-1.c | 41 +++++++++++++++++++++++++++++++ gcc/unroll.c | 2 +- 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/20030721-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b120c1501eb..180fc69f843 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2003-07-17 Eric Botcazou + + PR optimization/11536 + * unroll.c (loop_iterations): Do not replace a register holding + the final value by its equivalent before the loop if it is not + invariant. + 2003-07-21 Dave Fluri * doc/extend.texi: Fixes to spelling, grammar, and diction. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 96b04a57764..1cfa9361195 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2003-07-21 Eric Botcazou + + PR optimization/11536 + * gcc.dg/20030721-1.c: New test. + 2003-07-19 Mark Mitchell PR c++/11546 diff --git a/gcc/testsuite/gcc.dg/20030721-1.c b/gcc/testsuite/gcc.dg/20030721-1.c new file mode 100644 index 00000000000..5e8ed0b434a --- /dev/null +++ b/gcc/testsuite/gcc.dg/20030721-1.c @@ -0,0 +1,41 @@ +/* { dg-options "-O2" } */ +/* PR optimization/11536 */ +/* Origin: samal@kam.mff.cuni.cz */ +/* Testcase by Andrew Pinski */ + +/* Verify that the loop optimizer doesn't use moving targets + to calculate the number of iterations of a loop. */ + +extern void abort(void); + +void foo(int) __attribute__((__noinline__)); + +void foo(int i) +{ + abort(); +} + +int main() +{ + int i; + int first= 0; + int last= 0; + + while (last<3) { + last = first; + + while (first<=last) { + first++; + + for (i=0;i<3;i++) + last++; + + if (last>10) + return 0; + } + + foo(first); + } + + return 0; +} diff --git a/gcc/unroll.c b/gcc/unroll.c index 62b8152daf4..1c66b13fe78 100644 --- a/gcc/unroll.c +++ b/gcc/unroll.c @@ -3618,7 +3618,7 @@ loop_iterations (struct loop *loop) if (find_common_reg_term (temp, reg2)) initial_value = temp; - else + else if (loop_invariant_p (loop, reg2)) { /* Find what reg2 is equivalent to. Hopefully it will either be reg1 or reg1 plus a constant. Let's ignore -- 2.30.2