https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110666
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> --- I totally messed up the !=1/!=0 cases for the outer eq case: Patch diff --git a/gcc/match.pd b/gcc/match.pd index 351d9285e92..3de30df8b06 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -6431,8 +6431,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) /* x != (typeof x)(x == CST) -> CST == 0 ? 1 : (CST == 1 ? (x!=0&&x!=1) : x != 0) */ /* x != (typeof x)(x != CST) -> CST == 1 ? 1 : (CST == 0 ? (x!=0&&x!=1) : x != 1) */ -/* x == (typeof x)(x == CST) -> CST == 0 ? 0 : (CST == 1 ? (x==0||x==1) : x != 0) */ -/* x == (typeof x)(x != CST) -> CST == 1 ? 0 : (CST == 0 ? (x==0||x==1) : x != 1) */ +/* x == (typeof x)(x == CST) -> CST == 0 ? 0 : (CST == 1 ? (x==0||x==1) : x == 0) */ +/* x == (typeof x)(x != CST) -> CST == 1 ? 0 : (CST == 0 ? (x==0||x==1) : x == 1) */ (for outer (ne eq) (for inner (ne eq) (simplify @@ -6457,9 +6457,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) ) ) ) - (if (innereq) - (ne @0 { build_zero_cst (TREE_TYPE (@0)); })) - (ne @0 { build_one_cst (TREE_TYPE (@0)); })) + (with { + tree value = build_int_cst (TREE_TYPE (@0), !innereq); + } + (if (outereq) + (eq @0 { value; }) + (ne @0 { value; }) + ) + ) ) ) )