]> git.ipfire.org Git - thirdparty/gcc.git/commit
tree-optimization/106922 - missed FRE/PRE
authorRichard Biener <rguenther@suse.de>
Wed, 21 Sep 2022 11:52:56 +0000 (13:52 +0200)
committerRichard Biener <rguenther@suse.de>
Mon, 17 Oct 2022 12:26:41 +0000 (14:26 +0200)
commite8d5f3a1b5a5839cb1db57d6f6766469cc4f8747
treef00c08d3a657652804da91119431b5d7ceb32727
parente5816c1c2390a7ed1a34526d7a3af02fdad00553
tree-optimization/106922 - missed FRE/PRE

The following enhances the store-with-same-value trick in
vn_reference_lookup_3 by not only looking for

  a = val;
  *ptr = val;
  .. = a;

but also

  *ptr = val;
  other = x;
  .. = a;

where the earlier store is more than one hop away.  It does this
by queueing the actual value to compare until after the walk but
as disadvantage only allows a single such skipped store from a
constant value.

Unfortunately we cannot handle defs from non-constants this way
since we're prone to pick up values from the past loop iteration
this way and we have no good way to identify values that are
invariant in the currently iterated cycle.  That's why we keep
the single-hop lookup for those cases.  gcc.dg/tree-ssa/pr87126.c
would be a testcase that's un-XFAILed when we'd handle those
as well.

PR tree-optimization/106922
* tree-ssa-sccvn.cc (vn_walk_cb_data::same_val): New member.
(vn_walk_cb_data::finish): Perform delayed verification of
a skipped may-alias.
(vn_reference_lookup_pieces): Likewise.
(vn_reference_lookup): Likewise.
(vn_reference_lookup_3): When skipping stores of the same
value also handle constant stores that are more than a
single VDEF away by delaying the verification.

* gcc.dg/tree-ssa/ssa-fre-100.c: New testcase.
* g++.dg/tree-ssa/pr106922.C: Adjust.

(cherry picked from commit 9baee6181b4e427e0b5ba417e51424c15858dce7)
gcc/testsuite/g++.dg/tree-ssa/pr106922.C
gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-100.c [new file with mode: 0644]
gcc/tree-ssa-sccvn.cc