]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR rtl-optimization/33848 (reference to non-existent label at -O1 on mips/mipsel)
authorRichard Sandiford <rsandifo@nildram.co.uk>
Thu, 22 Nov 2007 09:27:55 +0000 (09:27 +0000)
committerRichard Sandiford <rsandifo@gcc.gnu.org>
Thu, 22 Nov 2007 09:27:55 +0000 (09:27 +0000)
gcc/
PR rtl-optimization/33848
* reload.c (subst_reloads): When replacing a LABEL_REF with a
register, only add a REG_LABEL note if the label is the target
of the jump.

gcc/testsuite/
PR rtl-optimization/33848
* gcc.dg/torture/pr33848.c: New test.

From-SVN: r130344

gcc/ChangeLog
gcc/reload.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr33848.c [new file with mode: 0644]

index 17e62103e6da37581c2dd12ad95e63a8b3180aac..63f136354f02d2623c8f725453c86de7d372c7ae 100644 (file)
@@ -1,3 +1,10 @@
+2007-11-22  Richard Sandiford  <rsandifo@nildram.co.uk>
+
+       PR rtl-optimization/33848
+       * reload.c (subst_reloads): When replacing a LABEL_REF with a
+       register, only add a REG_LABEL note if the label is the target
+       of the jump.
+
 2007-11-16  Richard Guenther  <rguenther@suse.de>
 
        PR middle-end/34030
index 501fe849d4b9a096fbeb67c3341dcceb92e0f840..5fb0f09e0f95679aaf8b34407a7778e13b28e4c8 100644 (file)
@@ -6158,17 +6158,16 @@ subst_reloads (rtx insn)
            }
 #endif /* ENABLE_CHECKING */
 
-         /* If we're replacing a LABEL_REF with a register, add a
-            REG_LABEL note to indicate to flow which label this
+         /* If we're replacing a LABEL_REF jump target with a register,
+            add a REG_LABEL note to indicate to flow which label this
             register refers to.  */
          if (GET_CODE (*r->where) == LABEL_REF
-             && JUMP_P (insn))
-           {
-             REG_NOTES (insn) = gen_rtx_INSN_LIST (REG_LABEL,
-                                                   XEXP (*r->where, 0),
-                                                   REG_NOTES (insn));
-             JUMP_LABEL (insn) = XEXP (*r->where, 0);
-          }
+             && JUMP_P (insn)
+             && JUMP_LABEL (insn) == XEXP (*r->where, 0)
+             && !find_reg_note (insn, REG_LABEL, XEXP (*r->where, 0)))
+           REG_NOTES (insn) = gen_rtx_INSN_LIST (REG_LABEL,
+                                                 XEXP (*r->where, 0),
+                                                 REG_NOTES (insn));
 
          /* Encapsulate RELOADREG so its machine mode matches what
             used to be there.  Note that gen_lowpart_common will
index 71a148318fb21c77959bc10183c91b9bbd57af0d..1aef4f96bd53ee06f43de0aa2e96a39798f74ef4 100644 (file)
@@ -1,3 +1,8 @@
+2007-11-22  Richard Sandiford  <rsandifo@nildram.co.uk>
+
+       PR rtl-optimization/33848
+       * gcc.dg/torture/pr33848.c: New test.
+
 2007-11-16  Richard Guenther  <rguenther@suse.de>
 
        PR middle-end/34030
diff --git a/gcc/testsuite/gcc.dg/torture/pr33848.c b/gcc/testsuite/gcc.dg/torture/pr33848.c
new file mode 100644 (file)
index 0000000..c3b85e9
--- /dev/null
@@ -0,0 +1,43 @@
+/* &&foo should be hoisted, but on most targets, excess register pressure
+   forces it to be rematerialized before "data != &&foo".  On targets that
+   have a "branch if registers are equal" instruction, this leads to the
+   branch having two LABEL_REFs: one for the branch target and one for
+   &&foo.  When reloading &&foo into a register, reload would wrongly
+   say that &&foo was the target of the branch, and the real target would
+   then be removed as dead.  */
+/* { dg-do link } */
+#define NVARS 30
+#define MULTI(X) \
+  X( 0), X( 1), X( 2), X( 3), X( 4), X( 5), X( 6), X( 7), X( 8), X( 9), \
+  X(10), X(11), X(12), X(13), X(14), X(15), X(16), X(17), X(18), X(19), \
+  X(20), X(21), X(22), X(23), X(24), X(25), X(26), X(27), X(28), X(29)
+
+#define DECLARE(INDEX) i##INDEX = gv[INDEX]
+#define COPY(INDEX) gv[INDEX] = i##INDEX
+
+volatile int gv[NVARS];
+void *volatile data;
+
+int
+main (void)
+{
+  __label__ foo;
+
+  if (gv[0] == 1)
+    goto foo;
+  data = &&foo;
+  do
+    {
+      int MULTI (DECLARE);
+      MULTI (COPY);
+      MULTI (COPY);
+      MULTI (COPY);
+      if (data != &&foo)
+       gv[0] = 1;
+      else
+       gv[1] = 2;
+    }
+  while (gv[0] > 0);
+ foo:
+  return 0;
+}