OSDN Git Service

PR optimization/11536
authormmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 21 Jul 2003 16:52:38 +0000 (16:52 +0000)
committermmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 21 Jul 2003 16:52:38 +0000 (16:52 +0000)
* 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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@69635 138bc75d-0d04-0410-961f-82ee72b054a4

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

index b120c15..180fc69 100644 (file)
@@ -1,3 +1,10 @@
+2003-07-17  Eric Botcazou  <ebotcazou@libertysurf.fr>
+
+        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  <dave.fluri@onlink.net>
 
        * doc/extend.texi: Fixes to spelling, grammar, and diction.
index 96b04a5..1cfa936 100644 (file)
@@ -1,3 +1,8 @@
+2003-07-21  Eric Botcazou  <ebotcazou@libertysurf.fr>
+
+        PR optimization/11536
+       * gcc.dg/20030721-1.c: New test.
+
 2003-07-19  Mark Mitchell  <mark@codesourcery.com>
 
        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 (file)
index 0000000..5e8ed0b
--- /dev/null
@@ -0,0 +1,41 @@
+/* { dg-options "-O2" } */
+/* PR optimization/11536 */
+/* Origin: samal@kam.mff.cuni.cz <samal@kam.mff.cuni.cz> */
+/* Testcase by Andrew Pinski <pinskia@physics.uc.edu> */
+
+/* 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;
+}
index 62b8152..1c66b13 100644 (file)
@@ -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