https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105197
--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
The following improves the output from if-conversion by simplifying ~cond ? a :
b
to cond ? b : a, possibly reducing the number of conds. Ideally if-conversion
would track predicates in a more concious way of course.
diff --git a/gcc/tree-if-conv.cc b/gcc/tree-if-conv.cc
index 7495ed653c0..dd3d5255a38 100644
--- a/gcc/tree-if-conv.cc
+++ b/gcc/tree-if-conv.cc
@@ -472,6 +472,14 @@ fold_build_cond_expr (tree type, tree cond, tree rhs, tree
lhs)
&& (integer_zerop (op1)))
cond = op0;
}
+ gassign *ass;
+ if (TREE_CODE (cond) == SSA_NAME
+ && (ass = dyn_cast <gassign *> (SSA_NAME_DEF_STMT (cond)))
+ && gimple_assign_rhs_code (ass) == BIT_NOT_EXPR)
+ {
+ cond = gimple_assign_rhs1 (ass);
+ std::swap (rhs, lhs);
+ }
cond_expr = fold_ternary (COND_EXPR, type, cond, rhs, lhs);
if (cond_expr == NULL_TREE)