Skip to content

Commit cce10cc

Browse files
authored
[RISCV] Add .insn alias for addresses without the leading immediate. (#94698)
Most other instructions accept addresses that start with a '(' without an immediate before it. The .insn cases were missing. This is also supported by binutils.
1 parent e9fa6ff commit cce10cc

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfo.td

+6
Original file line numberDiff line numberDiff line change
@@ -1140,6 +1140,9 @@ def : InstAlias<".insn_i $opcode, $funct3, $rd, $rs1, $imm12",
11401140
def : InstAlias<".insn_i $opcode, $funct3, $rd, ${imm12}(${rs1})",
11411141
(InsnI_Mem AnyReg:$rd, uimm7_opcode:$opcode, uimm3:$funct3,
11421142
AnyReg:$rs1, simm12:$imm12)>;
1143+
def : InstAlias<".insn_i $opcode, $funct3, $rd, (${rs1})",
1144+
(InsnI_Mem AnyReg:$rd, uimm7_opcode:$opcode, uimm3:$funct3,
1145+
AnyReg:$rs1, 0)>;
11431146
def : InstAlias<".insn_b $opcode, $funct3, $rs1, $rs2, $imm12",
11441147
(InsnB uimm7_opcode:$opcode, uimm3:$funct3, AnyReg:$rs1,
11451148
AnyReg:$rs2, simm13_lsb0:$imm12)>;
@@ -1157,6 +1160,9 @@ def : InstAlias<".insn_uj $opcode, $rd, $imm20",
11571160
def : InstAlias<".insn_s $opcode, $funct3, $rs2, ${imm12}(${rs1})",
11581161
(InsnS uimm7_opcode:$opcode, uimm3:$funct3, AnyReg:$rs2,
11591162
AnyReg:$rs1, simm12:$imm12)>;
1163+
def : InstAlias<".insn_s $opcode, $funct3, $rs2, (${rs1})",
1164+
(InsnS uimm7_opcode:$opcode, uimm3:$funct3, AnyReg:$rs2,
1165+
AnyReg:$rs1, 0)>;
11601166
}
11611167

11621168
//===----------------------------------------------------------------------===//

llvm/lib/Target/RISCV/RISCVInstrInfoC.td

+6
Original file line numberDiff line numberDiff line change
@@ -823,9 +823,15 @@ def : InstAlias<".insn_css $opcode, $funct3, $rs2, $imm6",
823823
def : InstAlias<".insn_cl $opcode, $funct3, $rd, ${imm5}(${rs1})",
824824
(InsnCL AnyRegC:$rd, uimm2_opcode:$opcode, uimm3:$funct3,
825825
AnyRegC:$rs1, uimm5:$imm5)>;
826+
def : InstAlias<".insn_cl $opcode, $funct3, $rd, (${rs1})",
827+
(InsnCL AnyRegC:$rd, uimm2_opcode:$opcode, uimm3:$funct3,
828+
AnyRegC:$rs1, 0)>;
826829
def : InstAlias<".insn_cs $opcode, $funct3, $rs2, ${imm5}(${rs1})",
827830
(InsnCS uimm2_opcode:$opcode, uimm3:$funct3, AnyRegC:$rs2,
828831
AnyRegC:$rs1, uimm5:$imm5)>;
832+
def : InstAlias<".insn_cs $opcode, $funct3, $rs2, (${rs1})",
833+
(InsnCS uimm2_opcode:$opcode, uimm3:$funct3, AnyRegC:$rs2,
834+
AnyRegC:$rs1, 0)>;
829835
def : InstAlias<".insn_ca $opcode, $funct6, $funct2, $rd, $rs2",
830836
(InsnCA AnyRegC:$rd, uimm2_opcode:$opcode, uimm6:$funct6,
831837
uimm2:$funct2, AnyRegC:$rs2)>;

llvm/test/MC/RISCV/insn.s

+27
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ target:
3838
# CHECK-OBJ: jalr a0, 0xa(a1)
3939
.insn i JALR, 0, a0, 10(a1)
4040

