On 4/17/25 11:50 AM, Andrew Pinski wrote:
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.
OK jeff