OSDN Git Service

Backported from mainline
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 1 Feb 2013 13:57:46 +0000 (13:57 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 1 Feb 2013 13:57:46 +0000 (13:57 +0000)
2012-11-13  Jakub Jelinek  <jakub@redhat.com>

PR rtl-optimization/54127
* cfgrtl.c (force_nonfallthru_and_redirect): When redirecting
asm goto labels from BB_HEAD (e->dest) to target bb, decrement
LABEL_NUSES of BB_HEAD (e->dest) and increment LABEL_NUSES of
BB_HEAD (target) appropriately and adjust JUMP_LABEL and/or
REG_LABEL_TARGET and REG_LABEL_OPERAND.

* gcc.dg/torture/pr54127.c: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_7-branch@195648 138bc75d-0d04-0410-961f-82ee72b054a4

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

index eba6dfb..7f8c87e 100644 (file)
@@ -1,3 +1,15 @@
+2013-02-01  Jakub Jelinek  <jakub@redhat.com>
+
+       Backported from mainline
+       2012-11-13  Jakub Jelinek  <jakub@redhat.com>
+
+       PR rtl-optimization/54127
+       * cfgrtl.c (force_nonfallthru_and_redirect): When redirecting
+       asm goto labels from BB_HEAD (e->dest) to target bb, decrement
+       LABEL_NUSES of BB_HEAD (e->dest) and increment LABEL_NUSES of
+       BB_HEAD (target) appropriately and adjust JUMP_LABEL and/or
+       REG_LABEL_TARGET and REG_LABEL_OPERAND.
+
 2013-02-01  Eric Botcazou  <ebotcazou@adacore.com>
 
        * fold-const.c (make_range_step) <TRUTH_NOT_EXPR>: Bail out if the
index 65a4ffc..5af13dd 100644 (file)
@@ -1231,14 +1231,46 @@ force_nonfallthru_and_redirect (edge e, basic_block target, rtx jump_label)
       && (note = extract_asm_operands (PATTERN (BB_END (e->src)))))
     {
       int i, n = ASM_OPERANDS_LABEL_LENGTH (note);
+      bool adjust_jump_target = false;
 
       for (i = 0; i < n; ++i)
        {
          if (XEXP (ASM_OPERANDS_LABEL (note, i), 0) == BB_HEAD (e->dest))
-           XEXP (ASM_OPERANDS_LABEL (note, i), 0) = block_label (target);
+           {
+             LABEL_NUSES (XEXP (ASM_OPERANDS_LABEL (note, i), 0))--;
+             XEXP (ASM_OPERANDS_LABEL (note, i), 0) = block_label (target);
+             LABEL_NUSES (XEXP (ASM_OPERANDS_LABEL (note, i), 0))++;
+             adjust_jump_target = true;
+           }
          if (XEXP (ASM_OPERANDS_LABEL (note, i), 0) == BB_HEAD (target))
            asm_goto_edge = true;
        }
+      if (adjust_jump_target)
+       {
+         rtx insn = BB_END (e->src), note;
+         rtx old_label = BB_HEAD (e->dest);
+         rtx new_label = BB_HEAD (target);
+
+         if (JUMP_LABEL (insn) == old_label)
+           {
+             JUMP_LABEL (insn) = new_label;
+             note = find_reg_note (insn, REG_LABEL_TARGET, new_label);
+             if (note)
+               remove_note (insn, note);
+           }
+         else
+           {
+             note = find_reg_note (insn, REG_LABEL_TARGET, old_label);
+             if (note)
+               remove_note (insn, note);
+             if (JUMP_LABEL (insn) != new_label
+                 && !find_reg_note (insn, REG_LABEL_TARGET, new_label))
+               add_reg_note (insn, REG_LABEL_TARGET, new_label);
+           }
+         while ((note = find_reg_note (insn, REG_LABEL_OPERAND, old_label))
+                != NULL_RTX)
+           XEXP (note, 0) = new_label;
+       }
     }
 
   if (EDGE_COUNT (e->src->succs) >= 2 || abnormal_edge_flags || asm_goto_edge)
index baf30d7..6321a75 100644 (file)
@@ -1,3 +1,11 @@
+2013-02-01  Jakub Jelinek  <jakub@redhat.com>
+
+       Backported from mainline
+       2012-11-13  Jakub Jelinek  <jakub@redhat.com>
+
+       PR rtl-optimization/54127
+       * gcc.dg/torture/pr54127.c: New test.
+
 2013-02-01  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gnat.dg/opt26.adb: New test.
diff --git a/gcc/testsuite/gcc.dg/torture/pr54127.c b/gcc/testsuite/gcc.dg/torture/pr54127.c
new file mode 100644 (file)
index 0000000..4f64998
--- /dev/null
@@ -0,0 +1,16 @@
+/* PR rtl-optimization/54127 */
+/* { dg-do compile } */
+
+extern void foo (void) __attribute__ ((__noreturn__));
+
+void
+bar (int x)
+{
+  if (x < 0)
+    foo ();
+  if (x == 0)
+    return;
+  __asm goto ("# %l[lab] %l[lab2]" : : : : lab, lab2);
+lab:;
+lab2:;
+}