On Wed, Jun 28, 2023 at 10:21:45AM +0000, Richard Biener via Gcc-patches wrote: > When NRV replaces a local variable with <retval> it also replaces > occurences in clobbers. This leads to <retval> being clobbered > before the return of it which is strictly invalid but harmless in > practice since there's no pass after NRV which would remove > earlier stores. > > The following fixes this nevertheless. > > Bootstrapped and tested on x86_64-unknown-linux-gnu, OK? > > Thanks, > Richard. > > PR tree-optimization/110434 > * tree-nrv.cc (pass_nrv::execute): Remove CLOBBERs of > VAR we replace with <retval>.
This is in a loop over all basic blocks in a function. Do we want to kill all clobbers, or just the ones at the end of functions (i.e. after the <result> = VAR; assignment that we also remove)? Complication is that doesn't necessarily have to be just the rest of a single basic block, but all basic blocks from that point until end of function. I mean, if we have var = whatever; use (var); var = {CLOBBER}; ... var = whatever_else; <result> = var; var = {CLOBBER}; killing the first clobber might result in missed optimizations later on. On the other side, could there be partial clobbers for the var -> <result>, var.fld = {CLOBBER}; ? Or even worse, indirect clobbers (MEM_REF with SSA_NAME pointing to var or parts of it)? Jakub