]> gcc.gnu.org Git - gcc.git/commitdiff
Refactor is_non_loop_exit_postdominating
authorRichard Biener <rguenther@suse.de>
Mon, 22 Aug 2022 13:24:23 +0000 (15:24 +0200)
committerRichard Biener <rguenther@suse.de>
Tue, 23 Aug 2022 07:05:07 +0000 (09:05 +0200)
That's a weird function in predicate analysis that currently looks like

/* Return true if BB1 is postdominating BB2 and BB1 is not a loop exit
   bb.  The loop exit bb check is simple and does not cover all cases.  */
static bool
is_non_loop_exit_postdominating (basic_block bb1, basic_block bb2)
{
  if (!dominated_by_p (CDI_POST_DOMINATORS, bb2, bb1))
    return false;
  if (single_pred_p (bb1) && !single_succ_p (bb2))
    return false;
  return true;
}

One can refactor this to

  return (dominated_by_p (CDI_POST_DOMINATORS, bb2, bb1)
          && !(single_pred_p (bb1) && !single_succ_p (bb2)));

Notable is that the comment refers to BB1 with respect to a loop
exit but the test seems to be written with an exit edge bb1 -> bb2
in mind.  None of the three callers are guaranteed to have bb1 and
bb2 connected directly with an edge.

The patch now introduces a is_loop_exit function and inlines
the post-dominance check which makes the find_control_equiv_block
case simpler because the post-dominance check can be elided.
It also avoids the double negation in compute_control_dep_chain
and makes it obvious this is the case where we do look at an edge.
For the main is_use_guarded API I chose to elide the loop exit
test, if the use block post-dominates the definition block of the
PHI node the use is always unconditional.  I don't quite understand
the loop exit special-casing of the remaining two uses though.

* gimple-predicate-analysis.cc (is_loop_exit): Split out
from ...
(is_non_loop_exit_postdominating): ... here.  Remove after
inlining ...
(find_control_equiv_block): ... here.
(compute_control_dep_chain): ... and here.
(predicate::is_use_guarded): Do not excempt loop exits
from short-cutting the case of the use post-dominating the
PHI definition.

gcc/gimple-predicate-analysis.cc

index d1b0d1283dc39e196d0983995558eb67c6f645c2..e8e2dbf70347584b50bbb06cdb76b4aa6cf803cc 100644 (file)
 
 #define DEBUG_PREDICATE_ANALYZER 1
 
-/* Return true if BB1 is postdominating BB2 and BB1 is not a loop exit
-   bb.  The loop exit bb check is simple and does not cover all cases.  */
+/* Return true if, when BB1 is postdominating BB2, BB1 is a loop exit.  */
 
 static bool
-is_non_loop_exit_postdominating (basic_block bb1, basic_block bb2)
+is_loop_exit (basic_block bb2, basic_block bb1)
 {
-  if (!dominated_by_p (CDI_POST_DOMINATORS, bb2, bb1))
-    return false;
-
-  if (single_pred_p (bb1) && !single_succ_p (bb2))
-    return false;
-
-  return true;
+  return single_pred_p (bb1) && !single_succ_p (bb2);
 }
 
 /* Find BB's closest postdominator that is its control equivalent (i.e.,
@@ -70,7 +63,7 @@ find_control_equiv_block (basic_block bb)
   basic_block pdom = get_immediate_dominator (CDI_POST_DOMINATORS, bb);
 
   /* Skip the postdominating bb that is also a loop exit.  */
-  if (!is_non_loop_exit_postdominating (pdom, bb))
+  if (is_loop_exit (bb, pdom))
     return NULL;
 
   /* If the postdominator is dominated by BB, return it.  */
@@ -1114,7 +1107,8 @@ compute_control_dep_chain (basic_block dom_bb, const_basic_block dep_bb,
 
       basic_block cd_bb = e->dest;
       cur_cd_chain.safe_push (e);
-      while (!is_non_loop_exit_postdominating (cd_bb, dom_bb))
+      while (!dominated_by_p (CDI_POST_DOMINATORS, dom_bb, cd_bb)
+            || is_loop_exit (dom_bb, cd_bb))
        {
          if (cd_bb == dep_bb)
            {
@@ -1885,7 +1879,7 @@ predicate::is_use_guarded (gimple *use_stmt, basic_block use_bb,
      in the same bb.  */
   predicate use_preds (def_bb, use_bb, m_eval);
 
-  if (is_non_loop_exit_postdominating (use_bb, def_bb))
+  if (dominated_by_p (CDI_POST_DOMINATORS, def_bb, use_bb))
     {
       if (is_empty ())
        {
This page took 0.06582 seconds and 5 git commands to generate.