> -----Original Message-----
> From: Marc Glisse <marc.gli...@inria.fr>
> Sent: Monday, August 26, 2024 4:46 AM
> To: Richard Biener <richard.guent...@gmail.com>
> Cc: Andrew Pinski (QUIC) <quic_apin...@quicinc.com>; gcc-
> patc...@gcc.gnu.org
> Subject: Re: [PATCH 3/3] Match: Add pattern for `(a ? b : 0) | (a
> ? 0 : c)` into `a ? b : c` [PR103660]
> 
> >> --- 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

Yes we can extend the pattern that is already there for vec_cond too. Though I 
also think we keep the special case for the newly added because then we need to 
extra steps to see that op is no longer there.

Another thing longer term is to remove VEC_COND_EXPR and merge it with 
COND_EXPP. I know this was already mentioned in a different thread but  I don't 
want to duplicate work someone else might be doing; so, I have held back on 
trying to implement that.

Thanks,
Andrew Pinski 

> 
> @smallexample
> (simplify
>    (plus (vec_cond:s @@0 @@1 @@2) @@3)
>    (vec_cond @@0 (plus! @@1 @@3) (plus! @@2 @@3)))
> @end smallexample
> 
> --
> Marc Glisse

Reply via email to