On Tue, Sep 02, 2025 at 03:28:46PM +0200, Richard Biener wrote:
> On Tue, 2 Sep 2025, Jakub Jelinek wrote:
>
> > On Tue, Sep 02, 2025 at 11:34:59AM +0200, Richard Biener wrote:
> > >
> > > Oops, now also to the list.
> >
> > If so, it needs to punt on anything that uses something more than once.
> > So, alg_add_factor and alg_sub_factor are always bad (so return NULL),
> > because they do use accumulator both in the PLUS/MINUS and LSHIFT.
> > alg_add_t2_m/alg_sub_t2_m/alg_shift if synth_shift_p
> > and alg.log[i], all in addition to what it has been doing before.
>
> Like the following?
Yes. LGTM.
> PR tree-optimization/121753
> * tree-vect-patterns.cc (vect_synth_mult_by_constant): Properly
> bail when synth_shift_p and an alg_shift use. Handle other
> problematic cases.
> ---
> gcc/tree-vect-patterns.cc | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc
> index 64a49cccc24..d0bf2f9e799 100644
> --- a/gcc/tree-vect-patterns.cc
> +++ b/gcc/tree-vect-patterns.cc
> @@ -4329,7 +4329,14 @@ vect_synth_mult_by_constant (vec_info *vinfo, tree op,
> tree val,
> case alg_add_t2_m:
> case alg_sub_t2_m:
> op_uses++;
> + /* Fallthru. */
> + case alg_shift:
> + if (synth_shift_p && alg.log[i])
> + return NULL;
> break;
> + case alg_add_factor:
> + case alg_sub_factor:
> + return NULL;
> default:
> break;
> }
Jakub