]> git.ipfire.org Git - thirdparty/gcc.git/commit
fab: rewrite optimize_stack_restore call check [PR122033]
authorAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Mon, 22 Sep 2025 22:26:00 +0000 (15:26 -0700)
committerAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Fri, 3 Oct 2025 14:28:00 +0000 (07:28 -0700)
commit4440e022d220c19358745a1ba7ccf6ae054ce347
treee8182c7f911f7cc2ea3be35079a6b92ef1131fa6
parent3eadb2d22a65bf146cd33566c89f6b3c27dc8d23
fab: rewrite optimize_stack_restore call check [PR122033]

The call check in optimize_stack_restore is not the same as
what is described in the comment before the function. It has never
been the same even. It has always allowed all nromal builtins but not
target builtins while the comment says no calls.

This rewrites it to allow the following.
* a restore right before a noreturn is fine to be removed as the noreturn
  function will do the restore (or exit the program).
* Internal functions are ok because they will turn into an instruction or 2
* Still specifically reject alloca and __scrub_leave
* simple or inexpensive builtins (including target builtins)

This will both reject some more locations but also accepts more locations due
to the internal and target and noreturn function calls checks.

Bootstrapped and tested on x86_64-linux-gnu.

Changes since v1:
* v2: Add comment about why restoring before calls is important.

PR tree-optimization/122033
gcc/ChangeLog:

* tree-ssa-ccp.cc (optimize_stack_restore): Rewrite the call check.
Update comment in the front to new rules on calls.
* tree.h (fndecl_builtin_alloc_p): New function.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/pr122033-1.c: New test.
* gcc.dg/tree-ssa/pr122033-2.c: New test.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
gcc/testsuite/gcc.dg/tree-ssa/pr122033-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/pr122033-2.c [new file with mode: 0644]
gcc/tree-ssa-ccp.cc
gcc/tree.h