41+
# CHECK-ASM: .insn i 103, 0, a0, 0(a1)
42+
# CHECK-ASM: encoding: [0x67,0x85,0x05,0x00]
43+
# CHECK-OBJ: jalr a0, 0x0(a1)
44+
.insn i 0x67, 0, a0, (a1)
45+
# CHECK-ASM: .insn i 103, 0, a0, 0(a1)
46+
# CHECK-ASM: encoding: [0x67,0x85,0x05,0x00]
47+
# CHECK-OBJ: jalr a0, 0x0(a1)
48+
.insn i JALR, 0, a0, (a1)
49+
4150
# CHECK-ASM: .insn i 3, 0, a0, 4(a1)
4251
# CHECK-ASM: encoding: [0x03,0x85,0x45,0x00]
4352
# CHECK-OBJ: lb a0, 0x4(a1)
@@ -47,6 +56,15 @@ target:
4756
# CHECK-OBJ: lb a0, 0x4(a1)
4857
.insn i LOAD, 0, a0, 4(a1)
4958

59+
# CHECK-ASM: .insn i 3, 0, a0, 0(a1)
60+
# CHECK-ASM: encoding: [0x03,0x85,0x05,0x00]
61+
# CHECK-OBJ: lb a0, 0x0(a1)
62+
.insn i 0x3, 0, a0, (a1)
63+
# CHECK-ASM: .insn i 3, 0, a0, 0(a1)
64+
# CHECK-ASM: encoding: [0x03,0x85,0x05,0x00]
65+
# CHECK-OBJ: lb a0, 0x0(a1)
66+
.insn i LOAD, 0, a0, (a1)
67+
5068
# CHECK-ASM: .insn b 99, 0, a0, a1, target
5169
# CHECK-ASM: [0x63'A',A,0xb5'A',A]
5270
# CHECK-OBJ: beq a0, a1, 0x0 <target>
@@ -74,6 +92,15 @@ target:
7492
# CHECK-OBJ: sb a0, 0x4(a1)
7593
.insn s STORE, 0, a0, 4(a1)
7694

95+
# CHECK-ASM: .insn s 35, 0, a0, 0(a1)
96+
# CHECK-ASM: encoding: [0x23,0x80,0xa5,0x00]
97+
# CHECK-OBJ: sb a0, 0x0(a1)
98+
.insn s 0x23, 0, a0, (a1)
99+
# CHECK-ASM: .insn s 35, 0, a0, 0(a1)
100+
# CHECK-ASM: encoding: [0x23,0x80,0xa5,0x00]
101+
# CHECK-OBJ: sb a0, 0x0(a1)
102+
.insn s STORE, 0, a0, (a1)
103+
77104
# CHECK-ASM: .insn u 55, a0, 4095
78105
# CHECK-ASM: encoding: [0x37,0xf5,0xff,0x00]
79106
# CHECK-OBJ: lui a0, 0xfff

llvm/test/MC/RISCV/insn_c.s

+10
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,21 @@ target:
5151
# CHECK-OBJ: c.lw a0, 0x58(a1)
5252
.insn cl 0, 2, a0, 13(a1)
5353

54+
# CHECK-ASM: .insn cl 0, 2, a0, 0
55+
# CHECK-ASM: encoding: [0x88,0x41]
56+
# CHECK-OBJ: c.lw a0, 0x0(a1)
57+
.insn cl 0, 2, a0, 0(a1)
58+
5459
# CHECK-ASM: .insn cs 0, 6, a0, 13
5560
# CHECK-ASM: encoding: [0xa8,0xcd]
5661
# CHECK-OBJ: c.sw a0, 0x58(a1)
5762
.insn cs 0, 6, a0, 13(a1)
5863

64+
# CHECK-ASM: .insn cs 0, 6, a0, 0
65+
# CHECK-ASM: encoding: [0x88,0xc1]
66+
# CHECK-OBJ: c.sw a0, 0x0(a1)
67+
.insn cs 0, 6, a0, (a1)
68+
5969
# CHECK-ASM: .insn ca 1, 35, 0, a0, a1
6070
# CHECK-ASM: encoding: [0x0d,0x8d]
6171
# CHECK-OBJ: c.sub a0, a1

0 commit comments

Comments
 (0)