From: Kyrylo Tkachov <[email protected]>

find_if_case_1 and find_if_case_2 open with the same twenty-two lines: the
hot/cold partition check on all three blocks, its long explanatory comment,
and the test that TEST_BB ends in a plain conditional jump.

Move them into if_case_blocks_ok_p.  No functional change.

gcc/ChangeLog:

        * ifcvt.cc (if_case_blocks_ok_p): New function.
        (find_if_case_1, find_if_case_2): Use it.

Signed-off-by: Kyrylo Tkachov <[email protected]>
---
 gcc/ifcvt.cc | 74 ++++++++++++++++++++++------------------------------
 1 file changed, 31 insertions(+), 43 deletions(-)

diff --git a/gcc/ifcvt.cc b/gcc/ifcvt.cc
index c3beeaebe77..478c9ee985c 100644
--- a/gcc/ifcvt.cc
+++ b/gcc/ifcvt.cc
@@ -6274,28 +6274,23 @@ block_has_only_trap (basic_block bb)
 
    (D) These heuristics need a lot of work.  */
 
-/* Tests for case 1 above.  */
-
-static bool
-find_if_case_1 (basic_block test_bb, edge then_edge, edge else_edge)
-{
-  basic_block then_bb = then_edge->dest;
-  basic_block else_bb = else_edge->dest;
-  basic_block new_bb;
-  int then_bb_index;
-  profile_probability then_prob;
-  rtx else_target = NULL_RTX;
+/* Return true if the if-case formed by TEST_BB, THEN_BB and ELSE_BB is one we
+   may convert at all.
 
-  /* If we are partitioning hot/cold basic blocks, we don't want to
-     mess up unconditional or indirect jumps that cross between hot
-     and cold sections.
+   If we are partitioning hot/cold basic blocks, we don't want to mess up
+   unconditional or indirect jumps that cross between hot and cold sections.
+   Basic block partitioning may result in some jumps that appear to be
+   optimizable (or blocks that appear to be mergeable), but which really must
+   be left untouched (they are required to make it safely across partition
+   boundaries).  See the comments at the top of
+   bb-reorder.cc:partition_hot_cold_basic_blocks for complete details.
 
-     Basic block partitioning may result in some jumps that appear to
-     be optimizable (or blocks that appear to be mergeable), but which really
-     must be left untouched (they are required to make it safely across
-     partition boundaries).  See  the comments at the top of
-     bb-reorder.cc:partition_hot_cold_basic_blocks for complete details.  */
+   TEST_BB must also end in a conditional jump with no other side-effects.  */
 
+static bool
+if_case_blocks_ok_p (basic_block test_bb, basic_block then_bb,
+                    basic_block else_bb)
+{
   if ((BB_END (then_bb)
        && JUMP_P (BB_END (then_bb))
        && CROSSING_JUMP_P (BB_END (then_bb)))
@@ -6306,8 +6301,22 @@ find_if_case_1 (basic_block test_bb, edge then_edge, 
edge else_edge)
          && CROSSING_JUMP_P (BB_END (else_bb))))
     return false;
 
-  /* Verify test_bb ends in a conditional jump with no other side-effects.  */
-  if (!onlyjump_p (BB_END (test_bb)))
+  return onlyjump_p (BB_END (test_bb));
+}
+
+/* Tests for case 1 above.  */
+
+static bool
+find_if_case_1 (basic_block test_bb, edge then_edge, edge else_edge)
+{
+  basic_block then_bb = then_edge->dest;
+  basic_block else_bb = else_edge->dest;
+  basic_block new_bb;
+  int then_bb_index;
+  profile_probability then_prob;
+  rtx else_target = NULL_RTX;
+
+  if (!if_case_blocks_ok_p (test_bb, then_bb, else_bb))
     return false;
 
   /* THEN has one successor.  */
@@ -6410,28 +6419,7 @@ find_if_case_2 (basic_block test_bb, edge then_edge, 
edge else_edge)
       && else_bb->loop_father->latch == else_bb)
     return false;
 
-  /* If we are partitioning hot/cold basic blocks, we don't want to
-     mess up unconditional or indirect jumps that cross between hot
-     and cold sections.
-
-     Basic block partitioning may result in some jumps that appear to
-     be optimizable (or blocks that appear to be mergeable), but which really
-     must be left untouched (they are required to make it safely across
-     partition boundaries).  See  the comments at the top of
-     bb-reorder.cc:partition_hot_cold_basic_blocks for complete details.  */
-
-  if ((BB_END (then_bb)
-       && JUMP_P (BB_END (then_bb))
-       && CROSSING_JUMP_P (BB_END (then_bb)))
-      || (JUMP_P (BB_END (test_bb))
-         && CROSSING_JUMP_P (BB_END (test_bb)))
-      || (BB_END (else_bb)
-         && JUMP_P (BB_END (else_bb))
-         && CROSSING_JUMP_P (BB_END (else_bb))))
-    return false;
-
-  /* Verify test_bb ends in a conditional jump with no other side-effects.  */
-  if (!onlyjump_p (BB_END (test_bb)))
+  if (!if_case_blocks_ok_p (test_bb, then_bb, else_bb))
     return false;
 
   /* ELSE has one successor.  */
-- 
2.50.1 (Apple Git-155)

Reply via email to