diff options
author | Andrew Pinski <quic_apinski@quicinc.com> | 2025-04-19 09:14:54 -0700 |
---|---|---|
committer | Andrew Pinski <andrew.pinski@oss.qualcomm.com> | 2025-09-07 23:56:59 -0700 |
commit | ed264541c353866cedf46ad873f2e2c46cf62839 (patch) | |
tree | c79a5905bd3062337f019e9fc4fc906eb6d2328d /libgcc | |
parent | d8c407a7c842a449f8bdb3bffd7e667833427ea4 (diff) | |
download | gcc-ed264541c353866cedf46ad873f2e2c46cf62839.zip gcc-ed264541c353866cedf46ad873f2e2c46cf62839.tar.gz gcc-ed264541c353866cedf46ad873f2e2c46cf62839.tar.bz2 |
strlen: Handle empty constructor as memset for combining with malloc to calloc [PR87900]
This was noticed when turning memset (with constant size) into a store of an empty constructor
but can be reproduced without that.
In this case we have the following IR:
```
p_3 = __builtin_malloc (4096);
*p_3 = {};
```
Which we can treat the store as a memset.
So this patch adds the similar optimization as memset/malloc now for malloc/constructor.
This patch is on top of https://gcc.gnu.org/pipermail/gcc-patches/2025-April/681439.html
(it calls allow_memset_malloc_to_calloc but that can be removed if that patch is rejected).
Changes since v1:
* v2: Correctly return false from handle_assign after removing stmt.
Bootstrapped and tested on x86_64-linux-gnu.
PR tree-optimization/87900
gcc/ChangeLog:
* tree-ssa-strlen.cc (strlen_pass::handle_assign): Add RHS argument.
For empty constructor RHS, see if can combine with a previous malloc into
a calloc.
(strlen_pass::check_and_optimize_call): Update call to handle_assign;
passing NULL_TREE for RHS.
(strlen_pass::check_and_optimize_stmt): Update call to handle_assign.
gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/calloc-10.c: New test.
* gcc.dg/tree-ssa/calloc-11.c: New test.
* gcc.dg/tree-ssa/calloc-12.c: New test.
Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
Diffstat (limited to 'libgcc')
0 files changed, 0 insertions, 0 deletions