]> git.ipfire.org Git - thirdparty/gcc.git/commit
s390: Allow 5+ argument tail-calls in some special cases [PR119873]
authorJakub Jelinek <jakub@redhat.com>
Thu, 24 Apr 2025 21:44:28 +0000 (23:44 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 24 Apr 2025 21:44:51 +0000 (23:44 +0200)
commit567684733e0c4f28158e19b72f4e7f660ad81561
treec89b227ac9b2a2f15d99d5b20659494526f31c17
parenta4e8d1884e0e9ed43add45d71278e618a729ff88
s390: Allow 5+ argument tail-calls in some special cases [PR119873]

protobuf (and therefore firefox too) currently doesn't build on s390*-linux.
The problem is that it uses [[clang::musttail]] attribute heavily, and in
llvm (IMHO llvm bug) [[clang::musttail]] calls with 5+ arguments on
s390*-linux are silently accepted and result in a normal non-tail call.
In GCC we just reject those because the target hook refuses to tail call it
(IMHO the right behavior).
Now, the reason why that happens is as s390_function_ok_for_sibcall attempts
to explain, the 5th argument (assuming normal <= wordsize integer or pointer
arguments, nothing that needs 2+ registers) is passed in %r6 which is not
call clobbered, so we can't do tail call when we'd have to change content
of that register and then caller would assume %r6 content didn't change and
use it again.
In the protobuf case though, the 5th argument is always passed through
from the caller to the musttail callee unmodified, so one can actually
emit just jg tail_called_function or perhaps tweak some registers but
keep %r6 untouched, and in that case I think it is just fine to tail call
it (at least unless the stack slots used for 6+ argument can't be modified
by the callee in the ABI and nothing checks for that).

So, the following patch checks for this special case, where the argument
which uses %r6 is passed in a single register and it is passed default
definition of SSA_NAME of a PARM_DECL with the same DECL_INCOMING_RTL.

It won't really work at -O0 but should work for -O1 and above, at least when
one doesn't really try to modify the parameter conditionally and hope it will
be optimized away in the end.

2025-04-24  Jakub Jelinek  <jakub@redhat.com>
    Stefan Schulze Frielinghaus  <stefansf@gcc.gnu.org>

PR target/119873
* config/s390/s390.cc (s390_call_saved_register_used): Don't return
true if default definition of PARM_DECL SSA_NAME of the same register
is passed in call saved register.
(s390_function_ok_for_sibcall): Adjust comment.

* gcc.target/s390/pr119873-1.c: New test.
* gcc.target/s390/pr119873-2.c: New test.
* gcc.target/s390/pr119873-3.c: New test.
* gcc.target/s390/pr119873-4.c: New test.
gcc/config/s390/s390.cc
gcc/testsuite/gcc.target/s390/pr119873-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/s390/pr119873-2.c [new file with mode: 0644]
gcc/testsuite/gcc.target/s390/pr119873-3.c [new file with mode: 0644]
gcc/testsuite/gcc.target/s390/pr119873-4.c [new file with mode: 0644]