Skip to content

Commit 341991f

Browse files
rampitecadilad
authored andcommitted
[AMDGPU] Allow accvgpr_read/write decode with opsel
These two instructions are VOP3P and have op_sel_hi bits, however do not use op_sel_hi. That is recommended to set unused op_sel_hi bits to 1. However, we cannot decode both representations with 1 and 0 if bits are set to default value 1. If bits are set to be ignored with '?' initializer then encoding defaults them to 0. The patch is a hack to force ignored '?' bits to 1 on encoding for these instructions. There is still canonicalization happens on disasm print if incoming values are non-default, so that disasm output does not match binary input, but this is pre-existing problem for all instructions with '?' bits. Fixes: SWDEV-272540 Differential Revision: https://reviews.llvm.org/D96543 Change-Id: Ia04210f5fe352c1a69970c2fa94c0c48632716df
1 parent 0bebc94 commit 341991f

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

llvm/lib/Target/AMDGPU/MCTargetDesc/SIMCCodeEmitter.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,20 @@ void SIMCCodeEmitter::encodeInstruction(const MCInst &MI, raw_ostream &OS,
298298
const MCInstrDesc &Desc = MCII.get(MI.getOpcode());
299299
unsigned bytes = Desc.getSize();
300300

301+
switch (MI.getOpcode()) {
302+
case AMDGPU::V_ACCVGPR_READ_B32_vi:
303+
case AMDGPU::V_ACCVGPR_WRITE_B32_vi:
304+
// Set unused op_sel_hi bits to 1.
305+
// FIXME: This shall be done for all VOP3P but not MAI instructions with
306+
// unused op_sel_hi bits if corresponding operands do not exist.
307+
// accvgpr_read/write are different, however. These are VOP3P, MAI, have
308+
// src0, but do not use op_sel.
309+
Encoding |= (1ul << 14) | (1ul << 59) | (1ul << 60);
310+
break;
311+
default:
312+
break;
313+
}
314+
301315
for (unsigned i = 0; i < bytes; i++) {
302316
OS.write((uint8_t) ((Encoding >> (8 * i)) & 0xff));
303317
}

llvm/lib/Target/AMDGPU/VOP3PInstructions.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,9 @@ multiclass VOP3P_Real_MAI<bits<7> op> {
431431
VOP3Pe_MAI <op, !cast<VOP3_Pseudo>(NAME).Pfl> {
432432
let AssemblerPredicate = HasMAIInsts;
433433
let DecoderNamespace = "GFX8";
434-
let Inst{14} = 1; // op_sel_hi(2) default value
435-
let Inst{59} = 1; // op_sel_hi(0) default value
436-
let Inst{60} = 1; // op_sel_hi(1) default value
434+
let Inst{14} = ?; // op_sel_hi(2)
435+
let Inst{59} = ?; // op_sel_hi(0)
436+
let Inst{60} = ?; // op_sel_hi(1)
437437
}
438438
}
439439

llvm/test/MC/Disassembler/AMDGPU/mai.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
# GFX908: v_accvgpr_read_b32 v2, a0 ; encoding: [0x02,0x40,0xd8,0xd3,0x00,0x01,0x00,0x18]
44
0x02,0x40,0xd8,0xd3,0x00,0x01,0x00,0x18
55

6+
# Check the alternative encoding with unused op_sel_hi bits set to zero
7+
# and not to default 1 is accepted.
8+
#
9+
# FIXME: Encoding is canonicalized when printing. It is valid but encoding
10+
# bits are not the same as in input.
11+
12+
# GFX908: v_accvgpr_read_b32 v2, a0 ; encoding: [0x02,0x40,0xd8,0xd3,0x00,0x01,0x00,0x18]
13+
0x02,0x00,0xd8,0xd3,0x00,0x01,0x00,0x00
14+
615
# GFX908: v_accvgpr_read_b32 v2, a1 ; encoding: [0x02,0x40,0xd8,0xd3,0x01,0x01,0x00,0x18]
716
0x02,0x40,0xd8,0xd3,0x01,0x01,0x00,0x18
817

@@ -18,6 +27,15 @@
1827
# GFX908: v_accvgpr_write_b32 a2, v1 ; encoding: [0x02,0x40,0xd9,0xd3,0x01,0x01,0x00,0x18]
1928
0x02,0x40,0xd9,0xd3,0x01,0x01,0x00,0x18
2029

30+
# Check the alternative encoding with unused op_sel_hi bits set to zero
31+
# and not to default 1 is accepted.
32+
#
33+
# FIXME: Encoding is canonicalized when printing. It is valid but encoding
34+
# bits are not the same as in input.
35+
36+
# GFX908: v_accvgpr_write_b32 a2, v1 ; encoding: [0x02,0x40,0xd9,0xd3,0x01,0x01,0x00,0x18]
37+
0x02,0x00,0xd9,0xd3,0x01,0x01,0x00,0x00
38+
2139
# GFX908: v_mfma_f32_32x32x1f32 a[0:31], v0, v1, a[1:32] ; encoding: [0x00,0x00,0xc0,0xd3,0x00,0x03,0x06,0x04]
2240
0x00,0x00,0xc0,0xd3,0x00,0x03,0x06,0x04
2341

0 commit comments

Comments
 (0)