public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH, rs6000]: mark clobber for registers changed by untpyed_call
@ 2020-02-05 13:53 Jiufu Guo
  2020-02-05 19:25 ` Segher Boessenkool
  0 siblings, 1 reply; 9+ messages in thread
From: Jiufu Guo @ 2020-02-05 13:53 UTC (permalink / raw)
  To: gcc-patches; +Cc: guojiufu, wschmidt, segher

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.

Because this would be a kind of wrong code, so I'm thinking to submit to
gcc10.

Bootstrap and regtest on powerpc64le are pass.  Is this okay for trunk?

Thanks,
Jiufu

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

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

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

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

diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
index f3c8eb0..d68bc24 100644
--- a/gcc/config/rs6000/rs6000.md
+++ b/gcc/config/rs6000/rs6000.md
@@ -10867,6 +10867,9 @@
 
   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)));
+
   for (i = 0; i < XVECLEN (operands[2], 0); i++)
     {
       rtx set = XVECEXP (operands[2], 0, i);
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
index 0000000..7719109
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/stackalign/builtin-return-2.c
@@ -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;
+}
+

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-02-14 18:12 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-05 13:53 [PATCH, rs6000]: mark clobber for registers changed by untpyed_call Jiufu Guo
2020-02-05 19:25 ` Segher Boessenkool
2020-02-06  2:49   ` Jiufu Guo
2020-02-06 15:35     ` Segher Boessenkool
2020-02-07  7:10       ` Jiufu Guo
2020-02-08 16:17         ` Segher Boessenkool
2020-02-08 21:45           ` Segher Boessenkool
2020-02-14  6:58             ` Jiufu Guo
2020-02-14 18:12               ` Segher Boessenkool

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).