Skip to content

Commit 9c6b56a

Browse files
committed
[AMDGPU] Add verifier for flat_scr_nase_hi read hazard
Also excludes S_MOV_B64 from the prohibited instructions as this is not required by the original ticket. We cannot fold it though anyway because of the RC mismatch, but we have some mir tests with such use.
1 parent 671a8ce commit 9c6b56a

File tree

2 files changed

+80
-1
lines changed

2 files changed

+80
-1
lines changed

llvm/lib/Target/AMDGPU/SIInstrInfo.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5808,6 +5808,18 @@ bool SIInstrInfo::verifyInstruction(const MachineInstr &MI,
58085808
}
58095809
}
58105810

5811+
if (ST.hasFlatScratchHiInB64InstHazard() && isSALU(MI) &&
5812+
MI.readsRegister(AMDGPU::SRC_FLAT_SCRATCH_BASE_HI, &RI) &&
5813+
Opcode != AMDGPU::S_MOV_B64) {
5814+
const MachineOperand *Dst = getNamedOperand(MI, AMDGPU::OpName::sdst);
5815+
if ((Dst && AMDGPU::getRegBitWidth(
5816+
*RI.getRegClassForReg(MRI, Dst->getReg())) == 64) ||
5817+
Opcode == AMDGPU::S_BITCMP0_B64 || Opcode == AMDGPU::S_BITCMP1_B64) {
5818+
ErrInfo = "Instruction cannot read flat_scratch_base_hi";
5819+
return false;
5820+
}
5821+
}
5822+
58115823
return true;
58125824
}
58135825

@@ -6259,7 +6271,8 @@ bool SIInstrInfo::isLegalRegOperand(const MachineInstr &MI, unsigned OpIdx,
62596271
return false;
62606272

62616273
if (ST.hasFlatScratchHiInB64InstHazard() &&
6262-
MO.getReg() == AMDGPU::SRC_FLAT_SCRATCH_BASE_HI && isSALU(MI)) {
6274+
MO.getReg() == AMDGPU::SRC_FLAT_SCRATCH_BASE_HI && isSALU(MI) &&
6275+
Opc != AMDGPU::S_MOV_B64) {
62636276
if (const MachineOperand *Dst = getNamedOperand(MI, AMDGPU::OpName::sdst)) {
62646277
if (AMDGPU::getRegBitWidth(*RI.getRegClassForReg(MRI, Dst->getReg())) ==
62656278
64)
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# RUN: not --crash llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1250 -verify-machineinstrs -run-pass=none -filetype=null %s 2>&1 | FileCheck %s
2+
3+
---
4+
name: salu_64_bit_inst_reads_flat_scratch_base_hi
5+
tracksRegLiveness: true
6+
body: |
7+
bb.0:
8+
9+
%0:sreg_64 = IMPLICIT_DEF
10+
$sgpr0_sgpr1 = IMPLICIT_DEF
11+
12+
; CHECK: *** Bad machine code: Instruction cannot read flat_scratch_base_hi ***
13+
; CHECK: S_ASHR_I64
14+
15+
%1:sreg_64 = S_ASHR_I64 %0:sreg_64, $src_flat_scratch_base_hi, implicit-def $scc
16+
17+
; CHECK: *** Bad machine code: Instruction cannot read flat_scratch_base_hi ***
18+
; CHECK: S_LSHL_B64
19+
20+
%2:sreg_64 = S_LSHL_B64 %0:sreg_64, $src_flat_scratch_base_hi, implicit-def $scc
21+
22+
; CHECK: *** Bad machine code: Instruction cannot read flat_scratch_base_hi ***
23+
; CHECK: S_LSHR_B64
24+
25+
%3:sreg_64 = S_LSHR_B64 %0:sreg_64, $src_flat_scratch_base_hi, implicit-def $scc
26+
27+
; CHECK: *** Bad machine code: Instruction cannot read flat_scratch_base_hi ***
28+
; CHECK: S_BFE_I64
29+
30+
%4:sreg_64 = S_BFE_I64 %0:sreg_64, $src_flat_scratch_base_hi, implicit-def $scc
31+
32+
; CHECK: *** Bad machine code: Instruction cannot read flat_scratch_base_hi ***
33+
; CHECK: S_BFE_U64
34+
35+
%5:sreg_64 = S_BFE_U64 %0:sreg_64, $src_flat_scratch_base_hi, implicit-def $scc
36+
37+
; CHECK: *** Bad machine code: Instruction cannot read flat_scratch_base_hi ***
38+
; CHECK: S_BFM_B64
39+
40+
%6:sreg_64 = S_BFM_B64 $src_flat_scratch_base_hi, 1, implicit-def $scc
41+
42+
; CHECK: *** Bad machine code: Instruction cannot read flat_scratch_base_hi ***
43+
; CHECK: S_BITCMP0_B64
44+
45+
S_BITCMP0_B64 %0:sreg_64, $src_flat_scratch_base_hi, implicit $scc, implicit-def $scc
46+
47+
; CHECK: *** Bad machine code: Instruction cannot read flat_scratch_base_hi ***
48+
; CHECK: S_BITCMP1_B64
49+
50+
S_BITCMP1_B64 %0:sreg_64, $src_flat_scratch_base_hi, implicit $scc, implicit-def $scc
51+
52+
; CHECK: *** Bad machine code: Instruction cannot read flat_scratch_base_hi ***
53+
; CHECK: S_BITREPLICATE_B64_B32
54+
55+
%7:sreg_64 = S_BITREPLICATE_B64_B32 $src_flat_scratch_base_hi, implicit-def $scc
56+
57+
; CHECK: *** Bad machine code: Instruction cannot read flat_scratch_base_hi ***
58+
; CHECK: S_BITSET0_B64
59+
60+
$sgpr0_sgpr1 = S_BITSET0_B64 $src_flat_scratch_base_hi, $sgpr0_sgpr1, implicit-def $scc
61+
62+
; CHECK: *** Bad machine code: Instruction cannot read flat_scratch_base_hi ***
63+
; CHECK: S_BITSET1_B64
64+
65+
$sgpr0_sgpr1 = S_BITSET1_B64 $src_flat_scratch_base_hi, $sgpr0_sgpr1, implicit-def $scc
66+
...

0 commit comments

Comments
 (0)