https://gcc.gnu.org/g:c40715a3482776162a92756adf24538a800d5b00
commit r17-4036-gc40715a3482776162a92756adf24538a800d5b00 Author: Kyrylo Tkachov <[email protected]> Date: Sun Sep 6 13:17:21 2026 +0200 ifcvt: factor the if-case precondition check 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]> Diff: --- gcc/ifcvt.cc | 74 +++++++++++++++++++++++++----------------------------------- 1 file changed, 31 insertions(+), 43 deletions(-) diff --git a/gcc/ifcvt.cc b/gcc/ifcvt.cc index dc1a781e691f..d7cbd7065fa1 100644 --- a/gcc/ifcvt.cc +++ b/gcc/ifcvt.cc @@ -6392,28 +6392,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))) @@ -6424,8 +6419,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. */ @@ -6528,28 +6537,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. */
