Skip to content

Commit 2a3f72e

Browse files
authored
[AMDGPU][CodeGen][True16] Correct size calculation for d16 insts (llvm#151042)
D16 pesudo instructions are introduced in true16 mode to represet a D16 load/store. In MC lowering, the pesudo instructions are lowered to the corresponding D16 Lo/Hi MC Inst respecting the register allocation. However, the pesudo instruction has size 0 and cause an issue in the Inst size estimation. Use D16 Lo when calculating inst size
1 parent a3228b6 commit 2a3f72e

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

llvm/lib/Target/AMDGPU/SIInstrInfo.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9281,6 +9281,16 @@ unsigned SIInstrInfo::getInstSizeInBytes(const MachineInstr &MI) const {
92819281
default:
92829282
if (MI.isMetaInstruction())
92839283
return 0;
9284+
9285+
// If D16 Pseudo inst, get correct MC code size
9286+
const auto *D16Info = AMDGPU::getT16D16Helper(Opc);
9287+
if (D16Info) {
9288+
// Assume d16_lo/hi inst are always in same size
9289+
unsigned LoInstOpcode = D16Info->LoOp;
9290+
const MCInstrDesc &Desc = getMCOpcodeFromPseudo(LoInstOpcode);
9291+
DescSize = Desc.getSize();
9292+
}
9293+
92849294
return DescSize;
92859295
}
92869296
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc -mtriple=amdgcn -mcpu=gfx1100 -amdgpu-s-branch-bits=4 -mattr=+real-true16 < %s | FileCheck -enable-var-scope -check-prefixes=GFX11 %s
3+
4+
; Make sure the inst size estimate for D16 pseudo insts are not 0
5+
6+
define amdgpu_kernel void @long_forward_branch_gfx11plus(ptr addrspace(1) %in, ptr addrspace(1) %out, i32 %cnd) #0 {
7+
; GFX11-LABEL: long_forward_branch_gfx11plus:
8+
; GFX11: ; %bb.0: ; %bb0
9+
; GFX11-NEXT: s_load_b32 s0, s[4:5], 0x34
10+
; GFX11-NEXT: s_waitcnt lgkmcnt(0)
11+
; GFX11-NEXT: s_cmp_eq_u32 s0, 0
12+
; GFX11-NEXT: s_cbranch_scc0 .LBB0_1
13+
; GFX11-NEXT: ; %bb.3: ; %bb0
14+
; GFX11-NEXT: s_getpc_b64 s[6:7]
15+
; GFX11-NEXT: .Lpost_getpc0:
16+
; GFX11-NEXT: s_add_u32 s6, s6, (.LBB0_2-.Lpost_getpc0)&4294967295
17+
; GFX11-NEXT: s_addc_u32 s7, s7, (.LBB0_2-.Lpost_getpc0)>>32
18+
; GFX11-NEXT: s_setpc_b64 s[6:7]
19+
; GFX11-NEXT: .LBB0_1: ; %bb2
20+
; GFX11-NEXT: s_load_b128 s[0:3], s[4:5], 0x24
21+
; GFX11-NEXT: v_mov_b32_e32 v1, 0
22+
; GFX11-NEXT: s_waitcnt lgkmcnt(0)
23+
; GFX11-NEXT: s_clause 0x1
24+
; GFX11-NEXT: global_load_d16_b16 v0, v1, s[0:1]
25+
; GFX11-NEXT: global_load_d16_hi_b16 v0, v1, s[0:1] offset:2
26+
; GFX11-NEXT: s_waitcnt vmcnt(1)
27+
; GFX11-NEXT: global_store_b16 v1, v0, s[2:3]
28+
; GFX11-NEXT: s_waitcnt vmcnt(0)
29+
; GFX11-NEXT: global_store_d16_hi_b16 v1, v0, s[2:3] offset:2
30+
; GFX11-NEXT: .LBB0_2: ; %bb3
31+
; GFX11-NEXT: s_endpgm
32+
bb0:
33+
;%idx = call i32 @llvm.amdgcn.workitem.id.x()
34+
%gep0 = getelementptr inbounds i16, ptr addrspace(1) %in, i32 0
35+
%gep1 = getelementptr inbounds i16, ptr addrspace(1) %in, i32 1
36+
%out0 = getelementptr inbounds i16, ptr addrspace(1) %out, i32 0
37+
%out1 = getelementptr inbounds i16, ptr addrspace(1) %out, i32 1
38+
%cmp = icmp eq i32 %cnd, 0
39+
br i1 %cmp, label %bb3, label %bb2 ; +9 dword branch
40+
bb2:
41+
; Estimated as 32-bytes on gfx11 (requiring a long branch)
42+
%load0 = load i16, ptr addrspace(1) %gep0
43+
%load1 = load i16, ptr addrspace(1) %gep1
44+
store i16 %load0, ptr addrspace(1) %out0
45+
store i16 %load1, ptr addrspace(1) %out1
46+
br label %bb3
47+
bb3:
48+
ret void
49+
}
50+
51+
declare i32 @llvm.amdgcn.workitem.id.x() #1

0 commit comments

Comments
 (0)