mark region also for USE predicate discovery
authorRichard Biener <rguenther@suse.de>
Tue, 6 Sep 2022 13:30:53 +0000 (15:30 +0200)
committerRichard Biener <rguenther@suse.de>
Wed, 7 Sep 2022 10:07:52 +0000 (12:07 +0200)
The following makes sure to mark the dominating region also for
USE predicate discovery, avoiding compute_control_dep_chain to
walk to unrelated areas, eating up walking budget.

* gimple-predicate-analysis.cc (dfs_mark_dominating_region):
Adjust to take the region exit source as argument.
(uninit_analysis::init_from_phi_def): Adjust.
(uninit_analysis::init_use_preds): Mark the dominating region
before computing control dependences.

gcc/gimple-predicate-analysis.cc

index 5dade45..f81af25 100644 (file)
@@ -934,23 +934,23 @@ simple_control_dep_chain (vec<edge>& chain, basic_block from, basic_block to)
 }
 
 /* Perform a DFS walk on predecessor edges to mark the region denoted
-   by the EXIT edge and DOM which dominates EXIT->src, including DOM.
+   by the EXIT_SRC block and DOM which dominates EXIT_SRC, including DOM.
    Blocks in the region are marked with FLAG and added to BBS.  BBS is
    filled up to its capacity only after which the walk is terminated
    and false is returned.  If the whole region was marked, true is returned.  */
 
 static bool
-dfs_mark_dominating_region (edge exit, basic_block dom, int flag,
+dfs_mark_dominating_region (basic_block exit_src, basic_block dom, int flag,
                            vec<basic_block> &bbs)
 {
-  if (exit->src == dom || exit->src->flags & flag)
+  if (exit_src == dom || exit_src->flags & flag)
     return true;
   if (!bbs.space (1))
     return false;
-  bbs.quick_push (exit->src);
-  exit->src->flags |= flag;
+  bbs.quick_push (exit_src);
+  exit_src->flags |= flag;
   auto_vec<edge_iterator, 20> stack (bbs.allocated () - bbs.length () + 1);
-  stack.quick_push (ei_start (exit->src->preds));
+  stack.quick_push (ei_start (exit_src->preds));
   while (!stack.is_empty ())
     {
       /* Look at the edge on the top of the stack.  */
@@ -1960,6 +1960,10 @@ uninit_analysis::init_use_preds (predicate &use_preds, basic_block def_bb,
     }
   while (1);
 
+  auto_bb_flag in_region (cfun);
+  auto_vec<basic_block, 20> region (MIN (n_basic_blocks_for_fn (cfun),
+                                        param_uninit_control_dep_attempts));
+
   /* Set DEP_CHAINS to the set of edges between CD_ROOT and USE_BB.
      Each DEP_CHAINS element is a series of edges whose conditions
      are logical conjunctions.  Together, the DEP_CHAINS vector is
@@ -1967,7 +1971,9 @@ uninit_analysis::init_use_preds (predicate &use_preds, basic_block def_bb,
   unsigned num_chains = 0;
   auto_vec<edge> dep_chains[MAX_NUM_CHAINS];
 
-  if (!compute_control_dep_chain (cd_root, use_bb, dep_chains, &num_chains))
+  if (!dfs_mark_dominating_region (use_bb, cd_root, in_region, region)
+      || !compute_control_dep_chain (cd_root, use_bb, dep_chains, &num_chains,
+                                    in_region))
     {
       /* If the info in dep_chains is not complete we need to use a
         conservative approximation for the use predicate.  */
@@ -1979,6 +1985,10 @@ uninit_analysis::init_use_preds (predicate &use_preds, basic_block def_bb,
       simple_control_dep_chain (dep_chains[0], cd_root, use_bb);
     }
 
+  /* Unmark the region.  */
+  for (auto bb : region)
+    bb->flags &= ~in_region;
+
   /* From the set of edges computed above initialize *THIS as the OR
      condition under which the definition in DEF_BB is used in USE_BB.
      Each OR subexpression is represented by one element of DEP_CHAINS,
@@ -2061,7 +2071,8 @@ uninit_analysis::init_from_phi_def (gphi *phi)
        }
     }
   for (unsigned i = 0; i < nedges; i++)
-    if (!dfs_mark_dominating_region (def_edges[i], cd_root, in_region, region))
+    if (!dfs_mark_dominating_region (def_edges[i]->src, cd_root,
+                                    in_region, region))
       break;
 
   unsigned num_chains = 0;