https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118947
--- Comment #8 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Andrew Pinski <pins...@gcc.gnu.org>: https://gcc.gnu.org/g:7b4849ec79873fa6de98436deda47e19cbac32ef commit r16-23-g7b4849ec79873fa6de98436deda47e19cbac32ef Author: Andrew Pinski <quic_apin...@quicinc.com> Date: Mon Feb 24 12:33:32 2025 -0800 gimple-fold: Improve optimize_memcpy_to_memset by walking back until aliasing says the ref is a may clobber. [PR118947] The case here is we have: ``` char buf[32] = {}; void* ret = aaa(); __builtin_memcpy(ret, buf, 32); ``` And buf does not escape. But we don't prop the zeroing from buf to the memcpy statement because optimize_memcpy_to_memset only looks back one statement. This can be fixed to look back until we get an statement that may clobber the reference. If we get a phi node, then we don't do anything. Bootstrapped and tested on x86_64-linux-gnu. PR tree-optimization/118947 gcc/ChangeLog: * gimple-fold.cc (optimize_memcpy_to_memset): Walk back until we get a statement that may clobber the read. gcc/testsuite/ChangeLog: * gcc.dg/pr118947-1.c: New test. Signed-off-by: Andrew Pinski <quic_apin...@quicinc.com>