This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix cprop_jump conversion of a conditional jump into unconditional jump (PR rtl-optimization/33673)


Hi!

cprop_jump is only called in cfglayout mode and in some cases changes
an conditional jump into an unconditional one.  As I was told unconditional
jumps aren't desirable in cfglayout mode, instead the basic block should
have just a fallthru edge to where it needs to actually jump to.
Otherwise (e.g. on the attached testcase on ppc-linux -m32) there won't be
a barrier after the jump and the compiler ICEs when verifying out of
cfglayout.  Only delete_insn (jump) in this case isn't sufficient, it ICEs
shortly after because there is no fallthru edge and no branch at the end of
the bb.

Bootstrapped/regtested on x86_64-linux, the testcase also tested on ppc-linux.

Ok for trunk?

2007-10-30  Jakub Jelinek  <jakub@redhat.com>

	PR rtl-optimization/33673
	* gcse.c (cprop_jump): If a conditional jump has been optimized
	into unconditional jump, make the remaining normal edge fallthru
	and delete the jump insn.

	* gcc.dg/pr33673.c: New test.

--- gcc/gcse.c.jj	2007-10-12 00:24:09.000000000 +0200
+++ gcc/gcse.c	2007-10-30 16:49:34.000000000 +0100
@@ -2875,6 +2875,24 @@ cprop_jump (basic_block bb, rtx setcc, r
     }
   purge_dead_edges (bb);
 
+  /* If a conditional jump has been changed into unconditional jump, remove
+     the jump and make the edge fallthru - this is always called in
+     cfglayout mode.  */
+  if (new != pc_rtx && simplejump_p (jump))
+    {
+      edge e;
+      edge_iterator ei;
+
+      for (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); )
+	if (e->dest != EXIT_BLOCK_PTR
+	    && BB_HEAD (e->dest) == JUMP_LABEL (jump))
+	  {
+	    e->flags |= EDGE_FALLTHRU;
+	    break;
+	  }
+      delete_insn (jump);
+    }
+
   return 1;
 }
 
--- gcc/testsuite/gcc.dg/pr33673.c.jj	2007-10-30 16:51:05.000000000 +0100
+++ gcc/testsuite/gcc.dg/pr33673.c	2007-10-30 16:50:50.000000000 +0100
@@ -0,0 +1,43 @@
+/* PR rtl-optimization/33673 */
+/* { dg-do compile } */
+/* { dg-options "-Os -fno-forward-propagate -fno-guess-branch-probability -fno-move-loop-invariants -fno-tree-dominator-opts -fno-tree-loop-optimize" } */
+
+extern int f1 (int);
+extern int f2 (int);
+
+extern int *a;
+
+static void
+find_reg (int n)
+{
+  int i, pass;
+  unsigned int used[2], used1[2];
+
+  int c = n ? f1 (a[1]) : f2 (a[1]);
+
+  for (i = 64, pass = 0; pass <= 1 && i >= 64; pass++)
+    {
+      if (pass == 1)
+	{
+	  unsigned int *scan_tp_ = used;
+	  unsigned int *scan_fp_ = used1;
+	  int j;
+	  for (j = 0; j < 2; j++)
+	    *scan_tp_++ = *scan_fp_++;
+	}
+      for (i = 0; i < 64; i++)
+	{
+	  int regno = i;
+	  if (n == 0)
+	    if (i == regno)
+	      break;
+	}
+    }
+}
+
+void
+global_alloc ()
+{
+  find_reg (0);
+  find_reg (1);
+}

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]