]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
RISC-V: Remove poly selftest when --preference=fixed-vlmax
authorJuzhe-Zhong <juzhe.zhong@rivai.ai>
Mon, 11 Dec 2023 03:00:14 +0000 (11:00 +0800)
committerLehua Ding <lehua.ding@rivai.ai>
Mon, 11 Dec 2023 06:07:34 +0000 (14:07 +0800)
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
gcc/testsuite/gcc.target/riscv/rvv/base/poly-selftest-1.c [new file with mode: 0644]

index 0ac17fb70a1ff89bd866dd56dae8d3926a430f1f..289916b999e224d2669fa834f56e69510f1db1a0 100644 (file)
@@ -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 (file)
index 0000000..0f128ac
--- /dev/null
@@ -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$} } */