Message ID | 20240307083219.444644-1-demin.han@starfivetech.com |
---|---|
State | New |
Headers | show |
Series | [v2] RISC-V: Fix ICE in riscv vector costs | expand |
LGTM except a nit comment: PR 114264 -> PR target/114264 No need to send V3, just commit it with this change. juzhe.zhong@rivai.ai From: demin.han Date: 2024-03-07 16:32 To: gcc-patches CC: juzhe.zhong; kito.cheng; pan2.li; jeffreyalaw Subject: [PATCH v2] RISC-V: Fix ICE in riscv vector costs The following code can result in ICE: -march=rv64gcv --param riscv-autovec-lmul=dynamic -O3 char *jpeg_difference7_input_buf; void jpeg_difference7(int *diff_buf) { unsigned width; int samp, Rb; while (--width) { Rb = samp = *jpeg_difference7_input_buf; *diff_buf++ = -(int)(samp + (long)Rb >> 1); } } One biggest_mode update missed in one branch and trigger assertion fail. gcc_assert (biggest_size >= mode_size); Tested On RV64 and no regression. PR 114264 gcc/ChangeLog: * config/riscv/riscv-vector-costs.cc: Fix ICE gcc/testsuite/ChangeLog: * gcc.dg/vect/costmodel/riscv/rvv/pr114264.c: New test. Signed-off-by: demin.han <demin.han@starfivetech.com> --- gcc/config/riscv/riscv-vector-costs.cc | 2 ++ .../gcc.dg/vect/costmodel/riscv/rvv/pr114264.c | 15 +++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr114264.c diff --git a/gcc/config/riscv/riscv-vector-costs.cc b/gcc/config/riscv/riscv-vector-costs.cc index 7c9840df4e9..f13a1296b31 100644 --- a/gcc/config/riscv/riscv-vector-costs.cc +++ b/gcc/config/riscv/riscv-vector-costs.cc @@ -413,6 +413,8 @@ compute_local_live_ranges ( auto *r = get_live_range (live_ranges, arg); gcc_assert (r); (*r).second = MAX (point, (*r).second); + biggest_mode = get_biggest_mode ( + biggest_mode, TYPE_MODE (TREE_TYPE (arg))); } } else diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr114264.c b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr114264.c new file mode 100644 index 00000000000..7853f292af7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr114264.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gcv -mabi=lp64d -O3 -ftree-vectorize --param=riscv-autovec-lmul=dynamic" } */ + +char *jpeg_difference7_input_buf; +void +jpeg_difference7 (int *diff_buf) +{ + unsigned width; + int samp, Rb; + while (--width) + { + Rb = samp = *jpeg_difference7_input_buf; + *diff_buf++ = -(int) (samp + (long) Rb >> 1); + } +}
diff --git a/gcc/config/riscv/riscv-vector-costs.cc b/gcc/config/riscv/riscv-vector-costs.cc index 7c9840df4e9..f13a1296b31 100644 --- a/gcc/config/riscv/riscv-vector-costs.cc +++ b/gcc/config/riscv/riscv-vector-costs.cc @@ -413,6 +413,8 @@ compute_local_live_ranges ( auto *r = get_live_range (live_ranges, arg); gcc_assert (r); (*r).second = MAX (point, (*r).second); + biggest_mode = get_biggest_mode ( + biggest_mode, TYPE_MODE (TREE_TYPE (arg))); } } else diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr114264.c b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr114264.c new file mode 100644 index 00000000000..7853f292af7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr114264.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gcv -mabi=lp64d -O3 -ftree-vectorize --param=riscv-autovec-lmul=dynamic" } */ + +char *jpeg_difference7_input_buf; +void +jpeg_difference7 (int *diff_buf) +{ + unsigned width; + int samp, Rb; + while (--width) + { + Rb = samp = *jpeg_difference7_input_buf; + *diff_buf++ = -(int) (samp + (long) Rb >> 1); + } +}
The following code can result in ICE: -march=rv64gcv --param riscv-autovec-lmul=dynamic -O3 char *jpeg_difference7_input_buf; void jpeg_difference7(int *diff_buf) { unsigned width; int samp, Rb; while (--width) { Rb = samp = *jpeg_difference7_input_buf; *diff_buf++ = -(int)(samp + (long)Rb >> 1); } } One biggest_mode update missed in one branch and trigger assertion fail. gcc_assert (biggest_size >= mode_size); Tested On RV64 and no regression. PR 114264 gcc/ChangeLog: * config/riscv/riscv-vector-costs.cc: Fix ICE gcc/testsuite/ChangeLog: * gcc.dg/vect/costmodel/riscv/rvv/pr114264.c: New test. Signed-off-by: demin.han <demin.han@starfivetech.com> --- gcc/config/riscv/riscv-vector-costs.cc | 2 ++ .../gcc.dg/vect/costmodel/riscv/rvv/pr114264.c | 15 +++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr114264.c