[llvm] [RISCV] Correct the register class in the C_SWSP and C_SDSP InstAliases. (PR #132086)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 19 12:19:39 PDT 2025


https://github.com/topperc created https://github.com/llvm/llvm-project/pull/132086

These instructions use GPR not GPRNoX0. Only the load forms prohibit X0.

>From 24c8393bb59df746ed3d487afa90ef7def6af9ab Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Wed, 19 Mar 2025 12:02:04 -0700
Subject: [PATCH] [RISCV] Correct the register class in the C_SWSP and C_SDSP
 InstAliases.

These instructions use GPR not GPRNoX0. Only the load forms prohibit X0.
---
 llvm/lib/Target/RISCV/RISCVInstrInfoC.td | 4 ++--
 llvm/test/MC/RISCV/rv64c-aliases-valid.s | 2 ++
 llvm/test/MC/RISCV/rvc-aliases-valid.s   | 2 ++
 3 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoC.td b/llvm/lib/Target/RISCV/RISCVInstrInfoC.td
index b3eca8ff89904..375fe640c6c3d 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfoC.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfoC.td
@@ -715,14 +715,14 @@ let Predicates = [HasStdExtCOrZca] in {
 def : InstAlias<"c.lw $rd, (${rs1})", (C_LW GPRC:$rd, GPRCMem:$rs1, 0)>;
 def : InstAlias<"c.sw $rs2, (${rs1})", (C_SW GPRC:$rs2, GPRCMem:$rs1, 0)>;
 def : InstAlias<"c.lwsp $rd, (${rs1})", (C_LWSP GPRNoX0:$rd, SPMem:$rs1, 0)>;
-def : InstAlias<"c.swsp $rs2, (${rs1})", (C_SWSP GPRNoX0:$rs2, SPMem:$rs1, 0)>;
+def : InstAlias<"c.swsp $rs2, (${rs1})", (C_SWSP GPR:$rs2, SPMem:$rs1, 0)>;
 }
 
 let Predicates = [HasStdExtCOrZca, IsRV64] in {
 def : InstAlias<"c.ld $rd, (${rs1})", (C_LD GPRC:$rd, GPRCMem:$rs1, 0)>;
 def : InstAlias<"c.sd $rs2, (${rs1})", (C_SD GPRC:$rs2, GPRCMem:$rs1, 0)>;
 def : InstAlias<"c.ldsp $rd, (${rs1})", (C_LDSP GPRNoX0:$rd, SPMem:$rs1, 0)>;
-def : InstAlias<"c.sdsp $rs2, (${rs1})", (C_SDSP GPRNoX0:$rs2, SPMem:$rs1, 0)>;
+def : InstAlias<"c.sdsp $rs2, (${rs1})", (C_SDSP GPR:$rs2, SPMem:$rs1, 0)>;
 }
 
 let Predicates = [HasStdExtCOrZcfOrZce, HasStdExtF, IsRV32] in {
diff --git a/llvm/test/MC/RISCV/rv64c-aliases-valid.s b/llvm/test/MC/RISCV/rv64c-aliases-valid.s
index 685669737d9bb..a464c24609fba 100644
--- a/llvm/test/MC/RISCV/rv64c-aliases-valid.s
+++ b/llvm/test/MC/RISCV/rv64c-aliases-valid.s
@@ -112,3 +112,5 @@ c.sdsp x8, (x2)
 c.ldsp x18, (x2)
 # CHECK-EXPAND: c.sdsp s2, 0(sp)
 c.sdsp x18, (x2)
+# CHECK-EXPAND: c.sdsp zero, 0(sp)
+c.sdsp x0, (x2)
diff --git a/llvm/test/MC/RISCV/rvc-aliases-valid.s b/llvm/test/MC/RISCV/rvc-aliases-valid.s
index 23398f9721446..c18e06fdc1bee 100644
--- a/llvm/test/MC/RISCV/rvc-aliases-valid.s
+++ b/llvm/test/MC/RISCV/rvc-aliases-valid.s
@@ -21,3 +21,5 @@ c.swsp x8, (x2)
 c.lwsp x18, (x2)
 # CHECK-EXPAND: c.swsp s2, 0(sp)
 c.swsp x18, (x2)
+# CHECK-EXPAND: c.swsp zero, 0(sp)
+c.swsp x0, (x2)



More information about the llvm-commits mailing list