On Fri, Oct 30, 2026 at 4:13 PM Robin Dapp <[email protected]> wrote: > > From: Robin Dapp <[email protected]> > > As announced a while ago, I have been working on representing vec-vec > extract differently for riscv. We have a large number of VLS vector > modes and vec_extract is a convert optab with input and output mode. > Specifying all possible combinations exceeds the mode representation so > I experimented with many approaches but none of them was satisfactory. > I always landed at a new hook or not querying the target at all. > Luckily, permute handling was already mostly set up for mismatched > input/output sizes and Igor recently upstreamed a patch to fix the > missing bits. > > Building on top of this, patch 1 adds a helper vec_extract_perm_p which > just takes source mode, target (subvec) mode, and an index and returns > whether the target supports the respective permute. The helper is used > in expmed for expanding a BIT_FIELD_REF. > extract_vector_from_vector_perm gets called as fallback in the recently > added extract_vector_from_vector. > > In patch 2, the same helper is wired up with can_vec_extract. I grabbed > the opportunity and replaced the remaining uses of convert_optab_handler > (vec_extract_optab) by can_vec_extract. > > Patch 3 adds the riscv specific implementation shuffle_extract_patterns > that eventually just emits a slidedown. At the same time, we can get > rid of a number of helpers and iterators. riscv is the only user of the > fallback. > > In the future I'm planning to do the same exercise for the opposite > direction: vec_set and vec_init. I'm not fully decided, how, yet > because vec-vec vec_set's (which is only vaguely documented but still > used) and vec_init's duties overlap to some extent. Also vec_set must > keep the unmentioned indices. But the principle is similar and we > should be able to at least fall back to a perm vec_set. > What I noticed while working on the code is that while we support > poly_ints in BIT_FIELD_REF in principle, not all functions are prepared > for it and for certain cases, permutes in particular seem a good > match for those. > > The series was bootstrapped and regtested on x86, power10, and aarch64. > Regtested on riscv64.
The series (skipped the riscv part) looks good to me but leave Richard S. time to comment due to the VLA vec-perm stuff which. Thanks, Richard. > Robin Dapp (3): > expmed: Extract subvectors via vec_perm_const. > vect: Use can_vec_extract. > RISC-V: Extract subvectors via vec_perm_const. > > gcc/config/riscv/autovec.md | 63 ------ > gcc/config/riscv/riscv-v.cc | 143 +++++--------- > gcc/config/riscv/vector-iterators.md | 184 ------------------ > gcc/expmed.cc | 105 +++++++++- > gcc/expmed.h | 3 + > gcc/optabs-query.cc | 30 +-- > gcc/optabs-query.h | 2 +- > .../riscv/rvv/autovec/subreg-extract.c | 6 +- > gcc/tree-vect-loop.cc | 17 +- > gcc/tree-vect-stmts.cc | 8 +- > 10 files changed, 191 insertions(+), 370 deletions(-) > > -- > 2.56.0 >
