]> git.ipfire.org Git - thirdparty/gcc.git/commit
RISC-V: Fix can_find_related_mode_p for VLS types
authorKito Cheng <kito.cheng@sifive.com>
Thu, 14 Aug 2025 13:29:38 +0000 (21:29 +0800)
committerKito Cheng <kito.cheng@sifive.com>
Thu, 11 Sep 2025 07:17:32 +0000 (15:17 +0800)
commit827e8ae4028e701801336cfa8e37ee475c2c2011
tree773753cd90ab95890d88a680e9f8bf433c35b1af
parentffbbeeec04a30426cc36069dfefdddd8146954f1
RISC-V: Fix can_find_related_mode_p for VLS types

can_find_related_mode_p incorrectly handled VLS (Vector Length Specific)
types by using TARGET_MIN_VLEN directly, which is in bits, instead of
converting it to bytes as required.

This patch fixes the issue by dividing TARGET_MIN_VLEN by 8 to convert
from bits to bytes when calculating the number of units for VLS modes.

The fix enables proper vectorization for several test cases:
- zve32f-1.c: Now correctly finds vector mode for SF mode in foo3,
  enabling vectorization of an additional loop.
- zve32f_zvl256b-1.c and zve32x_zvl256b-1.c: Added -mrvv-max-lmul=m2
  option to handle V8SI[2] (vector array mode) requirements during
  vectorizer analysis, which needs V16SI to pass, and V16SI was enabled
  incorrectly before.

Changes since V4:
- Fix testsuite, also triaged why changed.

gcc/ChangeLog:

* config/riscv/riscv-selftests.cc (riscv_run_selftests): Call
run_vectorize_related_mode_selftests.
(test_vectorize_related_mode): New function to test
vectorize_related_mode behavior.
(run_vectorize_related_mode_selftests): New function to run all
vectorize_related_mode tests.
(run_vectorize_related_mode_vla_selftests): New function to test
VLA modes.
(run_vectorize_related_mode_vls_rv64gcv_selftests): New function to
test VLS modes on rv64gcv.
(run_vectorize_related_mode_vls_rv32gc_zve32x_zvl256b_selftests):
New function to test VLS modes on rv32gc_zve32x_zvl256b.
(run_vectorize_related_mode_vls_selftests): New function to run all
VLS mode tests.
* config/riscv/riscv-v.cc (can_find_related_mode_p): Fix VLS type
handling by converting TARGET_MIN_VLEN from bits to bytes.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/zve32f-1.c: Update expected
vectorization count from 2 to 3.
* gcc.target/riscv/rvv/autovec/zve32f_zvl256b-1.c: Add
-mrvv-max-lmul=m2 option.
* gcc.target/riscv/rvv/autovec/zve32x_zvl256b-1.c: Add
-mrvv-max-lmul=m2 option.
gcc/config/riscv/riscv-selftests.cc
gcc/config/riscv/riscv-v.cc
gcc/testsuite/gcc.target/riscv/rvv/autovec/zve32f-1.c
gcc/testsuite/gcc.target/riscv/rvv/autovec/zve32f_zvl256b-1.c
gcc/testsuite/gcc.target/riscv/rvv/autovec/zve32x_zvl256b-1.c