]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
rs6000: mark clobber for registers changed by untpyed_call
authorJiufu Guo <guojiufu@linux.ibm.com>
Mon, 17 Feb 2020 02:48:39 +0000 (10:48 +0800)
committerJiufu Guo <guojiufu@linux.ibm.com>
Wed, 26 Feb 2020 10:13:44 +0000 (18:13 +0800)
As PR93047 said, __builtin_apply/__builtin_return does not work well with
-frename-registers.  This is caused by return register(e.g. r3) is used to
rename another register, before return register is stored to stack.
This patch fix this issue by emitting clobber for those egisters which
maybe changed by untyped call.

gcc/
2020-02-26  Jiufu Guo  <guojiufu@linux.ibm.com>

PR target/93047
* config/rs6000/rs6000.md (untyped_call): Add emit_clobber.

gcc/testsuite
2020-02-26  Jiufu Guo  <guojiufu@linux.ibm.com>

PR target/93047
* gcc.dg/torture/stackalign/builtin-return-2.c: New test case.

gcc/ChangeLog
gcc/config/rs6000/rs6000.md
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/stackalign/builtin-return-2.c [new file with mode: 0644]

index cf37d814a66b2ae13e4a57486e2503842c408adc..fedf2aa77d534f018fa10d0898b97bfca9351ca9 100644 (file)
@@ -1,3 +1,8 @@
+2020-02-26  Jiufu Guo  <guojiufu@linux.ibm.com>
+
+       PR target/93047
+       * config/rs6000/rs6000.md (untyped_call): Add emit_clobber.
+
 2020-02-26  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/93820
index 32da805a32db0f4b1b01027eb735bfb534628b0e..a768f5dd511ebf28ecb908fa7fe7a9694cb3850a 100644 (file)
 
   emit_call_insn (gen_call (operands[0], const0_rtx, const0_rtx));
 
+  for (int i = 0; i < XVECLEN (operands[2], 0); i++)
+    emit_clobber (SET_SRC (XVECEXP (operands[2], 0, i)));
+  emit_insn (gen_blockage ());
+
   for (i = 0; i < XVECLEN (operands[2], 0); i++)
     {
       rtx set = XVECEXP (operands[2], 0, i);
index 100489e1201c8b3922736a9393418176fd712f75..31c7e4dc7a85ac442ee11977a4bd51efd0981249 100644 (file)
@@ -1,3 +1,8 @@
+2020-02-26  Jiufu Guo  <guojiufu@linux.ibm.com>
+
+       PR target/93047
+       * gcc.dg/torture/stackalign/builtin-return-2.c: New test case.
+
 2020-02-26  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/93820
diff --git a/gcc/testsuite/gcc.dg/torture/stackalign/builtin-return-2.c b/gcc/testsuite/gcc.dg/torture/stackalign/builtin-return-2.c
new file mode 100644 (file)
index 0000000..7719109
--- /dev/null
@@ -0,0 +1,40 @@
+/* PR target/93047 */
+/* Originator: Andrew Church <gcczilla@achurch.org> */
+/* { dg-do run } */
+/* { dg-additional-options "-O3 -frename-registers" } */
+/* { dg-require-effective-target untyped_assembly } */
+
+#ifdef __MMIX__
+/* No parameters on stack for bar.  */
+#define STACK_ARGUMENTS_SIZE 0
+#else
+#define STACK_ARGUMENTS_SIZE 64
+#endif
+
+extern void abort(void);
+
+int foo(int n)
+{
+  return n+1;
+}
+
+int bar(int n)
+{
+  __builtin_return(__builtin_apply((void (*)(void))foo, __builtin_apply_args(),
+                                  STACK_ARGUMENTS_SIZE));
+}
+
+int main(void)
+{
+  /* Allocate 64 bytes on the stack to make sure that __builtin_apply
+     can read at least 64 bytes above the return address.  */
+  char dummy[64];
+
+  __asm__ ("" : : "" (dummy));
+
+  if (bar(1) != 2)
+    abort();
+
+  return 0;
+}
+