[llvm] 11b5e29 - [RISCV] Add compress patterns for QC_E_J/JAL and QC_E_LI (#141561)

via llvm-commits llvm-commits at lists.llvm.org
Tue May 27 21:59:38 PDT 2025


Author: Sudharsan Veeravalli
Date: 2025-05-28T10:29:36+05:30
New Revision: 11b5e29cb4b4559f6e64302c089d9048f3c2624d

URL: https://github.com/llvm/llvm-project/commit/11b5e29cb4b4559f6e64302c089d9048f3c2624d
DIFF: https://github.com/llvm/llvm-project/commit/11b5e29cb4b4559f6e64302c089d9048f3c2624d.diff

LOG: [RISCV] Add compress patterns for QC_E_J/JAL and QC_E_LI (#141561)

Added: 
    

Modified: 
    llvm/lib/Target/RISCV/RISCVInstrInfo.td
    llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td
    llvm/test/MC/RISCV/xqcilb-valid.s
    llvm/test/MC/RISCV/xqcili-valid.s

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.td b/llvm/lib/Target/RISCV/RISCVInstrInfo.td
index 9058934557b54..de424b3be852b 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfo.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.td
@@ -379,7 +379,8 @@ def Simm21Lsb0JALAsmOperand : BareSImmNLsb0AsmOperand<21> {
 }
 
 // A 21-bit signed immediate where the least significant bit is zero.
-def simm21_lsb0_jal : Operand<OtherVT> {
+def simm21_lsb0_jal : Operand<OtherVT>,
+                      ImmLeaf<XLenVT, [{return isShiftedInt<20, 1>(Imm);}]>  {
   let ParserMatchClass = Simm21Lsb0JALAsmOperand;
   let PrintMethod = "printBranchOperand";
   let EncoderMethod = "getImmOpValueAsrN<1>";

diff  --git a/llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td b/llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td
index c4d6d2d704526..f292c93765744 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td
@@ -124,7 +124,8 @@ def simm16nonzero : RISCVOp<XLenVT>,
   let OperandType = "OPERAND_SIMM16_NONZERO";
 }
 
-def simm20_li : RISCVOp<XLenVT> {
+def simm20_li : RISCVOp<XLenVT>,
+                ImmLeaf<XLenVT, [{return isInt<20>(Imm);}]>{
   let ParserMatchClass = SImmAsmOperand<20, "LI">;
   let EncoderMethod = "getImmOpValue";
   let DecoderMethod = "decodeSImmOperand<20>";
@@ -1514,15 +1515,22 @@ def : CompressPat<(QC_E_J bare_simm12_lsb0:$offset),
                   (C_J bare_simm12_lsb0:$offset)>;
 def : CompressPat<(QC_E_JAL bare_simm12_lsb0:$offset),
                   (C_JAL bare_simm12_lsb0:$offset)>;
+def : CompressPat<(QC_E_JAL simm21_lsb0_jal:$offset),
+                  (JAL X1, simm21_lsb0_jal:$offset)>;
+def : CompressPat<(QC_E_J simm21_lsb0_jal:$offset),
+                  (JAL X0, simm21_lsb0_jal:$offset)>;
 } // isCompressOnly = true, Predicates = [HasVendorXqcilb, IsRV32]
 
 let Predicates = [HasVendorXqcili, IsRV32] in {
 def : CompressPat<(QC_LI GPRNoX0:$rd, simm6:$imm),
                   (C_LI GPRNoX0:$rd, simm6:$imm)>;
 
-let isCompressOnly = true in
+let isCompressOnly = true in {
 def : CompressPat<(QC_E_LI GPRNoX0:$rd, simm6:$imm),
                   (C_LI GPRNoX0:$rd, simm6:$imm)>;
+def : CompressPat<(QC_E_LI GPRNoX0:$rd, simm20_li:$imm),
+                  (QC_LI GPRNoX0:$rd, simm20_li:$imm)>;
+} // isCompressOnly = true
 } // Predicates = [HasVendorXqcili, IsRV32]
 
 let isCompressOnly = true, Predicates = [HasVendorXqcilia, IsRV32] in {

diff  --git a/llvm/test/MC/RISCV/xqcilb-valid.s b/llvm/test/MC/RISCV/xqcilb-valid.s
index 4653bfe958772..3d5b3891ddff6 100644
--- a/llvm/test/MC/RISCV/xqcilb-valid.s
+++ b/llvm/test/MC/RISCV/xqcilb-valid.s
@@ -35,3 +35,17 @@ qc.e.jal 0xffffff8c
 # CHECK-OBJ-ALIAS: j 0x40e
 # CHECK-ENC: encoding: [0x01,0xa1]
 qc.e.j 1024
+
+# CHECK-NOALIAS: jal ra, 3000
+# CHECK-ALIAS: jal 3000
+# CHECK-OBJ-NOALIAS: jal ra, 0xbc8
+# CHECK-OBJ-ALIAS: jal 0xbc8
+# CHECK-ENC: encoding: [0xef,0x00,0x90,0x3b]
+qc.e.jal 3000
+
+# CHECK-NOALIAS: jal zero, -3000
+# CHECK-ALIAS: j -3000
+# CHECK-OBJ-NOALIAS: jal zero, 0xfffff45c
+# CHECK-OBJ-ALIAS: j 0xfffff45c
+# CHECK-ENC: encoding: [0x6f,0xf0,0x8f,0xc4]
+qc.e.j -3000

diff  --git a/llvm/test/MC/RISCV/xqcili-valid.s b/llvm/test/MC/RISCV/xqcili-valid.s
index aa2898da3173a..8e9c164de662c 100644
--- a/llvm/test/MC/RISCV/xqcili-valid.s
+++ b/llvm/test/MC/RISCV/xqcili-valid.s
@@ -53,3 +53,8 @@ qc.e.li x10, 4294967295
 # CHECK-NOALIAS: c.li a0, 31
 # CHECK-ENC: encoding: [0x7d,0x45]
 qc.li x10, 31
+
+# CHECK-ALIAS: li a0, 4294
+# CHECK-NOALIAS: qc.li a0, 4294
+# CHECK-ENC: encoding: [0x1b,0x05,0xc6,0x10]
+qc.e.li x10, 4294


        


More information about the llvm-commits mailing list