]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
RISC-V: Fix dynamic LMUL cost model ICE
authorJuzhe-Zhong <juzhe.zhong@rivai.ai>
Thu, 9 Nov 2023 02:39:17 +0000 (10:39 +0800)
committerPan Li <pan2.li@intel.com>
Thu, 9 Nov 2023 03:31:36 +0000 (11:31 +0800)
When trying to use dynamic LMUL to compile benchmark.
Notice there is a bunch ICEs.

This patch fixes those ICEs and append tests.

gcc/ChangeLog:

* config/riscv/riscv-vector-costs.cc (costs::preferred_new_lmul_p): Fix ICE.

gcc/testsuite/ChangeLog:

* gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul-ice-1.c: New test.
* gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul-ice-2.c: New test.
* gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul-ice-3.c: New test.

gcc/config/riscv/riscv-vector-costs.cc
gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul-ice-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul-ice-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul-ice-3.c [new file with mode: 0644]

index af87388a1e4daaf343604f218c01493490d24ca5..8036c9c40d751a3544d7c766765f5d8a10ad2b5b 100644 (file)
@@ -231,7 +231,9 @@ compute_local_live_ranges (
 
                     TODO: We may elide the cases that the unnecessary IMM in
                     the future.  */
-                 if (is_gimple_val (var) && !POINTER_TYPE_P (TREE_TYPE (var)))
+                 if (poly_int_tree_p (var)
+                     || (is_gimple_val (var)
+                         && !POINTER_TYPE_P (TREE_TYPE (var))))
                    {
                      biggest_mode
                        = get_biggest_mode (biggest_mode,
@@ -416,7 +418,8 @@ static void
 update_local_live_ranges (
   vec_info *vinfo,
   hash_map<basic_block, vec<stmt_point>> &program_points_per_bb,
-  hash_map<basic_block, hash_map<tree, pair>> &live_ranges_per_bb)
+  hash_map<basic_block, hash_map<tree, pair>> &live_ranges_per_bb,
+  machine_mode *biggest_mode)
 {
   loop_vec_info loop_vinfo = dyn_cast<loop_vec_info> (vinfo);
   if (!loop_vinfo)
@@ -501,6 +504,8 @@ update_local_live_ranges (
                           : get_store_value (gsi_stmt (si));
              tree sel_type = build_nonstandard_integer_type (
                TYPE_PRECISION (TREE_TYPE (var)), 1);
+             *biggest_mode
+               = get_biggest_mode (*biggest_mode, TYPE_MODE (sel_type));
              tree sel = build_decl (UNKNOWN_LOCATION, VAR_DECL,
                                     get_identifier ("vect_perm"), sel_type);
              pair &live_range = live_ranges->get_or_insert (sel, &existed_p);
@@ -572,7 +577,7 @@ costs::preferred_new_lmul_p (const vector_costs *uncast_other) const
 
   /* Update live ranges according to PHI.  */
   update_local_live_ranges (other->m_vinfo, program_points_per_bb,
-                           live_ranges_per_bb);
+                           live_ranges_per_bb, &biggest_mode);
 
   /* TODO: We calculate the maximum live vars base on current STMTS
      sequence.  We can support live range shrink if it can give us
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul-ice-1.c b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul-ice-1.c
new file mode 100644 (file)
index 0000000..4f019cc
--- /dev/null
@@ -0,0 +1,25 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -O3 -ftree-vectorize --param riscv-autovec-lmul=dynamic" } */
+
+int a, *b[9], c, d, e; 
+
+static int
+fn1 ()
+{
+  for (c = 6; c >= 0; c--)
+    for (d = 0; d < 2; d++)
+      {
+        b[d * 2 + c] = 0;
+        e = a > 1 ? : 0;
+        if (e == 2) 
+          return 0;
+      }
+  return 0;
+}
+
+int
+main ()
+{
+  fn1 ();
+  return 0; 
+}
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul-ice-2.c b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul-ice-2.c
new file mode 100644 (file)
index 0000000..6fc8062
--- /dev/null
@@ -0,0 +1,22 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -Ofast -ftree-vectorize --param riscv-autovec-lmul=dynamic" } */
+
+typedef struct rtx_def *rtx;
+struct replacement {
+    rtx *where;
+    rtx *subreg_loc;
+    int mode;
+};
+static struct replacement replacements[150];
+void move_replacements (rtx *x, rtx *y, int n_replacements)
+{
+  int i;
+  for (i = 0; i < n_replacements; i++)
+    if (replacements[i].subreg_loc == x)
+      replacements[i].subreg_loc = y;
+    else if (replacements[i].where == x) 
+      {
+       replacements[i].where = y;
+       replacements[i].subreg_loc = 0;
+      }
+}
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul-ice-3.c b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul-ice-3.c
new file mode 100644 (file)
index 0000000..c1f698b
--- /dev/null
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -O2 -ftree-vectorize -flto -fno-use-linker-plugin -flto-partition=none --param riscv-autovec-lmul=dynamic" } */
+
+void (*foo[6][6]) (int);
+void bar (hdR)
+    int hdR;
+{ }
+void xxx ()
+{
+    unsigned int i, j;
+    for (i = 0; i < 6; ++i)
+       for (j = 0; j < 6; ++j)
+            foo [i][j] = bar;
+}