[Bug middle-end/83022] malloc & memset -> calloc is not always an optimization

glisse at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Nov 16 21:24:00 GMT 2017


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83022

--- Comment #1 from Marc Glisse <glisse at gcc dot gnu.org> ---
I am pretty sure this was discussed when the patch was reviewed. IIRC the
original patch was specifically pattern-matching if(p!=0) (with p the result of
malloc) as the only acceptable condition between malloc and memset for this
transformation, but the move to the strlen pass made that inconvenient and it
was decided that always doing the transformation was ok (I hope I am not
rewriting history). If there is a way to check the probability of reaching the
call to memset from the call to malloc (preferably conditional to the fact that
malloc returned something != 0), that could be checked before generating
calloc, but that may not be easy... (compare the local count of the 2 BBs?
That's 10000 and 3300 here, but I see you have already filed PR 83023 to
improve it)

Did you actually hit a measurable slowdown in a real application?


More information about the Gcc-bugs mailing list