]> git.ipfire.org Git - thirdparty/gcc.git/commit
phiprop: Allow for one store inbetween the load and the phi which is being used to...
authorAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Sat, 28 Mar 2026 05:37:19 +0000 (22:37 -0700)
committerAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Mon, 4 May 2026 13:48:59 +0000 (06:48 -0700)
commit143bb738d4f17b10ab369436ea1daaa2da3cc1dc
tree6534f25cf6319325572dd8ff7cc0966d5fb4026f
parent40f567d9cabc5170ed396025d516b93838f4f141
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 <andrew.pinski@oss.qualcomm.com>
gcc/testsuite/g++.dg/tree-ssa/phiprop-3.C [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/phiprop-10.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/phiprop-11.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/phiprop-12.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/phiprop-8.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/phiprop-9.c [new file with mode: 0644]
gcc/tree-ssa-phiprop.cc