Segher Boessenkool <seg...@kernel.crashing.org> writes: > On Sat, Feb 08, 2020 at 10:17:42AM -0600, Segher Boessenkool wrote: >> And we do not know which of the register will be used for the return, in >> untyped_call (only untyped-return knows). But we can add clobbers of all >> registers that *might* be used for the return, we do know that here, see >> operands[2] of untyped_call. > > Clobbers in parallel to the call, I mean, not as separate insns later. > Thanks Segher, as discussed, we may refine the patch by adding a 'barrier' to avoid instructions mis-scheduled. This improvement patch maybe fine for practice.
Below is the updated patch: bootstrap and regtest pass on powerpc64le. Is this ok to submit to trunk? diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md index f3c8eb0..2fbe68f 100644 --- a/gcc/config/rs6000/rs6000.md +++ b/gcc/config/rs6000/rs6000.md @@ -10867,6 +10867,10 @@ 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); 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 <gcczi...@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; +} + > > Segher