Skip to content

Commit 34f08d1

Browse files
committed
[SOL] Correctly disassemble store imm (#131)
1 parent 9e3a910 commit 34f08d1

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

llvm/lib/Target/SBF/Disassembler/SBFDisassembler.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class SBFDisassembler : public MCDisassembler {
7070
bool isMov32(uint64_t Inst) const { return (Inst >> 56) == 0xb4; }
7171
bool isNewMem(uint64_t Inst) const;
7272
bool isSyscallOrExit(uint64_t Inst) const { return (Inst >> 56) == 0x95; }
73+
bool isAlu32NewLoadStoreReg(uint64_t Inst) const;
7374
};
7475

7576
} // end anonymous namespace
@@ -172,6 +173,14 @@ bool SBFDisassembler::isNewMem(uint64_t Inst) const {
172173
return MSB == 0x2 || MSB == 0x3 || MSB == 0x8 || MSB == 0x9;
173174
}
174175

176+
bool SBFDisassembler::isAlu32NewLoadStoreReg(uint64_t Inst) const {
177+
bool IsNotDw = (Inst >> 60) != 0x9;
178+
bool IsNotStoreImm = (Inst >> 56 & 0xf) != 0x7;
179+
return isNewMem(Inst) && IsNotDw && IsNotStoreImm &&
180+
STI.hasFeature(SBF::FeatureNewMemEncoding) &&
181+
STI.hasFeature(SBF::ALU32);
182+
}
183+
175184
DecodeStatus SBFDisassembler::getInstruction(MCInst &Instr, uint64_t &Size,
176185
ArrayRef<uint8_t> Bytes,
177186
uint64_t Address,
@@ -197,17 +206,17 @@ DecodeStatus SBFDisassembler::getInstruction(MCInst &Instr, uint64_t &Size,
197206
STI.hasFeature(SBF::FeatureDisableLddw))
198207
Result =
199208
decodeInstruction(DecoderTableSBFv264, Instr, Insn, Address, this, STI);
200-
else if (isNewMem(Insn) && (Insn >> 60) != 0x9 &&
201-
STI.hasFeature(SBF::FeatureNewMemEncoding) &&
202-
STI.hasFeature(SBF::ALU32))
209+
else if (isAlu32NewLoadStoreReg(Insn)) {
203210
Result =
204211
decodeInstruction(DecoderTableSBFALU32MEMv264,
205212
Instr, Insn, Address, this, STI);
213+
}
206214
else if ((isNewMem(Insn) && STI.hasFeature(SBF::FeatureNewMemEncoding)) ||
207-
(isSyscallOrExit(Insn) && STI.hasFeature(SBF::FeatureStaticSyscalls)))
215+
(isSyscallOrExit(Insn) && STI.hasFeature(SBF::FeatureStaticSyscalls))) {
208216
Result =
209217
decodeInstruction(DecoderTableSBFv264,
210218
Instr, Insn, Address, this, STI);
219+
}
211220
else
212221
Result =
213222
decodeInstruction(DecoderTableSBF64, Instr, Insn, Address, this, STI);

llvm/test/CodeGen/SBF/store-imm.ll

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
; RUN: llc < %s -march=sbf -mattr=+store-imm -show-mc-encoding | FileCheck %s
22
; RUN: llc < %s -march=sbf -mattr=+store-imm,+alu32 -show-mc-encoding | FileCheck %s
33
; RUN: llc < %s -march=sbf -mattr=+store-imm,+mem-encoding -show-mc-encoding | FileCheck --check-prefix=CHECK-V2 %s
4+
; RUN: llc -march=sbf -mcpu=v3 -filetype=obj -o - %s | llvm-objdump -d --no-print-imm-hex - | FileCheck --check-prefix=CHECK-DUMP %s
45

56
define void @byte(ptr %p0) {
67
; CHECK-LABEL: byte:
@@ -10,6 +11,10 @@ define void @byte(ptr %p0) {
1011

1112
; CHECK-V2: stb [r1 + 0], 1 # encoding: [0x27,0x01,0x00,0x00,0x01,0x00,0x00,0x00]
1213
; CHECK-V2: stb [r1 + 1], 255 # encoding: [0x27,0x01,0x01,0x00,0xff,0x00,0x00,0x00]
14+
15+
; CHECK-DUMP: stb [r1 + 0], 1
16+
; CHECK-DUMP: stb [r1 + 1], 255
17+
1318
%p1 = getelementptr i8, ptr %p0, i32 1
1419
store volatile i8 1, ptr %p0, align 1
1520
store volatile i8 -1, ptr %p1, align 1
@@ -23,6 +28,10 @@ define void @half(ptr, ptr %p0) {
2328

2429
; CHECK-V2: sth [r2 + 0], 1 # encoding: [0x37,0x02,0x00,0x00,0x01,0x00,0x00,0x00]
2530
; CHECK-V2: sth [r2 + 2], 65535 # encoding: [0x37,0x02,0x02,0x00,0xff,0xff,0x00,0x00]
31+
32+
; CHECK-DUMP: sth [r2 + 0], 1
33+
; CHECK-DUMP: sth [r2 + 2], 65535
34+
2635
%p1 = getelementptr i8, ptr %p0, i32 2
2736
store volatile i16 1, ptr %p0, align 2
2837
store volatile i16 -1, ptr %p1, align 2
@@ -42,6 +51,13 @@ define void @word(ptr, ptr, ptr %p0) {
4251
; CHECK-V2: stw [r3 + 8], -2000000000 # encoding: [0x87,0x03,0x08,0x00,0x00,0x6c,0xca,0x88]
4352
; CHECK-V2: stw [r3 + 12], -1 # encoding: [0x87,0x03,0x0c,0x00,0xff,0xff,0xff,0xff]
4453
; CHECK-V2: stw [r3 + 12], 0 # encoding: [0x87,0x03,0x0c,0x00,0x00,0x00,0x00,0x00]
54+
55+
; CHECK-DUMP: stw [r3 + 0], 1
56+
; CHECK-DUMP: stw [r3 + 4], -1
57+
; CHECK-DUMP: stw [r3 + 8], -2000000000
58+
; CHECK-DUMP: stw [r3 + 12], -1
59+
; CHECK-DUMP: stw [r3 + 12], 0
60+
4561
%p1 = getelementptr i8, ptr %p0, i32 4
4662
%p2 = getelementptr i8, ptr %p0, i32 8
4763
%p3 = getelementptr i8, ptr %p0, i32 12
@@ -68,6 +84,12 @@ define void @dword(ptr, ptr, ptr, ptr %p0) {
6884
; CHECK-V2: stdw [r4 + 16], -2000000000 # encoding: [0x97,0x04,0x10,0x00,0x00,0x6c,0xca,0x88]
6985
; CHECK-V2: lddw r1, 4294967295 # encoding: [0x18,0x01,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
7086
; CHECK-V2: stxdw [r4 + 24], r1 # encoding: [0x9f,0x14,0x18,0x00,0x00,0x00,0x00,0x00]
87+
88+
; CHECK-DUMP: stdw [r4 + 0], 1
89+
; CHECK-DUMP: stdw [r4 + 8], -1
90+
; CHECK-DUMP: stdw [r4 + 16], 2000000000
91+
; CHECK-DUMP: stdw [r4 + 16], -2000000000
92+
7193
%p1 = getelementptr i8, ptr %p0, i32 8
7294
%p2 = getelementptr i8, ptr %p0, i32 16
7395
%p3 = getelementptr i8, ptr %p0, i32 24

0 commit comments

Comments
 (0)