On 9/30/25 2:30 AM, Zhongyao Chen wrote:
Improve RISC-V vector code generation by preferring tail-agnostic (ta) and
mask-agnostic (ma) policies for vector instructions when merge operands
are undefined. This optimization, controlled by a uarch-specific
`prefer_agnostic`
tuning parameter, reduces `vsetvl` instructions and avoids conservative
undisturbed policy selections, addressing PR target/118945.
Changes from v1:
- According to review comments, make it "demand policy" for "agnostic"
instead of changing the fusion rule.
PR target/118945
gcc/ChangeLog:
* config/riscv/riscv.cc (riscv_prefer_agnostic_p): New function.
(riscv_tune_param): Add prefer_agnostic member.
(various tune info structures): Initialize prefer_agnostic.
* config/riscv/riscv-protos.h (riscv_prefer_agnostic_p): Add
prototype.
* config/riscv/riscv-v.cc (get_prefer_tail_policy,
get_prefer_mask_policy): Use riscv_prefer_agnostic_p.
* config/riscv/riscv-vsetvl.cc (vsetvl_info::get_demand_flags):
demand policy for agnostic when prefer_agnostic is true.
gcc/testsuite/ChangeLog:
* gcc.target/riscv/rvv/autovec/pr118945-1.c: New file.
* gcc.target/riscv/rvv/autovec/pr118945-2.c: New file.
---
gcc/config/riscv/riscv-protos.h | 1 +
gcc/config/riscv/riscv-v.cc | 12 +++------
gcc/config/riscv/riscv-vsetvl.cc | 4 +--
gcc/config/riscv/riscv.cc | 22 +++++++++++++++-
.../gcc.target/riscv/rvv/autovec/pr118945-1.c | 13 ++++++++++
.../gcc.target/riscv/rvv/autovec/pr118945-2.c | 26 +++++++++++++++++++
6 files changed, 67 insertions(+), 11 deletions(-)
create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/pr118945-1.c
create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/pr118945-2.c
Overall I like it. I think Robin's comments are spot on, particularly
the need to improve the testcase a little bit. Looking forward to this
getting into the tree relatively soon.
jeff