On Thu, 18 Jun 2026, Richard Sandiford wrote: > Richard Biener <[email protected]> writes: > > The following fixes an oversight in the guards covering VEC_PERM_EXPR > > folding. When the existing permutes are not handled by the CPU then > > we know we have not yet applied vector lowering. But only when we > > also consider the variable permute fallback. > > > > This doesn't fix the PR because !can_vec_perm_p does not tell us > > the truth since both vector lowering and RTL expansion will eventually > > consider vec_shl and vec_shr. I'd like to retire those fallbacks > > of vec_perm_const, we instead should require for targets to > > syntesize a whole vector shift themselves. > > > > The alternative would be to (optionally?) pass in op0 and op1 > > to can_vec_perm_const_p. > > Perhaps we'd need to do that anyway, even if we get rid of the optabs. > I don't see otherwise how the target would distinguish a VEC_PERM_EXPR > involving zero with a VEC_PERM_EXPR involving some other constant. > Also, shift_amt_for_vec_perm_mask seems to be forgiving about the > index used into the second vector, which is only possible if you > know that the second vector is uniform.
Hmm, true. I'll rework in that direction. Ricahrd. > Thanks, > Richard > > > > > > Thoughts? > > > > Thanks, > > Richard. > > > > PR middle-end/125875 > > * match.pd: When checking for !can_vec_perm_const_p also > > allow variable permutes. > > --- > > gcc/match.pd | 18 +++++++++--------- > > 1 file changed, 9 insertions(+), 9 deletions(-) > > > > diff --git a/gcc/match.pd b/gcc/match.pd > > index 475939a0b63..d8073a90956 100644 > > --- a/gcc/match.pd > > +++ b/gcc/match.pd > > @@ -11688,9 +11688,9 @@ and, > > number of VEC_PERM_EXPRs that can't be handled. */ > > if (can_vec_perm_const_p (result_mode, op_mode, sel2, false) > > || (single_use (@0) > > - ? (!can_vec_perm_const_p (result_mode, op_mode, sel0, false) > > - || !can_vec_perm_const_p (result_mode, op_mode, sel1, false)) > > - : !can_vec_perm_const_p (result_mode, op_mode, sel1, false))) > > + ? (!can_vec_perm_const_p (result_mode, op_mode, sel0, true) > > + || !can_vec_perm_const_p (result_mode, op_mode, sel1, true)) > > + : !can_vec_perm_const_p (result_mode, op_mode, sel1, true))) > > op0 = vec_perm_indices_to_tree (TREE_TYPE (@5), sel2); > > } > > (if (op0) > > @@ -11755,9 +11755,9 @@ and, > > number of VEC_PERM_EXPRs that can't be handled. */ > > if (can_vec_perm_const_p (result_mode, op_mode, sel2, false) > > || (single_use (@0) > > - ? (!can_vec_perm_const_p (result_mode, op_mode, sel0, false) > > - || !can_vec_perm_const_p (result_mode, op_mode, sel1, > > false)) > > - : !can_vec_perm_const_p (result_mode, op_mode, sel1, false))) > > + ? (!can_vec_perm_const_p (result_mode, op_mode, sel0, true) > > + || !can_vec_perm_const_p (result_mode, op_mode, sel1, true)) > > + : !can_vec_perm_const_p (result_mode, op_mode, sel1, true))) > > op0 = vec_perm_indices_to_tree (TREE_TYPE (@4), sel2); > > } > > (if (op0) > > @@ -11819,9 +11819,9 @@ and, > > number of VEC_PERM_EXPRs that can't be handled. */ > > if (can_vec_perm_const_p (result_mode, op_mode, sel2, false) > > || (single_use (@0) > > - ? (!can_vec_perm_const_p (result_mode, op_mode, sel0, false) > > - || !can_vec_perm_const_p (result_mode, op_mode, sel1, > > false)) > > - : !can_vec_perm_const_p (result_mode, op_mode, sel1, false))) > > + ? (!can_vec_perm_const_p (result_mode, op_mode, sel0, true) > > + || !can_vec_perm_const_p (result_mode, op_mode, sel1, true)) > > + : !can_vec_perm_const_p (result_mode, op_mode, sel1, true))) > > op0 = vec_perm_indices_to_tree (TREE_TYPE (@4), sel2); > > } > > (if (op0) > -- Richard Biener <[email protected]> SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, Germany; GF: Jochen Jaser, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)
