jump.c (duplicate_loop_exit_test): Better test for jumps entering the loop; create...
authorJan Hubicka <jh@suse.cz>
Tue, 31 Jul 2001 13:36:12 +0000 (15:36 +0200)
committerJan Hubicka <hubicka@gcc.gnu.org>
Tue, 31 Jul 2001 13:36:12 +0000 (13:36 +0000)
* jump.c (duplicate_loop_exit_test): Better test for jumps
entering the loop; create loop pre_header.

From-SVN: r44512

gcc/ChangeLog
gcc/jump.c

index 85b915b75e37fc3427a08c527a26bab660563f34..461b9023af3154406165b04dc67ddf16f4c420af 100644 (file)
@@ -1,3 +1,8 @@
+Tue Jul 31 15:33:27 CEST 2001  Jan Hubicka  <jh@suse.cz>
+
+       * jump.c (duplicate_loop_exit_test): Better test for jumps
+       entering the loop; create loop pre_header.
+
 2001-07-31 Hartmut Penner <hpenner@de.ibm.com>
 
         * doc/install.texi: Add s390 and s390x as new targets.
index ddef4a1453ce126145d8e79c9d7e35b063f1d24a..dd099f2a84098633325b536905cb78e898a86cd5 100644 (file)
@@ -305,6 +305,7 @@ duplicate_loop_exit_test (loop_start)
   rtx lastexit;
   int max_reg = max_reg_num ();
   rtx *reg_map = 0;
+  rtx loop_pre_header_label;
 
   /* Scan the exit code.  We do not perform this optimization if any insn:
 
@@ -405,6 +406,7 @@ duplicate_loop_exit_test (loop_start)
            reg_map[REGNO (reg)] = gen_reg_rtx (GET_MODE (reg));
          }
       }
+  loop_pre_header_label = gen_label_rtx ();
 
   /* Now copy each insn.  */
   for (insn = exitcode; insn != lastexit; insn = NEXT_INSN (insn))
@@ -475,9 +477,14 @@ duplicate_loop_exit_test (loop_start)
                  /* The jump_insn after loop_start should be followed
                     by barrier and loopback label.  */
                  if (prev_nonnote_insn (label)
-                     && (PREV_INSN (prev_nonnote_insn (label))
-                         == NEXT_INSN (loop_start)))
-                   predict_insn_def (copy, PRED_LOOP_HEADER, TAKEN);
+                     && (prev_nonnote_insn (prev_nonnote_insn (label))
+                         == next_nonnote_insn (loop_start)))
+                   {
+                     predict_insn_def (copy, PRED_LOOP_HEADER, TAKEN);
+                     /* To keep pre-header, we need to redirect all loop
+                        entrances before the LOOP_BEG note.  */
+                     redirect_jump (copy, loop_pre_header_label, 0);
+                   }
                  else
                    predict_insn_def (copy, PRED_LOOP_HEADER, NOT_TAKEN);
                }
@@ -512,6 +519,8 @@ duplicate_loop_exit_test (loop_start)
       emit_barrier_before (loop_start);
     }
 
+  emit_label_before (loop_pre_header_label, loop_start);
+
   /* Now scan from the first insn we copied to the last insn we copied
      (copy) for new pseudo registers.  Do this after the code to jump to
      the end label since that might create a new pseudo too.  */