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>