]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
RISC-V: Fix VSETVL PASS fusion bug
authorJuzhe-Zhong <juzhe.zhong@rivai.ai>
Mon, 18 Sep 2023 11:08:25 +0000 (19:08 +0800)
committerPan Li <pan2.li@intel.com>
Mon, 18 Sep 2023 11:11:40 +0000 (19:11 +0800)
There is an obvious fusion bug that is exposed by more VLS patterns support.
After more VLS modes support, it cause following FAILs:
FAIL: gcc.target/riscv/rvv/autovec/reduc/reduc_run-2.c execution test
FAIL: gcc.target/riscv/rvv/autovec/reduc/reduc_run-2.c execution test
FAIL: gcc.target/riscv/rvv/autovec/reduc/reduc_run-2.c execution test
FAIL: gcc.target/riscv/rvv/autovec/reduc/reduc_run-2.c execution test

Demand 1: SEW = 64, LMUL = 1, RATIO = 64, demand SEW, demand GE_SEW.
Demand 2: SEW = 64, LMUL = 2, RATIO = 32, demand SEW, demand GE_SEW, demand RATIO.

Before this patch:
merge demand: SEW = 64, LMUL = 1, RATIO = 32, demand SEW, demand LMUL, demand GE_SEW.
It's obvious incorrect of merge LMUL which should be new LMUL = (demand 2 RATIO * greatest SEW) = M2

gcc/ChangeLog:

* config/riscv/riscv-vsetvl.cc (vlmul_for_greatest_sew_second_ratio): New function.
* config/riscv/riscv-vsetvl.def (DEF_SEW_LMUL_FUSE_RULE): Fix bug.

gcc/config/riscv/riscv-vsetvl.cc
gcc/config/riscv/riscv-vsetvl.def

index 5f031c18df5149aa26ec0b0e6624a51eb53c23b9..df980b6770e47849e48843a3fff3bcfce0f1999f 100644 (file)
@@ -1308,6 +1308,14 @@ vlmul_for_first_sew_second_ratio (const vector_insn_info &info1,
   return calculate_vlmul (info1.get_sew (), info2.get_ratio ());
 }
 
+static vlmul_type
+vlmul_for_greatest_sew_second_ratio (const vector_insn_info &info1,
+                                    const vector_insn_info &info2)
+{
+  return calculate_vlmul (MAX (info1.get_sew (), info2.get_sew ()),
+                         info2.get_ratio ());
+}
+
 static unsigned
 ratio_for_second_sew_first_vlmul (const vector_insn_info &info1,
                                  const vector_insn_info &info2)
index 7289c01efcfe4d9dcd718a6da072053f3564eb78..709cc4ee0df8b8d21f0c5efad62ea6baa7dcdece 100644 (file)
@@ -329,8 +329,8 @@ DEF_SEW_LMUL_FUSE_RULE (/*SEW*/ DEMAND_TRUE, /*LMUL*/ DEMAND_FALSE,
                        /*NEW_DEMAND_SEW*/ true,
                        /*NEW_DEMAND_LMUL*/ false,
                        /*NEW_DEMAND_RATIO*/ true,
-                       /*NEW_DEMAND_GE_SEW*/ true, greatest_sew, first_vlmul,
-                       second_ratio)
+                       /*NEW_DEMAND_GE_SEW*/ true, greatest_sew,
+                       vlmul_for_greatest_sew_second_ratio, second_ratio)
 DEF_SEW_LMUL_FUSE_RULE (/*SEW*/ DEMAND_TRUE, /*LMUL*/ DEMAND_FALSE,
                        /*RATIO*/ DEMAND_ANY, /*GE_SEW*/ DEMAND_TRUE,
                        /*SEW*/ DEMAND_FALSE, /*LMUL*/ DEMAND_TRUE,