+ tree cond_expr;
+ tree phi;
+ basic_block bb1, bb2;
+ edge e1, e2;
+ tree arg0, arg1;
+
+ bb = bb_order[i];
+
+ cond_expr = last_stmt (bb);
+ /* Check to see if the last statement is a COND_EXPR. */
+ if (!cond_expr
+ || TREE_CODE (cond_expr) != COND_EXPR)
+ continue;
+
+ e1 = EDGE_SUCC (bb, 0);
+ bb1 = e1->dest;
+ e2 = EDGE_SUCC (bb, 1);
+ bb2 = e2->dest;
+
+ /* We cannot do the optimization on abnormal edges. */
+ if ((e1->flags & EDGE_ABNORMAL) != 0
+ || (e2->flags & EDGE_ABNORMAL) != 0)
+ continue;
+
+ /* If either bb1's succ or bb2 or bb2's succ is non NULL. */
+ if (EDGE_COUNT (bb1->succs) == 0
+ || bb2 == NULL
+ || EDGE_COUNT (bb2->succs) == 0)
+ continue;
+
+ /* Find the bb which is the fall through to the other. */
+ if (EDGE_SUCC (bb1, 0)->dest == bb2)
+ ;
+ else if (EDGE_SUCC (bb2, 0)->dest == bb1)
+ {
+ basic_block bb_tmp = bb1;
+ edge e_tmp = e1;
+ bb1 = bb2;
+ bb2 = bb_tmp;
+ e1 = e2;
+ e2 = e_tmp;
+ }
+ else
+ continue;
+
+ e1 = EDGE_SUCC (bb1, 0);
+
+ /* Make sure that bb1 is just a fall through. */
+ if (!single_succ_p (bb1)
+ || (e1->flags & EDGE_FALLTHRU) == 0)
+ continue;
+
+ /* Also make sure that bb1 only have one predecessor and that it
+ is bb. */
+ if (!single_pred_p (bb1)
+ || single_pred (bb1) != bb)
+ continue;
+
+ phi = phi_nodes (bb2);
+
+ /* Check to make sure that there is only one PHI node.
+ TODO: we could do it with more than one iff the other PHI nodes
+ have the same elements for these two edges. */
+ if (!phi || PHI_CHAIN (phi) != NULL)
+ continue;
+
+ arg0 = PHI_ARG_DEF_TREE (phi, e1->dest_idx);
+ arg1 = PHI_ARG_DEF_TREE (phi, e2->dest_idx);
+
+ /* Something is wrong if we cannot find the arguments in the PHI
+ node. */
+ gcc_assert (arg0 != NULL && arg1 != NULL);
+
+ /* Do the replacement of conditional if it can be done. */
+ if (conditional_replacement (bb, bb1, e1, e2, phi, arg0, arg1))
+ cfgchanged = true;
+ else if (value_replacement (bb, bb1, e1, e2, phi, arg0, arg1))
+ cfgchanged = true;
+ else if (abs_replacement (bb, bb1, e1, e2, phi, arg0, arg1))
+ cfgchanged = true;
+ else if (minmax_replacement (bb, bb1, e1, e2, phi, arg0, arg1))
+ cfgchanged = true;
+ }
+
+ free (bb_order);
+
+ /* If the CFG has changed, we should cleanup the CFG. */
+ return cfgchanged ? TODO_cleanup_cfg : 0;
+}