[llvm] [RISCV] Add compress patterns for qc.extu and qc.mvltui (PR #140682)

via llvm-commits llvm-commits at lists.llvm.org
Fri May 23 00:00:51 PDT 2025


https://github.com/hchandel updated https://github.com/llvm/llvm-project/pull/140682

>From 10039cfee5c0b21c4ec47576712c58af13544f7a Mon Sep 17 00:00:00 2001
From: Harsh Chandel <quic_hchandel at quicinc.com>
Date: Tue, 20 May 2025 11:12:02 +0530
Subject: [PATCH 1/2] [RISCV] Add compress patterns for qc.extu and qc.mvltui

Change-Id: I6d28c27aaf512455ffd121ea4abf629e3942f379
---
 llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td | 4 ++++
 llvm/test/MC/RISCV/xqcibm-valid.s           | 5 +++++
 llvm/test/MC/RISCV/xqcicm-valid.s           | 5 +++++
 3 files changed, 14 insertions(+)

diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td b/llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td
index 04db0fd07f109..1feebed0613b8 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td
@@ -1489,6 +1489,8 @@ def : CompressPat<(QC_E_SW GPR:$rs2, GPRMem:$rs1, simm12:$imm12),
 let Predicates = [HasVendorXqcicm, IsRV32] in {
 def : CompressPat<(QC_MVEQI GPRC:$rd, GPRC:$rd, 0, GPRC:$rs1),
                   (QC_C_MVEQZ GPRC:$rd, GPRC:$rs1)>;
+def : CompressPat<(QC_MVLTUI GPRC:$rd, GPRC:$rd, 1, GPRC:$rs1),
+                  (QC_C_MVEQZ GPRC:$rd, GPRC:$rs1)>;
 }
 
 let Predicates = [HasVendorXqcibm, IsRV32] in {
@@ -1501,6 +1503,8 @@ def : CompressPat<(BSETI GPRC:$rs1, GPRC:$rs1, uimmlog2xlennonzero:$shamt),
                   (QC_C_BSETI GPRC:$rs1, uimmlog2xlennonzero:$shamt)>;
 def : CompressPat<(BEXTI GPRC:$rs1, GPRC:$rs1, uimmlog2xlennonzero:$shamt),
                   (QC_C_BEXTI GPRC:$rs1, uimmlog2xlennonzero:$shamt)>;
+def : CompressPat<(QC_EXTU GPRC:$rd, GPRC:$rd, 1, uimmlog2xlennonzero:$shamt),
+                  (QC_C_BEXTI GPRC:$rd, uimmlog2xlennonzero:$shamt)>;
 } // Predicates = [HasVendorXqcibm, HasStdExtZbs, IsRV32]
 
 let isCompressOnly = true, Predicates = [HasVendorXqcilb, IsRV32] in {
diff --git a/llvm/test/MC/RISCV/xqcibm-valid.s b/llvm/test/MC/RISCV/xqcibm-valid.s
index 4bbf2bc2b01d0..090b72834364b 100644
--- a/llvm/test/MC/RISCV/xqcibm-valid.s
+++ b/llvm/test/MC/RISCV/xqcibm-valid.s
@@ -133,6 +133,11 @@ qc.c.extu x15, 32
 # CHECK-ENC: encoding: [0xaa,0x15]
 qc.extu x11, x11, 11, 0
 
+# CHECK-NOALIAS: qc.c.bexti  a1, 5
+# CHECK-ALIAS: bexti   a1, a1, 5
+# CHECK-ENC: encoding: [0x95,0x91]
+qc.extu x11, x11, 1, 5
+
 # CHECK-NOALIAS: qc.c.bexti  s1, 8
 # CHECK-ALIAS: bexti s1, s1, 8
 # CHECK-ENC-ZBS: encoding: [0xa1,0x90]
diff --git a/llvm/test/MC/RISCV/xqcicm-valid.s b/llvm/test/MC/RISCV/xqcicm-valid.s
index f480a9e5fb007..0eb253ff5e434 100644
--- a/llvm/test/MC/RISCV/xqcicm-valid.s
+++ b/llvm/test/MC/RISCV/xqcicm-valid.s
@@ -130,3 +130,8 @@ qc.mvgeui x9, x10, 31, x12
 # CHECK-ENC: encoding: [0x06,0xae]
 qc.mveqi x9, x9, 0, x12
 
+# CHECK-NOALIAS: qc.c.mveqz s1, a2
+# CHECK-ALIAS: qc.mveqi s1, s1, 0, a2
+# CHECK-ENC: encoding: [0x06,0xae]
+qc.mvltui x9, x9, 1, x12
+

>From 1c95e65bf929acdabe515fde4ba9d940fb000d8a Mon Sep 17 00:00:00 2001
From: Harsh Chandel <quic_hchandel at quicinc.com>
Date: Thu, 22 May 2025 13:16:23 +0530
Subject: [PATCH 2/2] fixup! Address comments regarding isCompressOnly

Change-Id: Ic093bf54ce1c726132e0ca10a08d99468a2e7487
---
 llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td b/llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td
index 1feebed0613b8..46c71f958ba54 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td
@@ -1489,6 +1489,7 @@ def : CompressPat<(QC_E_SW GPR:$rs2, GPRMem:$rs1, simm12:$imm12),
 let Predicates = [HasVendorXqcicm, IsRV32] in {
 def : CompressPat<(QC_MVEQI GPRC:$rd, GPRC:$rd, 0, GPRC:$rs1),
                   (QC_C_MVEQZ GPRC:$rd, GPRC:$rs1)>;
+let isCompressOnly = true in
 def : CompressPat<(QC_MVLTUI GPRC:$rd, GPRC:$rd, 1, GPRC:$rs1),
                   (QC_C_MVEQZ GPRC:$rd, GPRC:$rs1)>;
 }
@@ -1503,6 +1504,7 @@ def : CompressPat<(BSETI GPRC:$rs1, GPRC:$rs1, uimmlog2xlennonzero:$shamt),
                   (QC_C_BSETI GPRC:$rs1, uimmlog2xlennonzero:$shamt)>;
 def : CompressPat<(BEXTI GPRC:$rs1, GPRC:$rs1, uimmlog2xlennonzero:$shamt),
                   (QC_C_BEXTI GPRC:$rs1, uimmlog2xlennonzero:$shamt)>;
+let isCompressOnly = true in
 def : CompressPat<(QC_EXTU GPRC:$rd, GPRC:$rd, 1, uimmlog2xlennonzero:$shamt),
                   (QC_C_BEXTI GPRC:$rd, uimmlog2xlennonzero:$shamt)>;
 } // Predicates = [HasVendorXqcibm, HasStdExtZbs, IsRV32]



More information about the llvm-commits mailing list