+/* Add condition COND into predicate list of basic block BB. */
+
+static void
+add_to_predicate_list (basic_block bb, tree new_cond)
+{
+ tree cond = (tree) bb->aux;
+
+ if (cond)
+ cond = fold_build2_loc (EXPR_LOCATION (cond),
+ TRUTH_OR_EXPR, boolean_type_node,
+ unshare_expr (cond), new_cond);
+ else
+ cond = new_cond;
+
+ bb->aux = cond;
+}
+
+/* Add condition COND into BB's predicate list. PREV_COND is
+ existing condition. */
+
+static tree
+add_to_dst_predicate_list (struct loop * loop, edge e,
+ tree prev_cond, tree cond,
+ gimple_stmt_iterator *gsi)
+{
+ tree new_cond = NULL_TREE;
+
+ if (!flow_bb_inside_loop_p (loop, e->dest))
+ return NULL_TREE;
+
+ if (prev_cond == boolean_true_node || !prev_cond)
+ new_cond = unshare_expr (cond);
+ else
+ {
+ tree tmp;
+ gimple tmp_stmt = NULL;
+
+ prev_cond = force_gimple_operand_gsi (gsi, unshare_expr (prev_cond),
+ true, NULL, true, GSI_SAME_STMT);
+
+ cond = force_gimple_operand_gsi (gsi, unshare_expr (cond),
+ true, NULL, true, GSI_SAME_STMT);
+
+ /* Add the condition to aux field of the edge. In case edge
+ destination is a PHI node, this condition will be ANDed with
+ block predicate to construct complete condition. */
+ e->aux = cond;
+
+ /* new_cond == prev_cond AND cond */
+ tmp = build2 (TRUTH_AND_EXPR, boolean_type_node,
+ unshare_expr (prev_cond), cond);
+ tmp_stmt = ifc_temp_var (boolean_type_node, tmp);
+ gsi_insert_before (gsi, tmp_stmt, GSI_SAME_STMT);
+ new_cond = gimple_assign_lhs (tmp_stmt);
+ }
+ add_to_predicate_list (e->dest, new_cond);
+ return new_cond;
+}
+
+/* During if-conversion aux field from basic block structure is used to hold
+ predicate list. Clean each basic block's predicate list for the given LOOP.
+ Also clean aux field of successor edges, used to hold true and false
+ condition from conditional expression. */