--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+/* PR tree-optimization/117414 */
+
+/* Fre1 should figure out that `*aaa != 0`
+ For f0, f1, and f2. */
+
+void foo();
+int f(int *aaa, int j, int t)
+{
+ int b = *aaa;
+ int c = b == 0;
+ int d = t != 1;
+ if (c | d)
+ return 0;
+
+ for(int i = 0; i < j; i++)
+ {
+ if (*aaa)
+ ;
+ else
+ foo();
+ }
+ return 0;
+}
+
+int f1(int *aaa, int j, int t)
+{
+ int b = *aaa;
+ if (b == 0)
+ return 0;
+ if (t != 1)
+ return 0;
+ for(int i = 0; i < j; i++)
+ {
+ if (*aaa)
+ ;
+ else
+ foo();
+ }
+ return 0;
+}
+
+/* { dg-final { scan-tree-dump-not "foo " "optimized" } } */
+/* { dg-final { scan-tree-dump "return 0;" "optimized" } } */
&& (code == NE_EXPR || code == EQ_EXPR))
{
gimple *def_stmt = SSA_NAME_DEF_STMT (lhs);
+ /* (A CMP B) != 0 is the same as (A CMP B).
+ (A CMP B) == 0 is just (A CMP B) with the edges swapped. */
+ if (is_gimple_assign (def_stmt)
+ && TREE_CODE_CLASS (gimple_assign_rhs_code (def_stmt)) == tcc_comparison)
+ {
+ tree_code nc = gimple_assign_rhs_code (def_stmt);
+ tree nlhs = vn_valueize (gimple_assign_rhs1 (def_stmt));
+ tree nrhs = vn_valueize (gimple_assign_rhs2 (def_stmt));
+ edge nt = true_e;
+ edge nf = false_e;
+ if (code == EQ_EXPR)
+ std::swap (nt, nf);
+ insert_predicates_for_cond (nc, nlhs, nrhs, nt, nf);
+ }
/* (a | b) == 0 ->
on true edge assert: a == 0 & b == 0. */
/* (a | b) != 0 ->