--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -2339,6 +2339,16 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(if (INTEGRAL_TYPE_P (type))
(bit_and @0 @1)))
+/* Fold `(a ? b : 0) | (a ? 0 : c)` into (a ? b : c).
+ Handle also ^ and + in replacement of `|`. */
+(for cnd (cond vec_cond)
+ (for op (bit_ior bit_xor plus)
+ (simplify
+ (op:c
+ (cnd:s @0 @00 integer_zerop)
+ (cnd:s @0 integer_zerop @01))
+ (cnd @0 @00 @01))))
Wouldn't it fall into something more generic like
(for cnd (cond vec_cond)
(for op (any_binary)
(simplify
(op
(cnd:s @0 @1 @2)
(cnd:s @0 @3 @4))
(cnd @0 (op! @1 @3) (op! @2 @4)))))
?
The example given in the doc for the use of '!' is pretty close
@smallexample
(simplify
(plus (vec_cond:s @@0 @@1 @@2) @@3)
(vec_cond @@0 (plus! @@1 @@3) (plus! @@2 @@3)))
@end smallexample
--
Marc Glisse