On Fri, May 16, 2025 at 9:49 AM Andrew Pinski <pins...@gmail.com> wrote:
>
> On Fri, May 16, 2025 at 9:32 AM Icen Zeyada <icen.zeya...@arm.com> wrote:
> >
> > Merge simple_comparison patterns under a single vec_cond_expr for bit_and
> > and bit_ior in the simplify pass.
> >
> > Ensure that when both operands of a bit-and or bit-or 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
> > and bit_ior.
> >
> > Signed-off-by: Icen Zeyada <icen.zeya...@arm.com>
> > ---
> >  gcc/match.pd | 10 ++++++++++
> >  1 file changed, 10 insertions(+)
> >
> > diff --git a/gcc/match.pd b/gcc/match.pd
> > index 79485f9678a0..da60d6a22290 100644
> > --- a/gcc/match.pd
> > +++ b/gcc/match.pd
> > @@ -6524,6 +6524,16 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
> >                 { build_int_cst (integer_type_node, prec - 1);}))))))
> >  #endif
> >
> > +(for op1 (simple_comparison)
> > + (for op2 (simple_comparison)
> > +  (for lop (bit_and bit_ior)
> > +    (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))))))
>
> I am trying to understand why you need op1/op2 here since they seem to
> be unused?
> Other than that it might make sense to extend `(a?0:-1) lop (b?0:-1)` too.
> I am not sure but xor might show up; though I don't think it is as
> important as &/| as you handle today.

I missed something in my review.
The transformation is valid for any value of @2 and not just -1.

And you should be able to handle `cond` (scalar) and not just vec_cond
as a follow up if you need.
```
int f1(bool a, bool b, int c, int d)
{
  return (a ? c : 0) & (b ? c : 0);
}
```

>
> Thanks,
> Andrew
>
> > +
> >  (for cnd (cond vec_cond)
> >   /* (a != b) ? (a - b) : 0 -> (a - b) */
> >   (simplify
> > --
> > 2.43.0
> >

Reply via email to