https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120043
--- Comment #5 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Richard Biener <rgue...@gcc.gnu.org>: https://gcc.gnu.org/g:93586e5d51188bf71f4f8fae4ee94ff631740f24 commit r16-472-g93586e5d51188bf71f4f8fae4ee94ff631740f24 Author: Richard Biener <rguent...@suse.de> Date: Thu May 8 10:05:42 2025 +0200 tree-optimization/120043 - bogus conditional store elimination The following fixes conditional store elimination to properly check for conditional stores to readonly memory which we can obviously not store to unconditionally. The tree_could_trap_p predicate used is only considering rvalues and the chosen approach mimics that of loop store motion. PR tree-optimization/120043 * tree-ssa-phiopt.cc (cond_store_replacement): Check whether the store is to readonly memory. * gcc.dg/torture/pr120043.c: New testcase.