]> git.ipfire.org Git - thirdparty/gcc.git/commit
i386: Guard noreturn no-callee-saved-registers optimization with -mnoreturn-no-callee...
authorJakub Jelinek <jakub@redhat.com>
Fri, 8 Mar 2024 08:18:19 +0000 (09:18 +0100)
committerJakub Jelinek <jakub@redhat.com>
Fri, 8 Mar 2024 08:29:30 +0000 (09:29 +0100)
commita307a26e8b392ba65edfdae15489556b7701db81
treee20f2f6fe8a7ffa2cf266fb8209fb5f9cf31c625
parenteed4e541711ab4ae7783f75dd132e2acca71fdb9
i386: Guard noreturn no-callee-saved-registers optimization with -mnoreturn-no-callee-saved-registers [PR38534]

The following patch hides the noreturn no_callee_saved_registers (except bp)
optimization with a not enabled by default option.
The reason is that most noreturn functions should be called just once in a
program (unless they are recursive or invoke longjmp or similar, for exceptions
we already punt), so it isn't that essential to save a few instructions in their
prologue, but more importantly because it interferes with debugging.
And unlike most other optimizations, doesn't actually make it harder to debug
the given function, which can be solved by recompiling the given function if
it is too hard to debug, but makes it harder to debug the callers of that
noreturn function.  Those can be from a different translation unit, different
binary or even different package, so if e.g. glibc abort needs to use all
of the callee saved registers (%rbx, %rbp, %r12, %r13, %r14, %r15), debugging
any programs which abort will be harder because any DWARF expressions which
use those registers will be optimized out, not just in the immediate caller,
but in other callers as well until some frame restores a particular register
from some stack slot.

2024-03-08  Jakub Jelinek  <jakub@redhat.com>

PR target/38534
* config/i386/i386.opt (mnoreturn-no-callee-saved-registers): New
option.
* config/i386/i386-options.cc (ix86_set_func_type): Don't use
TYPE_NO_CALLEE_SAVED_REGISTERS_EXCEPT_BP unless
ix86_noreturn_no_callee_saved_registers is enabled.
* doc/invoke.texi (-mnoreturn-no-callee-saved-registers): Document.

* gcc.target/i386/pr38534-1.c: Add -mnoreturn-no-callee-saved-registers
to dg-options.
* gcc.target/i386/pr38534-2.c: Likewise.
* gcc.target/i386/pr38534-3.c: Likewise.
* gcc.target/i386/pr38534-4.c: Likewise.
* gcc.target/i386/pr38534-5.c: Likewise.
* gcc.target/i386/pr38534-6.c: Likewise.
* gcc.target/i386/pr114097-1.c: Likewise.
* gcc.target/i386/stack-check-17.c: Likewise.
gcc/config/i386/i386-options.cc
gcc/config/i386/i386.opt
gcc/doc/invoke.texi
gcc/testsuite/gcc.target/i386/pr114097-1.c
gcc/testsuite/gcc.target/i386/pr38534-1.c
gcc/testsuite/gcc.target/i386/pr38534-2.c
gcc/testsuite/gcc.target/i386/pr38534-3.c
gcc/testsuite/gcc.target/i386/pr38534-4.c
gcc/testsuite/gcc.target/i386/pr38534-5.c
gcc/testsuite/gcc.target/i386/pr38534-6.c
gcc/testsuite/gcc.target/i386/stack-check-17.c