diff mbox

[RFA,rtl-optimization/52714] Do not allow combine to create invalid RTL

Message ID 530F9262.20408@redhat.com
State New
Headers show

Commit Message

Jeff Law Feb. 27, 2014, 7:30 p.m. UTC
On 02/17/14 02:28, Eric Botcazou wrote:
>
> Although it's probably time to concede defeat in this particular case, I don't
> think we should use the NONJUMP_INSN_P big hammer because we want to eliminate
> branches if possible.  So I'd just add the minimal test to the two existing
> conditions so as to prevent the invalid RTL from being created, e.g.
>
>    && (!JUMP_P (i3) || SET_DEST (set[01]) == pc_rtx)
Done.  Attached is the final iteration that got installed.


Verified with a cross compiler.  Bootstrap on m68k will start at some 
point and finish in the next week or so.

jeff
diff mbox

Patch

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index a20cee3..16c499b 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@ 
+2014-02-27  Jeff Law  <law@redhat.com>
+
+	PR rtl-optimization/52714
+	* combine.c (try_combine): When splitting an unrecognized PARALLEL
+	into two independent simple sets, if I3 is a jump, ensure the
+	pattern we place into I3 is a (set (pc) ...)
+
 2014-02-27  Mikael Pettersson  <mikpe@it.uu.se>
 	    Jeff Law  <law@redhat.com>
 
diff --git a/gcc/combine.c b/gcc/combine.c
index 1b598b4..fc473b6 100644
--- a/gcc/combine.c
+++ b/gcc/combine.c
@@ -3712,6 +3712,9 @@  try_combine (rtx i3, rtx i2, rtx i1, rtx i0, int *new_direct_jump_p,
 #ifdef HAVE_cc0
 	  && !reg_referenced_p (cc0_rtx, set0)
 #endif
+	  /* If I3 is a jump, ensure that set0 is a jump so that
+	     we do not create invalid RTL.  */
+	  && (!JUMP_P (i3) || SET_DEST (set0) == pc_rtx)
 	 )
 	{
 	  newi2pat = set1;
@@ -3726,6 +3729,9 @@  try_combine (rtx i3, rtx i2, rtx i1, rtx i0, int *new_direct_jump_p,
 #ifdef HAVE_cc0
 	       && !reg_referenced_p (cc0_rtx, set1)
 #endif
+	       /* If I3 is a jump, ensure that set1 is a jump so that
+		  we do not create invalid RTL.  */
+	       && (!JUMP_P (i3) || SET_DEST (set1) == pc_rtx)
 	      )
 	{
 	  newi2pat = set0;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index be4cb12..b95bcfd 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@ 
+2014-02-27  Jeff Law  <law@redhat.com>
+
+	PR rtl-optimization/52714
+	* gcc.c-torture/compile/pr52714.c: New test.
+
 2014-02-27  Mikael Pettersson  <mikpe@it.uu.se>
             Jeff Law  <law@redhat.com>
 
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr52714.c b/gcc/testsuite/gcc.c-torture/compile/pr52714.c
new file mode 100644
index 0000000..03d4990
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr52714.c
@@ -0,0 +1,25 @@ 
+
+int __re_compile_fastmap(unsigned char *p)
+{
+    unsigned char **stack;
+    unsigned size;
+    unsigned avail;
+
+    stack = __builtin_alloca(5 * sizeof(unsigned char*));
+    if (stack == 0)
+	return -2;
+    size = 5;
+    avail = 0;
+
+    for (;;) {
+	switch (*p++) {
+	case 0:
+	    if (avail == size)
+		return -2;
+	    stack[avail++] = p;
+	}
+    }
+
+    return 0;
+}
+