Skip to content

Commit 8b511e1

Browse files
authored
[RISCV] Fix 0-offset aliases for compressed sp-based opcodes (#98034)
The "26.3.1. Stack-Pointer-Based Loads and Stores" compressed opcodes have access to all registers (except x0). Fix the opcode aliases with 0 offset so that the aliases also work for all registers, not only the RVC registers. Previously, LLVM would accept e.g. `c.lwsp x8, (sp)` but not e.g. `c.lwsp x18, (sp)`, even though e.g. `c.lwsp x18, 0(sp)` would be accepted. This was noticed while implementing #97925 . The implementation in that other PR is indeed correct (i.e `qk.c.lhusp` et al are restricted to the RVC registers).
1 parent d521324 commit 8b511e1

File tree

5 files changed

+24
-8
lines changed

5 files changed

+24
-8
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfoC.td

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -716,29 +716,29 @@ let EmitPriority = 0 in {
716716
let Predicates = [HasStdExtCOrZca] in {
717717
def : InstAlias<"c.lw $rd, (${rs1})", (C_LW GPRC:$rd, GPRCMem:$rs1, 0)>;
718718
def : InstAlias<"c.sw $rs2, (${rs1})", (C_SW GPRC:$rs2, GPRCMem:$rs1, 0)>;
719-
def : InstAlias<"c.lwsp $rd, (${rs1})", (C_LWSP GPRC:$rd, SPMem:$rs1, 0)>;
720-
def : InstAlias<"c.swsp $rs2, (${rs1})", (C_SWSP GPRC:$rs2, SPMem:$rs1, 0)>;
719+
def : InstAlias<"c.lwsp $rd, (${rs1})", (C_LWSP GPRNoX0:$rd, SPMem:$rs1, 0)>;
720+
def : InstAlias<"c.swsp $rs2, (${rs1})", (C_SWSP GPRNoX0:$rs2, SPMem:$rs1, 0)>;
721721
}
722722

723723
let Predicates = [HasStdExtCOrZca, IsRV64] in {
724724
def : InstAlias<"c.ld $rd, (${rs1})", (C_LD GPRC:$rd, GPRCMem:$rs1, 0)>;
725725
def : InstAlias<"c.sd $rs2, (${rs1})", (C_SD GPRC:$rs2, GPRCMem:$rs1, 0)>;
726-
def : InstAlias<"c.ldsp $rd, (${rs1})", (C_LDSP GPRC:$rd, SPMem:$rs1, 0)>;
727-
def : InstAlias<"c.sdsp $rs2, (${rs1})", (C_SDSP GPRC:$rs2, SPMem:$rs1, 0)>;
726+
def : InstAlias<"c.ldsp $rd, (${rs1})", (C_LDSP GPRNoX0:$rd, SPMem:$rs1, 0)>;
727+
def : InstAlias<"c.sdsp $rs2, (${rs1})", (C_SDSP GPRNoX0:$rs2, SPMem:$rs1, 0)>;
728728
}
729729

730730
let Predicates = [HasStdExtCOrZcfOrZce, HasStdExtF, IsRV32] in {
731731
def : InstAlias<"c.flw $rd, (${rs1})", (C_FLW FPR32C:$rd, GPRCMem:$rs1, 0)>;
732732
def : InstAlias<"c.fsw $rs2, (${rs1})", (C_FSW FPR32C:$rs2, GPRCMem:$rs1, 0)>;
733-
def : InstAlias<"c.flwsp $rd, (${rs1})", (C_FLWSP FPR32C:$rd, SPMem:$rs1, 0)>;
734-
def : InstAlias<"c.fswsp $rs2, (${rs1})", (C_FSWSP FPR32C:$rs2, SPMem:$rs1, 0)>;
733+
def : InstAlias<"c.flwsp $rd, (${rs1})", (C_FLWSP FPR32:$rd, SPMem:$rs1, 0)>;
734+
def : InstAlias<"c.fswsp $rs2, (${rs1})", (C_FSWSP FPR32:$rs2, SPMem:$rs1, 0)>;
735735
}
736736

737737
let Predicates = [HasStdExtCOrZcd, HasStdExtD] in {
738738
def : InstAlias<"c.fld $rd, (${rs1})", (C_FLD FPR64C:$rd, GPRCMem:$rs1, 0)>;
739739
def : InstAlias<"c.fsd $rs2, (${rs1})", (C_FSD FPR64C:$rs2, GPRCMem:$rs1, 0)>;
740-
def : InstAlias<"c.fldsp $rd, (${rs1})", (C_FLDSP FPR64C:$rd, SPMem:$rs1, 0)>;
741-
def : InstAlias<"c.fsdsp $rs2, (${rs1})", (C_FSDSP FPR64C:$rs2, SPMem:$rs1, 0)>;
740+
def : InstAlias<"c.fldsp $rd, (${rs1})", (C_FLDSP FPR64:$rd, SPMem:$rs1, 0)>;
741+
def : InstAlias<"c.fsdsp $rs2, (${rs1})", (C_FSDSP FPR64:$rs2, SPMem:$rs1, 0)>;
742742
}
743743
} // EmitPriority = 0
744744

llvm/test/MC/RISCV/rv32fc-aliases-valid.s

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ c.fsw f8, (x9)
1212
c.flwsp f8, (x2)
1313
# CHECK-EXPAND: c.fswsp fs0, 0(sp)
1414
c.fswsp f8, (x2)
15+
# CHECK-EXPAND: c.flwsp fs2, 0(sp)
16+
c.flwsp f18, (x2)
17+
# CHECK-EXPAND: c.fswsp fs2, 0(sp)
18+
c.fswsp f18, (x2)

llvm/test/MC/RISCV/rv64c-aliases-valid.s

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,7 @@ c.sd x8, (x9)
108108
c.ldsp x8, (x2)
109109
# CHECK-EXPAND: c.sdsp s0, 0(sp)
110110
c.sdsp x8, (x2)
111+
# CHECK-EXPAND: c.ldsp s2, 0(sp)
112+
c.ldsp x18, (x2)
113+
# CHECK-EXPAND: c.sdsp s2, 0(sp)
114+
c.sdsp x18, (x2)

llvm/test/MC/RISCV/rvc-aliases-valid.s

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ c.sw x8, (x9)
1717
c.lwsp x8, (x2)
1818
# CHECK-EXPAND: c.swsp s0, 0(sp)
1919
c.swsp x8, (x2)
20+
# CHECK-EXPAND: c.lwsp s2, 0(sp)
21+
c.lwsp x18, (x2)
22+
# CHECK-EXPAND: c.swsp s2, 0(sp)
23+
c.swsp x18, (x2)

llvm/test/MC/RISCV/rvdc-aliases-valid.s

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ c.fsd f8, (x9)
1616
c.fldsp f8, (x2)
1717
# CHECK-EXPAND: c.fsdsp fs0, 0(sp)
1818
c.fsdsp f8, (x2)
19+
# CHECK-EXPAND: c.fldsp fs2, 0(sp)
20+
c.fldsp f18, (x2)
21+
# CHECK-EXPAND: c.fsdsp fs2, 0(sp)
22+
c.fsdsp f18, (x2)

0 commit comments

Comments
 (0)