https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116823
--- Comment #9 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Andrew Pinski <[email protected]>: https://gcc.gnu.org/g:143bb738d4f17b10ab369436ea1daaa2da3cc1dc commit r17-304-g143bb738d4f17b10ab369436ea1daaa2da3cc1dc Author: Andrew Pinski <[email protected]> Date: Fri Mar 27 22:37:19 2026 -0700 phiprop: Allow for one store inbetween the load and the phi which is being used to insert [PR123120] So phiprop has one disadvantage is that if there is store between the phi with the addresses and the new load, phiprop will no do anything. This means for some C++ code where you have a min of a max (or the opposite), depending on the argument order of evaluation phiprop might do the transformation or it might not (see tree-ssa/phiprop-3.C for examples). So we need to allow skipping of one store inbetween the load and where the phi is located. Aggregates include a store when doing phiprop so we need to check if there are also loads between the original store/load and the store we are skipping. This can be added afterwards but I didn't see aggregate case happening enough to make a big dent. I added testcases (phiprop-{10,11}.c) to make sure cases where the load would make a different shows up though. changes since v1: * v2: rewrite can_handle_load to avoid duplicated skipping store code. PR tree-optimization/123120 PR tree-optimization/116823 gcc/ChangeLog: * tree-ssa-phiprop.cc (phiprop_insert_phi): Add other_vuse argument, use it instead of the vuse on the use_stmt. (can_handle_load): Add aggregate argument. Also return the vuse of the load/store when the insert is allowed. Skipping over one non-modifying store for !aggregate. (propagate_with_phi): Update call to can_handle_load and phiprop_insert_phi. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/phiprop-8.c: New test. * gcc.dg/tree-ssa/phiprop-9.c: New test. * gcc.dg/tree-ssa/phiprop-10.c: New test. * gcc.dg/tree-ssa/phiprop-11.c: New test. * gcc.dg/tree-ssa/phiprop-12.c: New test. * g++.dg/tree-ssa/phiprop-3.C: New test. Signed-off-by: Andrew Pinski <[email protected]>
