Skip to content

Commit 4f5f44f

Browse files
toppercmahesh-attarde
authored andcommitted
[RISCV] Correct the immediate swizzling for P-ext plui.h/w. (llvm#149945)
If I'm reading the spec correctly, plui.h/w encode the immediate differently from pli.h/w. pli.h/w appear to rotate the immediate left by 1 before encoding while plui.h/w rotates the immediate right by 1 before encoding. Since I was splitting the classes, I made the name closer to the instruction names since the immediate width was ambiguous. I've added an _i suffix to make it similar to base and Zb* class names.
1 parent 16362b3 commit 4f5f44f

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfoP.td

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ def simm10_unsigned : RISCVOp {
4444
//===----------------------------------------------------------------------===//
4545

4646
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
47-
class RVPLoadImm10<bits<7> funct7, string opcodestr,
48-
DAGOperand TyImm10 = simm10>
49-
: RVInst<(outs GPR:$rd), (ins TyImm10:$imm10), opcodestr, "$rd, $imm10", [],
47+
class PLI_i<bits<7> funct7, string opcodestr>
48+
: RVInst<(outs GPR:$rd), (ins simm10:$imm10), opcodestr, "$rd, $imm10", [],
5049
InstFormatOther> {
5150
bits<10> imm10;
5251
bits<5> rd;
@@ -60,7 +59,22 @@ class RVPLoadImm10<bits<7> funct7, string opcodestr,
6059
}
6160

6261
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
63-
class RVPLoadImm8<bits<8> funct8, string opcodestr>
62+
class PLUI_i<bits<7> funct7, string opcodestr>
63+
: RVInst<(outs GPR:$rd), (ins simm10_unsigned:$imm10), opcodestr,
64+
"$rd, $imm10", [], InstFormatOther> {
65+
bits<10> imm10;
66+
bits<5> rd;
67+
68+
let Inst{31-25} = funct7;
69+
let Inst{24} = imm10{0};
70+
let Inst{23-15} = imm10{9-1};
71+
let Inst{14-12} = 0b010;
72+
let Inst{11-7} = rd;
73+
let Inst{6-0} = OPC_OP_IMM_32.Value;
74+
}
75+
76+
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
77+
class PLI_B_i<bits<8> funct8, string opcodestr>
6478
: RVInst<(outs GPR:$rd), (ins uimm8:$uimm8), opcodestr, "$rd, $uimm8", [],
6579
InstFormatOther> {
6680
bits<8> uimm8;
@@ -148,11 +162,11 @@ def PSSLAI_W : RVPUnaryImm5<0b101, "psslai.w">;
148162
} // Predicates = [HasStdExtP, IsRV64]
149163

150164
let Predicates = [HasStdExtP] in
151-
def PLI_H : RVPLoadImm10<0b1011000, "pli.h">;
165+
def PLI_H : PLI_i<0b1011000, "pli.h">;
152166
let Predicates = [HasStdExtP, IsRV64] in
153-
def PLI_W : RVPLoadImm10<0b1011001, "pli.w">;
167+
def PLI_W : PLI_i<0b1011001, "pli.w">;
154168
let Predicates = [HasStdExtP] in
155-
def PLI_B : RVPLoadImm8<0b10110100, "pli.b">;
169+
def PLI_B : PLI_B_i<0b10110100, "pli.b">;
156170

157171
let Predicates = [HasStdExtP] in {
158172
def PSEXT_H_B : RVPUnaryWUF<0b00, 0b00100, "psext.h.b">;
@@ -165,6 +179,6 @@ def PSEXT_W_H : RVPUnaryWUF<0b01, 0b00101, "psext.w.h">;
165179
} // Predicates = [HasStdExtP, IsRV64]
166180

167181
let Predicates = [HasStdExtP] in
168-
def PLUI_H : RVPLoadImm10<0b1111000, "plui.h", simm10_unsigned>;
182+
def PLUI_H : PLUI_i<0b1111000, "plui.h">;
169183
let Predicates = [HasStdExtP, IsRV64] in
170-
def PLUI_W : RVPLoadImm10<0b1111001, "plui.w", simm10_unsigned>;
184+
def PLUI_W : PLUI_i<0b1111001, "plui.w">;

llvm/test/MC/RISCV/rv32p-valid.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ psabs.h a1, a2
7171
# CHECK-ASM: encoding: [0x9b,0x22,0x73,0xe4]
7272
psabs.b t0, t1
7373
# CHECK-ASM-AND-OBJ: plui.h gp, 32
74-
# CHECK-ASM: encoding: [0x9b,0x21,0x20,0xf0]
74+
# CHECK-ASM: encoding: [0x9b,0x21,0x08,0xf0]
7575
plui.h gp, 32
7676
# CHECK-ASM-AND-OBJ: plui.h gp, -412
77-
# CHECK-ASM: encoding: [0x9b,0xa1,0x64,0xf0]
77+
# CHECK-ASM: encoding: [0x9b,0x21,0x99,0xf0]
7878
plui.h gp, 612

llvm/test/MC/RISCV/rv64p-valid.s

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@ psabs.h t1, t5
9595
# CHECK-ASM: encoding: [0x1b,0x25,0x79,0xe4]
9696
psabs.b a0, s2
9797
# CHECK-ASM-AND-OBJ: plui.h s2, 4
98-
# CHECK-ASM: encoding: [0x1b,0x29,0x04,0xf0]
98+
# CHECK-ASM: encoding: [0x1b,0x29,0x01,0xf0]
9999
plui.h s2, 4
100100
# CHECK-ASM-AND-OBJ: plui.h gp, -412
101-
# CHECK-ASM: encoding: [0x9b,0xa1,0x64,0xf0]
101+
# CHECK-ASM: encoding: [0x9b,0x21,0x99,0xf0]
102102
plui.h gp, 612
103103
# CHECK-ASM-AND-OBJ: plui.w a2, 1
104-
# CHECK-ASM: encoding: [0x1b,0x26,0x01,0xf2]
104+
# CHECK-ASM: encoding: [0x1b,0x26,0x00,0xf3]
105105
plui.w a2, 1
106106
# CHECK-ASM-AND-OBJ: plui.w a2, -1
107107
# CHECK-ASM: encoding: [0x1b,0xa6,0xff,0xf3]

0 commit comments

Comments
 (0)