]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR rtl-optimization/10171 (wrong code for inlined function)
authorJason Merrill <jason@redhat.com>
Tue, 25 Mar 2003 20:23:25 +0000 (15:23 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 25 Mar 2003 20:23:25 +0000 (15:23 -0500)
        PR optimization/10171
        * unroll.c (unroll_loop): Don't delete the jump at the end unless
        we also delete a jump at the beginning.

From-SVN: r64862

gcc/ChangeLog
gcc/unroll.c

index 4facc063b519b53d9db91ef56294f5433cbf9835..ebdd20c98d540a4e00dedafd6ee6c0b825720a2b 100644 (file)
@@ -1,3 +1,9 @@
+2003-03-25  Jason Merrill  <jason@redhat.com>
+
+       PR optimization/10171
+       * unroll.c (unroll_loop): Don't delete the jump at the end unless
+       we also delete a jump at the beginning.
+
 2003-03-25  Gerald Pfeifer  <pfeifer@dbai.tuwien.ac.at>
 
        * doc/passes.texi (Passes): Properly document that we do not
index b9232274add66fa9367cbd110fbcf06bf34b883d..7c24256532339021e1b775b91f8caa24dfe579a3 100644 (file)
@@ -353,9 +353,11 @@ unroll_loop (loop, insn_count, strength_reduce_p)
         jump to the loop condition.  Make sure to delete the jump
         insn, otherwise the loop body will never execute.  */
 
+      /* FIXME this actually checks for a jump to the continue point, which
+        is not the same as the condition in a for loop.  As a result, this
+        optimization fails for most for loops.  We should really use flow
+        information rather than instruction pattern matching.  */
       rtx ujump = ujump_to_loop_cont (loop->start, loop->cont);
-      if (ujump)
-       delete_related_insns (ujump);
 
       /* If number of iterations is exactly 1, then eliminate the compare and
         branch at the end of the loop since they will never be taken.
@@ -367,9 +369,10 @@ unroll_loop (loop, insn_count, strength_reduce_p)
       if (GET_CODE (last_loop_insn) == BARRIER)
        {
          /* Delete the jump insn.  This will delete the barrier also.  */
-         delete_related_insns (PREV_INSN (last_loop_insn));
+         last_loop_insn = PREV_INSN (last_loop_insn);
        }
-      else if (GET_CODE (last_loop_insn) == JUMP_INSN)
+
+      if (ujump && GET_CODE (last_loop_insn) == JUMP_INSN)
        {
 #ifdef HAVE_cc0
          rtx prev = PREV_INSN (last_loop_insn);
@@ -381,24 +384,27 @@ unroll_loop (loop, insn_count, strength_reduce_p)
          if (only_sets_cc0_p (prev))
            delete_related_insns (prev);
 #endif
-       }
 
-      /* Remove the loop notes since this is no longer a loop.  */
-      if (loop->vtop)
-       delete_related_insns (loop->vtop);
-      if (loop->cont)
-       delete_related_insns (loop->cont);
-      if (loop_start)
-       delete_related_insns (loop_start);
-      if (loop_end)
-       delete_related_insns (loop_end);
+         delete_related_insns (ujump);
 
-      return;
+         /* Remove the loop notes since this is no longer a loop.  */
+         if (loop->vtop)
+           delete_related_insns (loop->vtop);
+         if (loop->cont)
+           delete_related_insns (loop->cont);
+         if (loop_start)
+           delete_related_insns (loop_start);
+         if (loop_end)
+           delete_related_insns (loop_end);
+
+         return;
+       }
     }
-  else if (loop_info->n_iterations > 0
-          /* Avoid overflow in the next expression.  */
-          && loop_info->n_iterations < MAX_UNROLLED_INSNS
-          && loop_info->n_iterations * insn_count < MAX_UNROLLED_INSNS)
+
+  if (loop_info->n_iterations > 0
+      /* Avoid overflow in the next expression.  */
+      && loop_info->n_iterations < MAX_UNROLLED_INSNS
+      && loop_info->n_iterations * insn_count < MAX_UNROLLED_INSNS)
     {
       unroll_number = loop_info->n_iterations;
       unroll_type = UNROLL_COMPLETELY;