--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-fre1-details" } */
+
+int test1 (int i, int j)
+{
+ int k;
+ if (i != j)
+ k = i;
+ else
+ k = j;
+ return k;
+}
+
+int test2 (int i, int j)
+{
+ int k;
+ if (i != j)
+ k = j;
+ else
+ k = i;
+ return k;
+}
+
+int test3 (int i, int j)
+{
+ int k;
+ if (i == j)
+ k = j;
+ else
+ k = i;
+ return k;
+}
+
+int test4 (int i, int j)
+{
+ int k;
+ if (i == j)
+ k = i;
+ else
+ k = j;
+ return k;
+}
+
+/* We'd expect 4 hits but since we only keep one forwarder the
+ VN predication machinery cannot record something for the entry
+ block since it doesn't work on edges but on their source. */
+/* { dg-final { scan-tree-dump-times "equal on edge" 2 "fre1" } } */
/* See if all non-TOP arguments have the same value. TOP is
equivalent to everything, so we can ignore it. */
- FOR_EACH_EDGE (e, ei, gimple_bb (phi)->preds)
+ basic_block bb = gimple_bb (phi);
+ FOR_EACH_EDGE (e, ei, bb->preds)
if (e->flags & EDGE_EXECUTABLE)
{
tree def = PHI_ARG_DEF_FROM_EDGE (phi, e);
&& known_eq (soff, doff))
continue;
}
+ /* There's also the possibility to use equivalences. */
+ if (!FLOAT_TYPE_P (TREE_TYPE (def)))
+ {
+ vn_nary_op_t vnresult;
+ tree ops[2];
+ ops[0] = def;
+ ops[1] = sameval;
+ tree val = vn_nary_op_lookup_pieces (2, EQ_EXPR,
+ boolean_type_node,
+ ops, &vnresult);
+ if (! val && vnresult && vnresult->predicated_values)
+ {
+ val = vn_nary_op_get_predicated_value (vnresult, e->src);
+ if (val && integer_truep (val))
+ {
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ {
+ fprintf (dump_file, "Predication says ");
+ print_generic_expr (dump_file, def, TDF_NONE);
+ fprintf (dump_file, " and ");
+ print_generic_expr (dump_file, sameval, TDF_NONE);
+ fprintf (dump_file, " are equal on edge %d -> %d\n",
+ e->src->index, e->dest->index);
+ }
+ continue;
+ }
+ /* If on all previous edges the value was equal to def
+ we can change sameval to def. */
+ if (EDGE_COUNT (bb->preds) == 2
+ && (val = vn_nary_op_get_predicated_value
+ (vnresult, EDGE_PRED (bb, 0)->src))
+ && integer_truep (val))
+ {
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ {
+ fprintf (dump_file, "Predication says ");
+ print_generic_expr (dump_file, def, TDF_NONE);
+ fprintf (dump_file, " and ");
+ print_generic_expr (dump_file, sameval, TDF_NONE);
+ fprintf (dump_file, " are equal on edge %d -> %d\n",
+ EDGE_PRED (bb, 0)->src->index,
+ EDGE_PRED (bb, 0)->dest->index);
+ }
+ sameval = def;
+ continue;
+ }
+ }
+ }
sameval = NULL_TREE;
break;
}