|| arg != gimple_cond_lhs (cond))
return false;
- /* Canonicalize. */
- if ((e2->flags & EDGE_TRUE_VALUE
- && gimple_cond_code (cond) == NE_EXPR)
- || (e1->flags & EDGE_TRUE_VALUE
- && gimple_cond_code (cond) == EQ_EXPR))
+ edge true_edge, false_edge;
+ /* We need to know which is the true edge and which is the false
+ edge so that we know when to invert the condition below. */
+ extract_true_false_edges_from_block (cond_bb, &true_edge, &false_edge);
+
+ /* Forward the edges over the middle basic block. */
+ if (true_edge->dest == middle_bb)
+ true_edge = EDGE_SUCC (true_edge->dest, 0);
+ if (false_edge->dest == middle_bb)
+ false_edge = EDGE_SUCC (false_edge->dest, 0);
+
+ /* Canonicalize the args with respect to the edges,
+ arg0 is from the true edge and arg1 is from the
+ false edge.
+ That is `cond ? arg0 : arg1`.*/
+ if (true_edge == e1)
+ gcc_assert (false_edge == e2);
+ else
{
+ gcc_assert (false_edge == e1);
+ gcc_assert (true_edge == e2);
std::swap (arg0, arg1);
- std::swap (e1, e2);
}
+ /* Canonicalize the args such that we get:
+ `arg != 0 ? arg0 : arg1`. So swap arg0/arg1
+ around if cond was an equals. */
+ if (gimple_cond_code (cond) == EQ_EXPR)
+ std::swap (arg0, arg1);
+
/* Check PHI arguments. */
if (lhs != arg0
|| TREE_CODE (arg1) != INTEGER_CST)