return true;
}
-/* Return true when BB post-dominates all its predecessors. */
-
-static bool
-bb_postdominates_preds (basic_block bb)
-{
- unsigned i;
-
- for (i = 0; i < EDGE_COUNT (bb->preds); i++)
- if (!dominated_by_p (CDI_POST_DOMINATORS, EDGE_PRED (bb, i)->src, bb))
- return false;
-
- return true;
-}
-
/* Return true when BB is if-convertible. This routine does not check
basic block's statements and phis.
return false;
}
- if (EDGE_COUNT (bb->preds) == 2
- && bb != loop->header
- && !bb_postdominates_preds (bb))
- return false;
+ /* At least one incoming edge has to be non-critical as otherwise edge
+ predicates are not equal to basic-block predicates of the edge
+ source. */
+ if (EDGE_COUNT (bb->preds) > 1
+ && bb != loop->header)
+ {
+ bool found = false;
+ FOR_EACH_EDGE (e, ei, bb->preds)
+ if (EDGE_COUNT (e->src->succs) == 1)
+ found = true;
+ if (!found)
+ {
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ fprintf (dump_file, "only critical predecessors\n");
+ return false;
+ }
+ }
return true;
}
return false;
calculate_dominance_info (CDI_DOMINATORS);
- calculate_dominance_info (CDI_POST_DOMINATORS);
/* Allow statements that can be handled during if-conversion. */
ifc_bbs = get_loop_body_in_if_conv_order (loop);
if-conversion. */
static basic_block
-find_phi_replacement_condition (struct loop *loop,
- basic_block bb, tree *cond,
+find_phi_replacement_condition (basic_block bb, tree *cond,
gimple_stmt_iterator *gsi)
{
edge first_edge, second_edge;
first_edge = EDGE_PRED (bb, 0);
second_edge = EDGE_PRED (bb, 1);
- /* Use condition based on following criteria:
- 1)
- S1: x = !c ? a : b;
-
- S2: x = c ? b : a;
-
- S2 is preferred over S1. Make 'b' first_bb and use its condition.
-
- 2) Do not make loop header first_bb.
-
- 3)
- S1: x = !(c == d)? a : b;
-
- S21: t1 = c == d;
- S22: x = t1 ? b : a;
-
- S3: x = (c == d) ? b : a;
-
- S3 is preferred over S1 and S2*, Make 'b' first_bb and use
- its condition.
-
- 4) If pred B is dominated by pred A then use pred B's condition.
- See PR23115. */
-
- /* Select condition that is not TRUTH_NOT_EXPR. */
+ /* Prefer an edge with a not negated predicate.
+ ??? That's a very weak cost model. */
tmp_cond = bb_predicate (first_edge->src);
gcc_assert (tmp_cond);
-
if (TREE_CODE (tmp_cond) == TRUTH_NOT_EXPR)
{
edge tmp_edge;
second_edge = tmp_edge;
}
- /* Check if FIRST_BB is loop header or not and make sure that
- FIRST_BB does not dominate SECOND_BB. */
- if (first_edge->src == loop->header
- || dominated_by_p (CDI_DOMINATORS,
- second_edge->src, first_edge->src))
+ /* Check if the edge we take the condition from is not critical.
+ We know that at least one non-critical edge exists. */
+ if (EDGE_COUNT (first_edge->src->succs) > 1)
{
*cond = bb_predicate (second_edge->src);
arg_1 = gimple_phi_arg_def (phi, 1);
}
- gcc_checking_assert (bb == bb->loop_father->header
- || bb_postdominates_preds (bb));
-
/* Build new RHS using selected condition and arguments. */
rhs = fold_build_cond_expr (TREE_TYPE (res), unshare_expr (cond),
arg_0, arg_1);
/* BB has two predecessors. Using predecessor's aux field, set
appropriate condition for the PHI node replacement. */
gsi = gsi_after_labels (bb);
- true_bb = find_phi_replacement_condition (loop, bb, &cond, &gsi);
+ true_bb = find_phi_replacement_condition (bb, &cond, &gsi);
while (!gsi_end_p (phi_gsi))
{
free (ifc_bbs);
ifc_bbs = NULL;
-
- /* Post-dominators are corrupt now. */
- free_dominance_info (CDI_POST_DOMINATORS);
}
/* If-convert LOOP when it is legal. For the moment this pass has no
if (changed && flag_tree_loop_if_convert_stores)
todo |= TODO_update_ssa_only_virtuals;
- free_dominance_info (CDI_POST_DOMINATORS);
-
#ifdef ENABLE_CHECKING
{
basic_block bb;
0, /* properties_provided */
0, /* properties_destroyed */
0, /* todo_flags_start */
- ( TODO_verify_stmts | TODO_verify_flow ), /* todo_flags_finish */
+ ( TODO_verify_stmts | TODO_verify_flow
+ | TODO_verify_ssa ), /* todo_flags_finish */
};
class pass_if_conversion : public gimple_opt_pass