https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70825
ktkachov at gcc dot gnu.org changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |ktkachov at gcc dot gnu.org --- Comment #5 from ktkachov at gcc dot gnu.org --- I've looked at RTL dce a bit and the reason it doesn't remove the store is because the MEM rtx used in the atomic instruction pattern is volatile andalso has the alias set ALIAS_SET_MEMORY_BARRIER associated with it. When the dse pass sees either of those it inserts a "wild read" into its calculations indicating that a memory happened from potentially any location, thus the stack store is potentially not dead and can't be eliminated. I've confirmed this by hacking get_builtin_sync_mem from builtins.c (that creates that mem rtx) to not set MEM_VOLATILE and the alias set to not ALIAS_SET_MEMORY_BARRIER. With those changes I see the stack store being eliminated by dse. So the same information that's used to prevent the compiler from moving memory instructions across these atomic operations prevents it from eliminating the preceding stack store.