]> git.ipfire.org Git - thirdparty/gcc.git/commit
tree-optimization/87615 - VN predication is expensive
authorRichard Biener <rguenther@suse.de>
Thu, 18 Sep 2025 08:41:45 +0000 (10:41 +0200)
committerRichard Biener <rguenth@gcc.gnu.org>
Thu, 18 Sep 2025 11:09:33 +0000 (13:09 +0200)
commitd5e80bf7571836bb307f38e45f0e6ba392cdcc3d
tree1b34b083890475641d37f8c88ae9b885f813255e
parent97c1d2fa97afc59b02d2894b88069136145603e2
tree-optimization/87615 - VN predication is expensive

The following restricts the number of locations we register a predicate
as valid which avoids the expensive linear search for cases like

   if (a)
     A;
   if (a)
     B;
   if (a)
     C;
   ...

where we register a != 0 as true for locations A, B, C ... in an
unlimited way.  The patch simply choses 8 as limit.  The underlying
issue for this case is the data structure which does not allow for
easy "forgetting" or more optimal searching when locations become
no longer relevant (the whole point of the location list is to
represent where predicates are relevant).

The patch also splits the search/copy loop into two to avoid copying
stuff that we'll not need when finding an existing better entry or,
new now, when we figure we run over the limit.

PR tree-optimization/87615
* tree-ssa-sccvn.cc (vn_nary_op_insert_into): When inserting
a new predicate or location into an existing predicate list
make sure to not exceed 8 locations.  Avoid copying things
when we later eventually throw them away.
(vn_nary_op_insert_pieces_predicated): Avoid expensive check
when not checking.
(dominated_by_p_w_unex): Apply the limit on a single successors
predecessor count consistently.
gcc/tree-ssa-sccvn.cc