Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[RISCV] Add compress patterns for Xqcisync instructions #138629

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 6, 2025

Conversation

svs-quic
Copy link
Contributor

@svs-quic svs-quic commented May 6, 2025

No description provided.

@llvmbot llvmbot added backend:RISC-V mc Machine (object) code labels May 6, 2025
@llvmbot
Copy link
Member

llvmbot commented May 6, 2025

@llvm/pr-subscribers-mc

@llvm/pr-subscribers-backend-risc-v

Author: Sudharsan Veeravalli (svs-quic)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/138629.diff

2 Files Affected:

  • (modified) llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td (+16)
  • (modified) llvm/test/MC/RISCV/xqcisync-valid.s (+41-15)
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td b/llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td
index 89b0595bc21fc..34b65e1ad98e3 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td
@@ -63,6 +63,15 @@ def uimm5slist : RISCVOp<XLenVT>, ImmLeaf<XLenVT,
   let EncoderMethod = "getImmOpValueSlist";
   let DecoderMethod = "decodeUImmSlistOperand";
   let OperandType = "OPERAND_UIMM5_SLIST";
+  let MCOperandPredicate = [{
+    int64_t Imm;
+    if (!MCOp.evaluateAsConstantImm(Imm))
+      return false;
+    return ((Imm == 0)  || (Imm == 1)  ||
+            (Imm == 2)  || (Imm == 4)  ||
+            (Imm == 8)  || (Imm == 16) ||
+            (Imm == 15) || (Imm == 31));
+  }];
 }
 
 def uimm10 : RISCVUImmLeafOp<10>;
@@ -1329,6 +1338,13 @@ def : Pat<(riscv_mileaveret_glue), (QC_C_MILEAVERET)>;
 // Compress Instruction tablegen backend.
 //===----------------------------------------------------------------------===//
 
