RISC-V: Remove poly selftest when --preference=fixed-vlmax

Message ID 20231211051919.3236502-1-juzhe.zhong@rivai.ai
State Accepted
Headers
Series RISC-V: Remove poly selftest when --preference=fixed-vlmax |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

juzhe.zhong@rivai.ai Dec. 11, 2023, 5:19 a.m. UTC
  This patch fixes multiple ICEs in full coverage testing:

cc1: internal compiler error: in riscv_legitimize_poly_move, at config/riscv/riscv.cc:2456^M
0x1fd8d78 riscv_legitimize_poly_move^M
        ../../../../gcc/gcc/config/riscv/riscv.cc:2456^M
0x1fd9518 riscv_legitimize_move(machine_mode, rtx_def*, rtx_def*)^M
        ../../../../gcc/gcc/config/riscv/riscv.cc:2583^M
0x2936820 gen_movdi(rtx_def*, rtx_def*)^M
        ../../../../gcc/gcc/config/riscv/riscv.md:2099^M
0x11a0f28 rtx_insn* insn_gen_fn::operator()<rtx_def*, rtx_def*>(rtx_def*, rtx_def*) const^M
        ../../../../gcc/gcc/recog.h:431^M
0x13cf2f9 emit_move_insn_1(rtx_def*, rtx_def*)^M
        ../../../../gcc/gcc/expr.cc:4553^M
0x13d010c emit_move_insn(rtx_def*, rtx_def*)^M
        ../../../../gcc/gcc/expr.cc:4723^M
0x216f5e0 run_poly_int_selftest^M
        ../../../../gcc/gcc/config/riscv/riscv-selftests.cc:185^M
0x21701e6 run_poly_int_selftests^M
        ../../../../gcc/gcc/config/riscv/riscv-selftests.cc:226^M
0x2172109 selftest::riscv_run_selftests()^M
        ../../../../gcc/gcc/config/riscv/riscv-selftests.cc:371^M
0x3b8067b selftest::run_tests()^M
        ../../../../gcc/gcc/selftest-run-tests.cc:112^M
0x1ad90ee toplev::run_self_tests()^M
        ../../../../gcc/gcc/toplev.cc:2209^M

Running target riscv-sim/-march=rv64gcv/-mabi=lp64d/-mcmodel=medlow/--param=riscv-autovec-lmul=m1/--param=riscv-autovec-preference=fixed-vlmax

The rootcause is that we are testing POLY value computation during FIXED-VLMAX and ICE in this code:

  if (BYTES_PER_RISCV_VECTOR.is_constant ())
    {
      gcc_assert (value.is_constant ());                           ----->  assert failed.
      riscv_emit_move (dest, GEN_INT (value.to_constant ()));
      return;
    }

For example, a poly value [15, 16] is computed by csrr vlen + multiple scalar integer instructions.

However, such compile-time unknown value need to be computed when it is scalable vector, that is !BYTES_PER_RISCV_VECTOR.is_constant (),
since csrr vlenb = [16, 0] when -march=rv64gcv --param=riscv-autovec-preference=fixed-vlmax and we have no chance to compute compile-time POLY value.

Also, we never reach the situation to compute a compile time unknown value when it is FIXED-VLMAX vector. So disable POLY selftest for FIXED-VLMAX.


gcc/ChangeLog:

	* config/riscv/riscv-selftests.cc (riscv_run_selftests): Remove poly self test when FIXED-VLMAX.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/base/poly-selftest-1.c: New test.

---
 gcc/config/riscv/riscv-selftests.cc                | 14 +++++++++++++-
 .../gcc.target/riscv/rvv/base/poly-selftest-1.c    | 12 ++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/poly-selftest-1.c
  

Comments

Kito Cheng Dec. 11, 2023, 5:30 a.m. UTC | #1
LGTM

