DCE __cxa_atexit calls where the function is pure/const [PR19661]mastertrunk
commitc9dd853680b12d9c9def5de61abde5d057c526ba
authorAndrew Pinski <quic_apinski@quicinc.com>
Fri, 15 Mar 2024 23:34:22 +0000 (15 16:34 -0700)
committerAndrew Pinski <quic_apinski@quicinc.com>
Tue, 7 May 2024 21:46:37 +0000 (7 14:46 -0700)
treec993383fcd4f682782358a30e145d7814db23eac
parente472527c7b45d23e8dfd0fb767a6e663b4bc136e
DCE __cxa_atexit calls where the function is pure/const [PR19661]

In C++ sometimes you have a deconstructor function which is "empty", like for an
example with unions or with arrays.  The front-end might not know it is empty either
so this should be done on during optimization.o
To implement it I added it to DCE where we mark if a statement is necessary or not.

Bootstrapped and tested on x86_64-linux-gnu with no regressions.

Changes since v1:
  * v2: Add support for __aeabi_atexit for arm-*eabi. Add extra comments.
        Add cxa_atexit-5.C testcase for -fPIC case.
  * v3: Fix testcases for the __aeabi_atexit (forgot to do in the v2).

PR tree-optimization/19661

gcc/ChangeLog:

* tree-ssa-dce.cc (is_cxa_atexit): New function.
(is_removable_cxa_atexit_call): New function.
(mark_stmt_if_obviously_necessary): Don't mark removable
cxa_at_exit calls.
(mark_all_reaching_defs_necessary_1): Likewise.
(propagate_necessity): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/tree-ssa/cxa_atexit-1.C: New test.
* g++.dg/tree-ssa/cxa_atexit-2.C: New test.
* g++.dg/tree-ssa/cxa_atexit-3.C: New test.
* g++.dg/tree-ssa/cxa_atexit-4.C: New test.
* g++.dg/tree-ssa/cxa_atexit-5.C: New test.
* g++.dg/tree-ssa/cxa_atexit-6.C: New test.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
gcc/testsuite/g++.dg/tree-ssa/cxa_atexit-1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/tree-ssa/cxa_atexit-2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/tree-ssa/cxa_atexit-3.C [new file with mode: 0644]
gcc/testsuite/g++.dg/tree-ssa/cxa_atexit-4.C [new file with mode: 0644]
gcc/testsuite/g++.dg/tree-ssa/cxa_atexit-5.C [new file with mode: 0644]
gcc/testsuite/g++.dg/tree-ssa/cxa_atexit-6.C [new file with mode: 0644]
gcc/tree-ssa-dce.cc