Skip to content

Commit ab91371

Browse files
authored
[AMDGPU][True16][MC] Support v_swap_b16. (#100442)
support V_SWAP_B16 true16 encoding in asm/disasm for GFX11/12 Co-authored-by: guochen2 <guochen2@amd.com>
1 parent 8d151f8 commit ab91371

9 files changed

+88
-1
lines changed

llvm/lib/Target/AMDGPU/SIInstrFormats.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,12 @@ def VOPDstOperand_t16Lo128 : VOPDstOperand <VGPR_16_Lo128> {
321321
let DecoderMethod = "DecodeVGPR_16_Lo128RegisterClass";
322322
}
323323

324+
// Source-encoded destination operand for instructions like v_swap_b16.
325+
def VOPSrcEncodedDstOperand_t16Lo128 : VOPDstOperand <VGPR_16_Lo128> {
326+
let EncoderMethod = VSrcT_b16_Lo128.EncoderMethod;
327+
let DecoderMethod = VSrcT_b16_Lo128.DecoderMethod;
328+
}
329+
324330
class VINTRPe <bits<2> op> : Enc32 {
325331
bits<8> vdst;
326332
bits<8> vsrc;

llvm/lib/Target/AMDGPU/VOP1Instructions.td

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,21 @@ def V_ACCVGPR_MOV_B32 : VOP1_Pseudo<"v_accvgpr_mov_b32", VOPProfileAccMov, [], 1
730730
let isAsCheapAsAMove = 1;
731731
}
732732

733+
def VOP_SWAP_I16 : VOPProfile_True16<VOP_I16_I16> {
734+
let Outs32 = (outs VOPDstOperand_t16Lo128:$vdst,
735+
VOPSrcEncodedDstOperand_t16Lo128:$vdst1);
736+
let Ins32 = (ins VOPSrcEncodedDstOperand_t16Lo128:$src0,
737+
VOPDstOperand_t16Lo128:$src1);
738+
let Asm32 = " $vdst, $src0";
739+
}
740+
733741
let SubtargetPredicate = isGFX11Plus in {
742+
def V_SWAP_B16 : VOP1_Pseudo<"v_swap_b16", VOP_SWAP_I16, [], /* VOP1Only= */true> {
743+
let Constraints = "$vdst = $src1, $vdst1 = $src0";
744+
let DisableEncoding = "$vdst1, $src1";
745+
let SchedRW = [Write64Bit, Write64Bit];
746+
let True16Predicate = UseRealTrue16Insts;
747+
}
734748
// Restrict src0 to be VGPR
735749
def V_PERMLANE64_B32 : VOP1_Pseudo<"v_permlane64_b32", VOP_MOVRELS,
736750
[], /*VOP1Only=*/ 1> {
@@ -953,7 +967,8 @@ defm V_CTZ_I32_B32 : VOP1_Real_FULL_with_name_gfx11_gfx12<0x03a,
953967
"V_FFBL_B32", "v_ctz_i32_b32">;
954968
defm V_CLS_I32 : VOP1_Real_FULL_with_name_gfx11_gfx12<0x03b,
955969
"V_FFBH_I32", "v_cls_i32">;
956-
defm V_PERMLANE64_B32 : VOP1Only_Real_gfx11_gfx12<0x067>;
970+
defm V_SWAP_B16 : VOP1Only_Real_gfx11_gfx12<0x066>;
971+
defm V_PERMLANE64_B32 : VOP1Only_Real_gfx11_gfx12<0x067>;
957972
defm V_MOV_B16_t16 : VOP1_Real_FULL_t16_gfx11_gfx12<0x01c, "v_mov_b16">;
958973
defm V_NOT_B16_fake16 : VOP1_Real_FULL_t16_gfx11_gfx12<0x069, "v_not_b16">;
959974
defm V_CVT_I32_I16_fake16 : VOP1_Real_FULL_t16_gfx11_gfx12<0x06a, "v_cvt_i32_i16">;

llvm/test/MC/AMDGPU/gfx10_unsupported.s

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3287,6 +3287,9 @@ v_subrev_u32_e64 v255, s[12:13], v1, v2
32873287
v_subrev_u32_sdwa v1, vcc, v2, v3 dst_sel:DWORD dst_unused:UNUSED_PAD src0_sel:WORD_1 src1_sel:BYTE_2
32883288
// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: instruction not supported on this GPU
32893289

3290+
v_swap_b16 v0.l, v0.l
3291+
// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: instruction not supported on this GPU
3292+
32903293
v_wmma_bf16_16x16x16_bf16 v[16:19], 1.0, v[8:15], v[16:19]
32913294
// CHECK: :[[@LINE-1]]:{{[0-9]+}}: error: instruction not supported on this GPU
32923295

llvm/test/MC/AMDGPU/gfx11_asm_vop1.s

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3448,6 +3448,15 @@ v_sqrt_f64 v[5:6], src_scc
34483448
v_sqrt_f64 v[254:255], 0xaf123456
34493449
// GFX11: encoding: [0xff,0x68,0xfc,0x7f,0x56,0x34,0x12,0xaf]
34503450

3451+
v_swap_b16 v5.l, v1.h
3452+
// GFX11: encoding: [0x81,0xcd,0x0a,0x7e]
3453+
3454+
v_swap_b16 v5.h, v1.l
3455+
// GFX11: encoding: [0x01,0xcd,0x0a,0x7f]
3456+
3457+
v_swap_b16 v127.l, v127.l
3458+
// GFX11: encoding: [0x7f,0xcd,0xfe,0x7e]
3459+
34513460
v_swap_b32 v5, v1
34523461
// GFX11: encoding: [0x01,0xcb,0x0a,0x7e]
34533462

llvm/test/MC/AMDGPU/gfx11_asm_vop1_t16_err.s

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,18 @@ v_sqrt_f16_e32 v255.l, v1.l
211211
v_sqrt_f16_e32 v5.l, v199.l
212212
// GFX11: :[[@LINE-1]]:{{[0-9]+}}: error: invalid operand for instruction
213213

214+
v_swap_b16_e32 v128.l, v0.l
215+
// GFX11: :[[@LINE-1]]:{{[0-9]+}}: error: invalid operand for instruction
216+
217+
v_swap_b16_e32 v0.l, s0
218+
// GFX11: :[[@LINE-1]]:{{[0-9]+}}: error: invalid operand for instruction
219+
220+
v_swap_b16_e32 v0.l, 0
221+
// GFX11: :[[@LINE-1]]:{{[0-9]+}}: error: invalid operand for instruction
222+
223+
v_swap_b16_e32 v0.l, 0xfe0b
224+
// GFX11: :[[@LINE-1]]:{{[0-9]+}}: error: invalid operand for instruction
225+
214226
v_trunc_f16_e32 v128, 0xfe0b
215227
// GFX11: :[[@LINE-1]]:{{[0-9]+}}: error: operands are not valid for this GPU or mode
216228

llvm/test/MC/AMDGPU/gfx12_asm_vop1.s

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3460,6 +3460,15 @@ v_sqrt_f64 v[5:6], src_scc
34603460
v_sqrt_f64 v[254:255], 0xaf123456
34613461
// GFX12: v_sqrt_f64_e32 v[254:255], 0xaf123456 ; encoding: [0xff,0x68,0xfc,0x7f,0x56,0x34,0x12,0xaf]
34623462

3463+
v_swap_b16 v5.l, v1.h
3464+
// GFX12: v_swap_b16 v5.l, v1.h ; encoding: [0x81,0xcd,0x0a,0x7e]
3465+
3466+
v_swap_b16 v5.h, v1.l
3467+
// GFX12: v_swap_b16 v5.h, v1.l ; encoding: [0x01,0xcd,0x0a,0x7f]
3468+
3469+
v_swap_b16 v127.l, v127.l
3470+
// GFX12: v_swap_b16 v127.l, v127.l ; encoding: [0x7f,0xcd,0xfe,0x7e]
3471+
34633472
v_swap_b32 v5, v1
34643473
// GFX12: v_swap_b32 v5, v1 ; encoding: [0x01,0xcb,0x0a,0x7e]
34653474

llvm/test/MC/AMDGPU/gfx12_asm_vop1_t16_err.s

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,21 @@ v_sqrt_f16_e32 v255, v1
201201
v_sqrt_f16_e32 v5, v199
202202
// GFX12: :[[@LINE-1]]:{{[0-9]+}}: error: operands are not valid for this GPU or mode
203203

204+
v_swap_b16_e32 v128.l, v0.l
205+
// GFX12: :[[@LINE-1]]:{{[0-9]+}}: error: invalid operand for instruction
206+
207+
v_swap_b16_e32 v0.l, v255.l
208+
// GFX12: :[[@LINE-1]]:{{[0-9]+}}: error: invalid operand for instruction
209+
210+
v_swap_b16_e32 v0.l, s0
211+
// GFX12: :[[@LINE-1]]:{{[0-9]+}}: error: invalid operand for instruction
212+
213+
v_swap_b16_e32 v0.l, 0
214+
// GFX12: :[[@LINE-1]]:{{[0-9]+}}: error: invalid operand for instruction
215+
216+
v_swap_b16_e32 v0.l, 0xfe0b
217+
// GFX12: :[[@LINE-1]]:{{[0-9]+}}: error: invalid operand for instruction
218+
204219
v_trunc_f16_e32 v128, 0xfe0b
205220
// GFX12: :[[@LINE-1]]:{{[0-9]+}}: error: operands are not valid for this GPU or mode
206221

llvm/test/MC/Disassembler/AMDGPU/decode-err.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@
1919
# W64: [[@LINE+1]]:1: warning: invalid instruction encoding
2020
0xff,0x04,0x02,0xc9,0x03,0x03,0x06,0x05,0x56,0x34,0x12,0xaf
2121

22+
# GFX11: v_swap_b16 v5.h, s1/*Invalid register, operand has 'VGPR_16_Lo128' register class*/ ; encoding: [0x01,0xcc,0x0a,0x7f]
23+
# GFX12: v_swap_b16 v5.h, s1/*Invalid register, operand has 'VGPR_16_Lo128' register class*/ ; encoding: [0x01,0xcc,0x0a,0x7f]
24+
0x01,0xcc,0x0a,0x7f
25+
26+
# GFX11: v_swap_b16 v5.h, 0x3c00/*Invalid immediate*/ ; encoding: [0x00,0xcc,0x0a,0x7f]
27+
# GFX12: v_swap_b16 v5.h, 0x3c00/*Invalid immediate*/ ; encoding: [0x00,0xcc,0x0a,0x7f]
28+
0xf2,0xcc,0x0a,0x7f
29+
30+
# GFX11: v_swap_b16 v5.h, 0x78563412/*Invalid immediate*/ ; encoding: [0x12,0xcc,0x0a,0x7f]
31+
# GFX12: v_swap_b16 v5.h, 0x78563412/*Invalid immediate*/ ; encoding: [0x12,0xcc,0x0a,0x7f]
32+
0xff,0xcc,0x0a,0x7f,0x12,0x34,0x56,0x78
33+
2234
# W32: v_wmma_f32_16x16x16_f16 v[16:23], v[0:7], v[8:15], v[16:23] ; encoding: [0x10,0x40,0x40,0xcc,0x00,0x11,0x42,0x1c]
2335
# W64: v_wmma_f32_16x16x16_f16 v[16:19], v[0:7], v[8:15], v[16:19] ; encoding: [0x10,0x40,0x40,0xcc,0x00,0x11,0x42,0x1c]
2436
0x10,0x40,0x40,0xcc,0x00,0x11,0x42,0x1c

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3344,6 +3344,12 @@
33443344
# GFX11: v_sqrt_f64_e32 v[254:255], 0xaf123456 ; encoding: [0xff,0x68,0xfc,0x7f,0x56,0x34,0x12,0xaf]
33453345
0xff,0x68,0xfc,0x7f,0x56,0x34,0x12,0xaf
33463346

3347+
# GFX11-TRUE16: v_swap_b16 v5.l, v1.h ; encoding: [0x81,0xcd,0x0a,0x7e]
3348+
0x81,0xcd,0x0a,0x7e
3349+
3350+
# GFX11-TRUE16: v_swap_b16 v5.h, v1.l ; encoding: [0x01,0xcd,0x0a,0x7f]
3351+
0x01,0xcd,0x0a,0x7f
3352+
33473353
# GFX11: v_swap_b32 v5, v1 ; encoding: [0x01,0xcb,0x0a,0x7e]
33483354
0x01,0xcb,0x0a,0x7e
33493355

0 commit comments

Comments
 (0)