On Mon, Dec 11, 2023 at 1:19 PM Juzhe-Zhong <juzhe.zhong@rivai.ai> wrote:
>
> This patch fixes multiple ICEs in full coverage testing:
>
> cc1: internal compiler error: in riscv_legitimize_poly_move, at config/riscv/riscv.cc:2456^M
> 0x1fd8d78 riscv_legitimize_poly_move^M
>         ../../../../gcc/gcc/config/riscv/riscv.cc:2456^M
> 0x1fd9518 riscv_legitimize_move(machine_mode, rtx_def*, rtx_def*)^M
>         ../../../../gcc/gcc/config/riscv/riscv.cc:2583^M
> 0x2936820 gen_movdi(rtx_def*, rtx_def*)^M
>         ../../../../gcc/gcc/config/riscv/riscv.md:2099^M
> 0x11a0f28 rtx_insn* insn_gen_fn::operator()<rtx_def*, rtx_def*>(rtx_def*, rtx_def*) const^M
>         ../../../../gcc/gcc/recog.h:431^M
> 0x13cf2f9 emit_move_insn_1(rtx_def*, rtx_def*)^M
>         ../../../../gcc/gcc/expr.cc:4553^M
> 0x13d010c emit_move_insn(rtx_def*, rtx_def*)^M
>         ../../../../gcc/gcc/expr.cc:4723^M
> 0x216f5e0 run_poly_int_selftest^M
>         ../../../../gcc/gcc/config/riscv/riscv-selftests.cc:185^M
> 0x21701e6 run_poly_int_selftests^M
>         ../../../../gcc/gcc/config/riscv/riscv-selftests.cc:226^M
> 0x2172109 selftest::riscv_run_selftests()^M
>         ../../../../gcc/gcc/config/riscv/riscv-selftests.cc:371^M
> 0x3b8067b selftest::run_tests()^M
>         ../../../../gcc/gcc/selftest-run-tests.cc:112^M
> 0x1ad90ee toplev::run_self_tests()^M
>         ../../../../gcc/gcc/toplev.cc:2209^M
>
> Running target riscv-sim/-march=rv64gcv/-mabi=lp64d/-mcmodel=medlow/--param=riscv-autovec-lmul=m1/--param=riscv-autovec-preference=fixed-vlmax
>
> The rootcause is that we are testing POLY value computation during FIXED-VLMAX and ICE in this code:
>
>   if (BYTES_PER_RISCV_VECTOR.is_constant ())
>     {
>       gcc_assert (value.is_constant ());                           ----->  assert failed.
>       riscv_emit_move (dest, GEN_INT (value.to_constant ()));
>       return;
>     }
>
> For example, a poly value [15, 16] is computed by csrr vlen + multiple scalar integer instructions.
>
> However, such compile-time unknown value need to be computed when it is scalable vector, that is !BYTES_PER_RISCV_VECTOR.is_constant (),
> since csrr vlenb = [16, 0] when -march=rv64gcv --param=riscv-autovec-preference=fixed-vlmax and we have no chance to compute compile-time POLY value.
>
> Also, we never reach the situation to compute a compile time unknown value when it is FIXED-VLMAX vector. So disable POLY selftest for FIXED-VLMAX.
>
>
> gcc/ChangeLog:
>
>         * config/riscv/riscv-selftests.cc (riscv_run_selftests): Remove poly self test when FIXED-VLMAX.
>
> gcc/testsuite/ChangeLog:
>
>         * gcc.target/riscv/rvv/base/poly-selftest-1.c: New test.
>
> ---
>  gcc/config/riscv/riscv-selftests.cc                | 14 +++++++++++++-
>  .../gcc.target/riscv/rvv/base/poly-selftest-1.c    | 12 ++++++++++++
>  2 files changed, 25 insertions(+), 1 deletion(-)
>  create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/poly-selftest-1.c
>
> diff --git a/gcc/config/riscv/riscv-selftests.cc b/gcc/config/riscv/riscv-selftests.cc
> index 0ac17fb70a1..289916b999e 100644
> --- a/gcc/config/riscv/riscv-selftests.cc
> +++ b/gcc/config/riscv/riscv-selftests.cc
> @@ -368,7 +368,19 @@ namespace selftest {
>  void
>  riscv_run_selftests (void)
>  {
> -  run_poly_int_selftests ();
> +  if (!BYTES_PER_RISCV_VECTOR.is_constant ())
> +    /* We can know POLY value = [4, 4] when BYTES_PER_RISCV_VECTOR
> +       is !is_constant () since we can use csrr vlenb and scalar shift
> +       instruction to compute such POLY value and store it into a scalar
> +       register.  Wheras, we can't know [4, 4] on it is specified as
> +       FIXED-VLMAX since BYTES_PER_RISCV_VECTOR = 16 for -march=rv64gcv
> +       and csrr vlenb is 16 which is totally unrelated to any
> +       compile-time unknown POLY value.
> +
> +       Since we never need to compute a compile-time unknown POLY value
> +       when --param=riscv-autovec-preference=fixed-vlmax, disable poly
> +       selftests in such situation.  */
> +    run_poly_int_selftests ();
>    run_const_vector_selftests ();
>    run_broadcast_selftests ();
>  }
> diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/poly-selftest-1.c b/gcc/testsuite/gcc.target/riscv/rvv/base/poly-selftest-1.c
> new file mode 100644
> index 00000000000..0f128ac26b2
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/poly-selftest-1.c
> @@ -0,0 +1,12 @@
> +/* { dg-do compile } */
> +/* { dg-options "-march=rv64gcv -mabi=lp64d -O0 -fself-test=$srcdir/selftests --param=riscv-autovec-preference=fixed-vlmax -S" } */
> +
> +/* Verify that -fself-test does not fail on a non empty source.  */
> +
> +int i;                                                                          void bar();                                                                     void foo()
> +{
> +  while (i--)
> +    bar();
> +}
> +
> +/* { dg-regexp {^-fself-test: [0-9]+ pass\(es\) in [.0-9]+ seconds$|.*: note: self-tests are not enabled in this build$} } */
> --
> 2.36.3
>
  

Patch

diff --git a/gcc/config/riscv/riscv-selftests.cc b/gcc/config/riscv/riscv-selftests.cc
index 0ac17fb70a1..289916b999e 100644
--- a/gcc/config/riscv/riscv-selftests.cc
+++ b/gcc/config/riscv/riscv-selftests.cc
@@ -368,7 +368,19 @@  namespace selftest {
 void
 riscv_run_selftests (void)
 {
-  run_poly_int_selftests ();
+  if (!BYTES_PER_RISCV_VECTOR.is_constant ())
+    /* We can know POLY value = [4, 4] when BYTES_PER_RISCV_VECTOR
+       is !is_constant () since we can use csrr vlenb and scalar shift
+       instruction to compute such POLY value and store it into a scalar
+       register.  Wheras, we can't know [4, 4] on it is specified as
+       FIXED-VLMAX since BYTES_PER_RISCV_VECTOR = 16 for -march=rv64gcv
+       and csrr vlenb is 16 which is totally unrelated to any
+       compile-time unknown POLY value.
+
+       Since we never need to compute a compile-time unknown POLY value
+       when --param=riscv-autovec-preference=fixed-vlmax, disable poly
+       selftests in such situation.  */
+    run_poly_int_selftests ();
   run_const_vector_selftests ();
   run_broadcast_selftests ();
 }
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/poly-selftest-1.c b/gcc/testsuite/gcc.target/riscv/rvv/base/poly-selftest-1.c
new file mode 100644
index 00000000000..0f128ac26b2
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/base/poly-selftest-1.c
@@ -0,0 +1,12 @@ 
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gcv -mabi=lp64d -O0 -fself-test=$srcdir/selftests --param=riscv-autovec-preference=fixed-vlmax -S" } */
+
+/* Verify that -fself-test does not fail on a non empty source.  */
+
+int i;                                                                          void bar();                                                                     void foo()
+{
+  while (i--)
+    bar();
+}
+
+/* { dg-regexp {^-fself-test: [0-9]+ pass\(es\) in [.0-9]+ seconds$|.*: note: self-tests are not enabled in this build$} } */