]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
middle-end/38474 - speedup PTA constraint solving
authorRichard Biener <rguenther@suse.de>
Thu, 29 Apr 2021 06:32:00 +0000 (08:32 +0200)
committerRichard Biener <rguenther@suse.de>
Thu, 29 Apr 2021 08:02:59 +0000 (10:02 +0200)
In testcases like PR38474 and PR99912 we're seeing very slow
PTA solving.  One can observe an excessive amount of forwarding,
mostly during sd constraint solving.  The way we solve the graph
does not avoid forwarding the same bits through multiple paths,
and especially when such alternate path involves ESCAPED as
intermediate this causes the ESCAPED solution to be expanded
in receivers.

The following adds heuristic to add_graph_edge which adds
forwarding edges but also guards the initial solution forwarding
(which is the expensive part) to detect the case of ESCAPED
receiving the same set and the destination already containing
ESCAPED.

This speeds up the PTA solving process by more than 50%.

2021-04-29  Richard Biener  <rguenther@suse.de>

PR middle-end/38474
* tree-ssa-structalias.c (add_graph_edge): Avoid direct
forwarding when indirect forwarding through ESCAPED
alread happens.

gcc/tree-ssa-structalias.c

index 529ec3a5b8049c9eb25f7ac9fd4dac1f9fb9a5cc..a0238710e7215ac0b36945b6cfa90fe850ffc9e5 100644 (file)
@@ -1195,6 +1195,22 @@ add_graph_edge (constraint_graph_t graph, unsigned int to,
 
       if (!graph->succs[from])
        graph->succs[from] = BITMAP_ALLOC (&pta_obstack);
+
+      /* The graph solving process does not avoid "triangles", thus
+        there can be multiple paths from a node to another involving
+        intermediate other nodes.  That causes extra copying which is
+        most difficult to avoid when the intermediate node is ESCAPED
+        because there are no edges added from ESCAPED.  Avoid
+        adding the direct edge FROM -> TO when we have FROM -> ESCAPED
+        and TO contains ESCAPED.
+        ???  Note this is only a heuristic, it does not prevent the
+        situation from occuring.  The heuristic helps PR38474 and
+        PR99912 significantly.  */
+      if (to < FIRST_REF_NODE
+         && bitmap_bit_p (graph->succs[from], find (escaped_id))
+         && bitmap_bit_p (get_varinfo (find (to))->solution, escaped_id))
+       return false;
+
       if (bitmap_set_bit (graph->succs[from], to))
        {
          r = true;