]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR target/40718 (Invalid code produced with -foptimize-sibling-calls)
authorUros Bizjak <ubizjak@gmail.com>
Sun, 23 Aug 2009 13:03:39 +0000 (15:03 +0200)
committerUros Bizjak <uros@gcc.gnu.org>
Sun, 23 Aug 2009 13:03:39 +0000 (15:03 +0200)
PR target/40718
* config/i386/i386.c (*call_pop_1): Disable for sibling calls.
(*call_value_pop_1): Ditto.
(*sibcall_pop_1): New insn pattern.
(*sibcall_value_pop_1): Ditto.

testsuite/ChangeLog:

PR target/40718
* gcc.target/i386/pr40718.c: New test.

From-SVN: r151033

gcc/ChangeLog
gcc/config/i386/i386.md
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/i386/pr40718.c [new file with mode: 0644]

index eb8c7d0179211b0857b490b589747b0128a9eef9..ee1b3f6a5923322d1dcaed935a78bdabddc67104 100644 (file)
@@ -1,3 +1,11 @@
+2009-08-23  Uros Bizjak  <ubizjak@gmail.com>
+
+       PR target/40718
+       * config/i386/i386.c (*call_pop_1): Disable for sibling calls.
+       (*call_value_pop_1): Ditto.
+       (*sibcall_pop_1): New insn pattern.
+       (*sibcall_value_pop_1): Ditto.
+
 2009-08-16  Uros Bizjak  <ubizjak@gmail.com>
 
        Backport from mainline:
index 1053d47e4b5312334cddf26534cf17eed3db906e..2c6b3a3d3c5ae1a336aec37f51cbe1721891bbd4 100644 (file)
         (match_operand:SI 1 "" ""))
    (set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG)
                            (match_operand:SI 2 "immediate_operand" "i")))]
-  "!TARGET_64BIT"
+  "!SIBLING_CALL_P (insn) && !TARGET_64BIT"
 {
   if (constant_call_address_operand (operands[0], Pmode))
-    {
-      if (SIBLING_CALL_P (insn))
-       return "jmp\t%P0";
-      else
-       return "call\t%P0";
-    }
-  if (SIBLING_CALL_P (insn))
-    return "jmp\t%A0";
-  else
-    return "call\t%A0";
+    return "call\t%P0";
+  return "call\t%A0";
+}
+  [(set_attr "type" "call")])
+
+(define_insn "*sibcall_pop_1"
+  [(call (mem:QI (match_operand:SI 0 "sibcall_insn_operand" "s,c,d,a"))
+        (match_operand:SI 1 "" ""))
+   (set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG)
+                           (match_operand:SI 2 "immediate_operand" "i,i,i,i")))]
+  "SIBLING_CALL_P (insn) && !TARGET_64BIT"
+{
+  if (constant_call_address_operand (operands[0], Pmode))
+    return "jmp\t%P0";
+  return "jmp\t%A0";
 }
   [(set_attr "type" "call")])
 
              (match_operand:SI 2 "" "")))
    (set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG)
                            (match_operand:SI 3 "immediate_operand" "i")))]
-  "!TARGET_64BIT"
+  "!SIBLING_CALL_P (insn) && !TARGET_64BIT"
 {
   if (constant_call_address_operand (operands[1], Pmode))
-    {
-      if (SIBLING_CALL_P (insn))
-       return "jmp\t%P1";
-      else
-       return "call\t%P1";
-    }
-  if (SIBLING_CALL_P (insn))
-    return "jmp\t%A1";
-  else
-    return "call\t%A1";
+    return "call\t%P1";
+  return "call\t%A1";
+}
+  [(set_attr "type" "callv")])
+
+(define_insn "*sibcall_value_pop_1"
+  [(set (match_operand 0 "" "")
+       (call (mem:QI (match_operand:SI 1 "sibcall_insn_operand" "s,c,d,a"))
+             (match_operand:SI 2 "" "")))
+   (set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG)
+                           (match_operand:SI 3 "immediate_operand" "i,i,i,i")))]
+  "SIBLING_CALL_P (insn) && !TARGET_64BIT"
+{
+  if (constant_call_address_operand (operands[1], Pmode))
+    return "jmp\t%P1";
+  return "jmp\t%A1";
 }
   [(set_attr "type" "callv")])
 
index f5dc05aa58ac0a848f2a87bb7989411509d4833c..991ca592c551c6b283945f27ab7f68db9acd447e 100644 (file)
@@ -1,3 +1,8 @@
+2009-08-23  Uros Bizjak  <ubizjak@gmail.com>
+
+       PR target/40718
+       * gcc.target/i386/pr40718.c: New test.
+
 2009-08-16  Uros Bizjak  <ubizjak@gmail.com>
 
        Backport from mainline:
diff --git a/gcc/testsuite/gcc.target/i386/pr40718.c b/gcc/testsuite/gcc.target/i386/pr40718.c
new file mode 100644 (file)
index 0000000..f6029ed
--- /dev/null
@@ -0,0 +1,36 @@
+/* { dg-do run } */
+/* { dg-require-effective-target ilp32 } */
+/* { dg-options "-O1 -foptimize-sibling-calls" } */
+
+void abort (void);
+
+struct S
+{
+  void (__attribute__((__stdcall__)) *f) (struct S *);
+  int i;
+};
+
+void __attribute__((__stdcall__))
+foo (struct S *s)
+{
+  s->i++;
+}
+
+void __attribute__((__stdcall__))
+bar (struct S *s)
+{
+  foo(s);
+  s->f(s);
+}
+
+int main (void)
+{
+  struct S s = { foo, 0 };
+
+  bar (&s);
+  if (s.i != 2)
+    abort ();
+
+  return 0;
+}
+