+let Predicates = [HasVendorXqcisync, IsRV32] in {
+def : CompressPat<(QC_SYNC uimm5slist:$imm5), (QC_C_SYNC uimm5slist:$imm5)>;
+def : CompressPat<(QC_SYNCR uimm5slist:$imm5), (QC_C_SYNCR uimm5slist:$imm5)>;
+def : CompressPat<(QC_SYNCWL uimm5slist:$imm5), (QC_C_SYNCWL uimm5slist:$imm5)>;
+def : CompressPat<(QC_SYNCWF uimm5slist:$imm5), (QC_C_SYNCWF uimm5slist:$imm5)>;
+} // Predicates = [HasVendorXqcisync, IsRV32]
+
 let isCompressOnly = true, Predicates = [HasVendorXqcilo, HasStdExtZcb, IsRV32] in {
 def : CompressPat<(QC_E_LBU GPRC:$rd, GPRCMem:$rs1, uimm2:$imm),
                   (C_LBU GPRC:$rd, GPRCMem:$rs1, uimm2:$imm)>;
diff --git a/llvm/test/MC/RISCV/xqcisync-valid.s b/llvm/test/MC/RISCV/xqcisync-valid.s
index 4f0063a6a488c..84ea74b74564f 100644
--- a/llvm/test/MC/RISCV/xqcisync-valid.s
+++ b/llvm/test/MC/RISCV/xqcisync-valid.s
@@ -1,11 +1,11 @@
 # Xqcisync - Qualcomm uC Sync Delay Extension
 # RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-xqcisync -M no-aliases -show-encoding \
-# RUN:     | FileCheck -check-prefixes=CHECK-ENC,CHECK-INST %s
+# RUN:     | FileCheck -check-prefixes=CHECK-ENC,CHECK-INST,CHECK-NOALIAS %s
 # RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+experimental-xqcisync < %s \
 # RUN:     | llvm-objdump --mattr=+experimental-xqcisync -M no-aliases --no-print-imm-hex -d - \
 # RUN:     | FileCheck -check-prefix=CHECK-INST %s
 # RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-xqcisync -show-encoding \
-# RUN:     | FileCheck -check-prefixes=CHECK-ENC,CHECK-INST %s
+# RUN:     | FileCheck -check-prefixes=CHECK-ENC,CHECK-INST,CHECK-ALIAS %s
 # RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+experimental-xqcisync < %s \
 # RUN:     | llvm-objdump --mattr=+experimental-xqcisync --no-print-imm-hex -d - \
 # RUN:     | FileCheck -check-prefix=CHECK-INST %s
@@ -14,34 +14,60 @@
 # CHECK-ENC: encoding: [0x2a,0x00]
 qc.c.delay 10
 
-# CHECK-INST: qc.sync      8
-# CHECK-ENC: encoding: [0x13,0x30,0x80,0x10]
-qc.sync 8
+# CHECK-INST: qc.sync      9
+# CHECK-ENC: encoding: [0x13,0x30,0x90,0x10]
+qc.sync 9
 
 # CHECK-INST: qc.syncr     23
 # CHECK-ENC: encoding: [0x13,0x30,0x70,0x21]
 qc.syncr 23
 
-# CHECK-INST: qc.syncwf    31
-# CHECK-ENC: encoding: [0x13,0x30,0xf0,0x41]
-qc.syncwf 31
+# CHECK-INST: qc.syncwf    30
+# CHECK-ENC: encoding: [0x13,0x30,0xe0,0x41]
+qc.syncwf 30
 
-# CHECK-INST: qc.syncwl    1
-# CHECK-ENC: encoding: [0x13,0x30,0x10,0x80]
-qc.syncwl 1
+# CHECK-INST: qc.syncwl    6
+# CHECK-ENC: encoding: [0x13,0x30,0x60,0x80]
+qc.syncwl 6
 
-# CHECK-INST: qc.c.sync      0
+# CHECK-NOALIAS: qc.c.sync      0
+# CHECK-ALIAS: qc.sync 0
 # CHECK-ENC: encoding: [0x01,0x80]
 qc.c.sync 0
 
-# CHECK-INST: qc.c.syncr     15
+# CHECK-NOALIAS: qc.c.syncr     15
+# CHECK-ALIAS: qc.syncr 15
 # CHECK-ENC: encoding: [0x01,0x87]
 qc.c.syncr 15
 
-# CHECK-INST: qc.c.syncwf    31
+# CHECK-NOALIAS: qc.c.syncwf    31
+# CHECK-ALIAS: qc.syncwf 31
 # CHECK-ENC: encoding: [0x81,0x93]
 qc.c.syncwf 31
 
-# CHECK-INST: qc.c.syncwl    4
+# CHECK-NOALIAS: qc.c.syncwl    4
+# CHECK-ALIAS: qc.syncwl 4
 # CHECK-ENC: encoding: [0x81,0x95]
 qc.c.syncwl 4
+
+# Check that compressed patterns work
+
+# CHECK-NOALIAS: qc.c.sync      8
+# CHECK-ALIAS: qc.sync 8
+# CHECK-ENC: encoding: [0x01,0x82]
+qc.sync 8
+
+# CHECK-NOALIAS: qc.c.syncr     31
+# CHECK-ALIAS: qc.syncr 31
+# CHECK-ENC: encoding: [0x81,0x87]
+qc.syncr 31
+
+# CHECK-NOALIAS: qc.c.syncwf    0
+# CHECK-ALIAS: qc.syncwf 0
+# CHECK-ENC: encoding: [0x01,0x90]
+qc.syncwf 0
+
+# CHECK-NOALIAS: qc.c.syncwl    16
+# CHECK-ALIAS: qc.syncwl 16
+# CHECK-ENC: encoding: [0x81,0x96]
+qc.syncwl 16

@svs-quic svs-quic requested review from topperc and removed request for 0x59616e May 6, 2025 04:48
@svs-quic
Copy link
Contributor Author

svs-quic commented May 6, 2025

Unrelated lldb test failure

Copy link
Contributor

@hchandel hchandel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@svs-quic svs-quic merged commit f54f4cf into llvm:main May 6, 2025
11 checks passed
@svs-quic svs-quic deleted the xqcisync_comp branch May 6, 2025 07:47
GeorgeARM pushed a commit to GeorgeARM/llvm-project that referenced this pull request May 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:RISC-V mc Machine (object) code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants