]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
unroll.c (loop_iterations): Remove common term from initial and final value only...
authorUlrich Weigand <uweigand@de.ibm.com>
Mon, 23 May 2005 17:04:39 +0000 (17:04 +0000)
committerUlrich Weigand <uweigand@gcc.gnu.org>
Mon, 23 May 2005 17:04:39 +0000 (17:04 +0000)
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

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/20050510-1.c [new file with mode: 0644]
gcc/unroll.c

index a25b92c61be7024f6b8fcc17766aeaf3bc7ccbc8..8d7ebacf37d949e523699728ec272770357166e8 100644 (file)
@@ -1,3 +1,8 @@
+2005-05-23  Ulrich Weigand  <uweigand@de.ibm.com>
+
+       * unroll.c (loop_iterations): Remove common term from initial
+       and final value only if it is loop invariant.
+
 2005-05-20  Mark Mitchell  <mark@codesourcery.com>
 
        * version.c (version_string): Mark as 3.4.5.
index 391be56c8518a91a47d38ec02f2f6b6a8fe5bf8c..710ee0a1dc77ce23ef0a73915414c97377488765 100644 (file)
@@ -1,3 +1,7 @@
+2005-05-23  Ulrich Weigand  <uweigand@de.ibm.com>
+
+       * 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 (file)
index 0000000..49a11d5
--- /dev/null
@@ -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);
+}
+
index 518e4a1168ed8b5df4100b83548d9cedeb1e1c90..8d0d5d4993ecf0b566c843ca43af3ef6819b200d 100644 (file)
@@ -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);