[Bug tree-optimization/82732] malloc+zeroing other than memset not optimized to calloc, so asm output is malloc+memset
pinskia at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Jan 13 21:18:46 GMT 2025
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82732
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
Last reconfirmed| |2025-01-13
--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
So VRP can do convert it to:
<bb 2> [local count: 118111600]:
_1 = (long unsigned int) size_8(D);
_2 = _1 * 4;
p_11 = malloc (_2);
if (size_8(D) != 0)
goto <bb 3>; [89.00%]
else
goto <bb 4>; [11.00%]
<bb 3> [local count: 105119324]:
_19 = size_8(D) + 4294967295;
_15 = (sizetype) _19;
_14 = (sizetype) size_8(D);
_7 = _14 * 4;
__builtin_memset (p_11, 0, _7);
BUT VRP2 is after strlen1 which does the conversion of malloc/memset -> calloc.
I have not looked into why FRE5 could see the redundant _7 being the same as _2
though (note VRP2 also runs after FRE5).
VRP2 can do it because of
Applying pattern match.pd:5271, gimple-match-7.cc:6107
Applying pattern match.pd:237, gimple-match-6.cc:10371
Applying pattern match.pd:4000, gimple-match-8.cc:1587
Applying pattern match.pd:4098, gimple-match-6.cc:16572
gimple_simplified to _15 = (sizetype) size_8(D);
Folded into: _15 = (sizetype) size_8(D);
More information about the Gcc-bugs
mailing list