https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101617
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
So it turns out you can make this generic and don't need to handle 1 specially
diff --git a/gcc/match.pd b/gcc/match.pd
index beb8d27535e..2af987278af 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -3805,14 +3805,23 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(simplify
(cond @0 INTEGER_CST@1 INTEGER_CST@2)
(switch
+ /* a ? CST : -1 -> -(!a) | CST. */
+ (if (INTEGRAL_TYPE_P (type) && integer_all_onesp (@2))
+ (with {
+ tree booltrue = constant_boolean_node (true, boolean_type_node);
+ }
+ (bit_ior (negate (convert (bit_xor (convert:boolean_type_node @0) {
booltrue; } ))) @2)))
+ /* a ? -1 : CST -> -(a) | CST. */
+ (if (INTEGRAL_TYPE_P (type) && integer_all_onesp (@1))
+ (with {
+ tree booltrue = constant_boolean_node (true, boolean_type_node);
+ }
+ (bit_ior (negate (convert (convert:boolean_type_node @0))) @2)))
(if (integer_zerop (@2))
(switch
/* a ? 1 : 0 -> a if 0 and 1 are integral types. */
(if (integer_onep (@1))
(convert (convert:boolean_type_node @0)))
- /* a ? -1 : 0 -> -a. */
- (if (INTEGRAL_TYPE_P (type) && integer_all_onesp (@1))
- (negate (convert (convert:boolean_type_node @0))))
/* a ? powerof2cst : 0 -> a << (log2(powerof2cst)) */
(if (INTEGRAL_TYPE_P (type) && integer_pow2p (@1))
(with {
@@ -3827,9 +3836,6 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
/* a ? 0 : 1 -> !a. */
(if (integer_onep (@2))
(convert (bit_xor (convert:boolean_type_node @0) { booltrue; } )))
- /* a ? -1 : 0 -> -(!a). */
- (if (INTEGRAL_TYPE_P (type) && integer_all_onesp (@2))
- (negate (convert (bit_xor (convert:boolean_type_node @0) { booltrue; }
))))
/* a ? powerof2cst : 0 -> (!a) << (log2(powerof2cst)) */
(if (INTEGRAL_TYPE_P (type) && integer_pow2p (@2))
(with {