RISC-V: Fix VTYPE fuse rule bug

Message ID 20230823023230.3501614-1-juzhe.zhong@rivai.ai
State Accepted
Headers
Series RISC-V: Fix VTYPE fuse rule bug |

Checks

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

Commit Message

juzhe.zhong@rivai.ai Aug. 23, 2023, 2:32 a.m. UTC
  This bug is exposed after refactor patch.
Separate it and commited.

gcc/ChangeLog:

        * config/riscv/riscv-vsetvl.cc (ge_sew_ratio_unavailable_p): Fix fuse rule bug.
        * config/riscv/riscv-vsetvl.def (DEF_SEW_LMUL_FUSE_RULE): Ditto.

---
 gcc/config/riscv/riscv-vsetvl.cc  | 10 ++++++++--
 gcc/config/riscv/riscv-vsetvl.def |  2 +-
 2 files changed, 9 insertions(+), 3 deletions(-)
  

Patch

diff --git a/gcc/config/riscv/riscv-vsetvl.cc b/gcc/config/riscv/riscv-vsetvl.cc
index 819a3918b3e..ec1aaa4b442 100644
--- a/gcc/config/riscv/riscv-vsetvl.cc
+++ b/gcc/config/riscv/riscv-vsetvl.cc
@@ -1423,8 +1423,14 @@  static bool
 ge_sew_ratio_unavailable_p (const vector_insn_info &info1,
 			    const vector_insn_info &info2)
 {
-  if (!info2.demand_p (DEMAND_LMUL) && info2.demand_p (DEMAND_GE_SEW))
-    return info1.get_sew () < info2.get_sew ();
+  if (!info2.demand_p (DEMAND_LMUL))
+    {
+      if (info2.demand_p (DEMAND_GE_SEW))
+	return info1.get_sew () < info2.get_sew ();
+      /* Demand GE_SEW should be available for non-demand SEW.  */
+      else if (!info2.demand_p (DEMAND_SEW))
+	return false;
+    }
   return true;
 }
 
diff --git a/gcc/config/riscv/riscv-vsetvl.def b/gcc/config/riscv/riscv-vsetvl.def
index 7a73149f1da..7289c01efcf 100644
--- a/gcc/config/riscv/riscv-vsetvl.def
+++ b/gcc/config/riscv/riscv-vsetvl.def
@@ -319,7 +319,7 @@  DEF_SEW_LMUL_FUSE_RULE (/*SEW*/ DEMAND_TRUE, /*LMUL*/ DEMAND_FALSE,
 			/*RATIO*/ DEMAND_TRUE, /*GE_SEW*/ DEMAND_FALSE,
 			/*NEW_DEMAND_SEW*/ true,
 			/*NEW_DEMAND_LMUL*/ false,
-			/*NEW_DEMAND_RATIO*/ false,
+			/*NEW_DEMAND_RATIO*/ true,
 			/*NEW_DEMAND_GE_SEW*/ true, first_sew,
 			vlmul_for_first_sew_second_ratio, second_ratio)
 DEF_SEW_LMUL_FUSE_RULE (/*SEW*/ DEMAND_TRUE, /*LMUL*/ DEMAND_FALSE,