From: Ulrich Weigand Date: Mon, 23 May 2005 17:04:39 +0000 (+0000) Subject: unroll.c (loop_iterations): Remove common term from initial and final value only... X-Git-Tag: releases/gcc-3.4.5~412 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=810fc2d3d64676dd2179e669f5732e9b43f5f799;p=thirdparty%2Fgcc.git unroll.c (loop_iterations): Remove common term from initial and final value only if it is loop invariant. ChangeLog: * unroll.c (loop_iterations): Remove common term from initial and final value only if it is loop invariant. testsuite/ChangeLog: * gcc.dg/20050510-1.c: New test. From-SVN: r100085 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a25b92c61be7..8d7ebacf37d9 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2005-05-23 Ulrich Weigand + + * unroll.c (loop_iterations): Remove common term from initial + and final value only if it is loop invariant. + 2005-05-20 Mark Mitchell * version.c (version_string): Mark as 3.4.5. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 391be56c8518..710ee0a1dc77 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2005-05-23 Ulrich Weigand + + * gcc.dg/20050510-1.c: New test. + 2005-05-19 Release Manager * GCC 3.4.4 released. diff --git a/gcc/testsuite/gcc.dg/20050510-1.c b/gcc/testsuite/gcc.dg/20050510-1.c new file mode 100644 index 000000000000..49a11d551592 --- /dev/null +++ b/gcc/testsuite/gcc.dg/20050510-1.c @@ -0,0 +1,31 @@ +/* This used to abort due to incorrect loop iteration count computation. */ + +/* { dg-do run } */ +/* { dg-options "-O2" } */ + +int test (unsigned char *data) +{ + unsigned char *top; + unsigned char *bottom; + unsigned int i = 0; + + for (bottom = data, top = data + 36; + top > bottom; + bottom++, top--) + { + i++; + } + + return i; +} + +int main (void) +{ + unsigned char buffer[36]; + + if (test (buffer) != 18) + abort (); + + exit (0); +} + diff --git a/gcc/unroll.c b/gcc/unroll.c index 518e4a1168ed..8d0d5d4993ec 100644 --- a/gcc/unroll.c +++ b/gcc/unroll.c @@ -3691,7 +3691,8 @@ loop_iterations (struct loop *loop) ??? Without a vtop we could still perform the optimization if we check the initial and final values carefully. */ if (loop->vtop - && (reg_term = find_common_reg_term (initial_value, final_value))) + && (reg_term = find_common_reg_term (initial_value, final_value)) + && loop_invariant_p (loop, reg_term)) { initial_value = subtract_reg_term (initial_value, reg_term); final_value = subtract_reg_term (final_value, reg_term);