On Wed, 21 May 2025, Icen Zeyada wrote:

> Merge simple_comparison patterns under a single vec_cond_expr for bit_and,
> bit_ior, and bit_xor in the simplify pass.
> 
> Ensure that when both operands of a bit_and, bit_or, or bit_xor are 
> simple_comparison
> results, they reside within the same vec_cond_expr rather than separate ones.
> This prepares the AST so that subsequent transformations (e.g., folding the
> comparisons if possible) can take effect.
> 
> PR tree-optimization/119196
> 
> gcc/ChangeLog:
> 
>       * match.pd: Merge multiple vec_cond_expr in a single one for
>         bit_and, bit_ior and bit_xor.
> 
> Signed-off-by: Icen Zeyada <icen.zeya...@arm.com>
> ---
>  gcc/match.pd | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/gcc/match.pd b/gcc/match.pd
> index 27f662f9714b..611f05ef9f9c 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -6524,6 +6524,15 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>               { build_int_cst (integer_type_node, prec - 1);}))))))
>  #endif
>  
> +
> +(for lop (bit_and bit_ior bit_xor)
> +   (simplify
> +   (lop
> +      (vec_cond @0 integer_minus_onep@2 integer_zerop@3)
> +      (vec_cond @1 @2 @3))
> +      (if (expand_vec_cond_expr_p (type, TREE_TYPE (@0)))
> +   (vec_cond (lop @0 @1) @2 @3))))
> +


We do have some related patterns below

/* Sink binary operation to branches, but only if we can fold it.  */
(for op (tcc_comparison plus minus mult bit_and bit_ior bit_xor
         lshift rshift rdiv trunc_div ceil_div floor_div round_div 
exact_div
         trunc_mod ceil_mod floor_mod round_mod min max)
/* (c ? a : b) op (c ? d : e)  -->  c ? (a op d) : (b op e) */
...

so it probably makes sense to put this new pattern after the above
set?  Can you please add a comment as well?  I do wonder whether
there is enough canonicalization done to ensure integer_minus_onep
is always first and integer_zerop second? (I doubt), similar that
they line up with both vec_conds.

As written the expand_vec_cond_expr_p condition looks redundant -
neither the type of the result nor the type of the predicate
are changing.  So you can drop this here I think.

Thanks,
Richard.

>  (for cnd (cond vec_cond)
>   /* (a != b) ? (a - b) : 0 -> (a - b) */
>   (simplify
> 

-- 
Richard Biener <rguent...@suse.de>
SUSE Software Solutions Germany GmbH,
Frankenstrasse 146, 90461 Nuernberg, Germany;
GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)

Reply via email to