Skip to content

Commit ed155ff

Browse files
authored
AMDGPU: Avoid report_fatal_error on ds ordered intrinsics (#145202)
1 parent c716558 commit ed155ff

File tree

3 files changed

+62
-12
lines changed

3 files changed

+62
-12
lines changed

llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,8 +1767,12 @@ bool AMDGPUInstructionSelector::selectDSOrderedIntrinsic(
17671767
bool WaveRelease = MI.getOperand(8).getImm() != 0;
17681768
bool WaveDone = MI.getOperand(9).getImm() != 0;
17691769

1770-
if (WaveDone && !WaveRelease)
1771-
report_fatal_error("ds_ordered_count: wave_done requires wave_release");
1770+
if (WaveDone && !WaveRelease) {
1771+
// TODO: Move this to IR verifier
1772+
const Function &Fn = MF->getFunction();
1773+
Fn.getContext().diagnose(DiagnosticInfoUnsupported(
1774+
Fn, "ds_ordered_count: wave_done requires wave_release", DL));
1775+
}
17721776

17731777
unsigned OrderedCountIndex = IndexOperand & 0x3f;
17741778
IndexOperand &= ~0x3f;
@@ -1779,13 +1783,18 @@ bool AMDGPUInstructionSelector::selectDSOrderedIntrinsic(
17791783
IndexOperand &= ~(0xf << 24);
17801784

17811785
if (CountDw < 1 || CountDw > 4) {
1782-
report_fatal_error(
1783-
"ds_ordered_count: dword count must be between 1 and 4");
1786+
const Function &Fn = MF->getFunction();
1787+
Fn.getContext().diagnose(DiagnosticInfoUnsupported(
1788+
Fn, "ds_ordered_count: dword count must be between 1 and 4", DL));
1789+
CountDw = 1;
17841790
}
17851791
}
17861792

1787-
if (IndexOperand)
1788-
report_fatal_error("ds_ordered_count: bad index operand");
1793+
if (IndexOperand) {
1794+
const Function &Fn = MF->getFunction();
1795+
Fn.getContext().diagnose(DiagnosticInfoUnsupported(
1796+
Fn, "ds_ordered_count: bad index operand", DL));
1797+
}
17891798

17901799
unsigned Instruction = IntrID == Intrinsic::amdgcn_ds_ordered_add ? 0 : 1;
17911800
unsigned ShaderType = SIInstrInfo::getDSShaderTypeValue(*MF);

llvm/lib/Target/AMDGPU/SIISelLowering.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9330,16 +9330,27 @@ SDValue SITargetLowering::LowerINTRINSIC_W_CHAIN(SDValue Op,
93309330
IndexOperand &= ~(0xf << 24);
93319331

93329332
if (CountDw < 1 || CountDw > 4) {
9333-
report_fatal_error(
9334-
"ds_ordered_count: dword count must be between 1 and 4");
9333+
const Function &Fn = DAG.getMachineFunction().getFunction();
9334+
DAG.getContext()->diagnose(DiagnosticInfoUnsupported(
9335+
Fn, "ds_ordered_count: dword count must be between 1 and 4",
9336+
DL.getDebugLoc()));
9337+
CountDw = 1;
93359338
}
93369339
}
93379340

9338-
if (IndexOperand)
9339-
report_fatal_error("ds_ordered_count: bad index operand");
9341+
if (IndexOperand) {
9342+
const Function &Fn = DAG.getMachineFunction().getFunction();
9343+
DAG.getContext()->diagnose(DiagnosticInfoUnsupported(
9344+
Fn, "ds_ordered_count: bad index operand", DL.getDebugLoc()));
9345+
}
93409346

9341-
if (WaveDone && !WaveRelease)
9342-
report_fatal_error("ds_ordered_count: wave_done requires wave_release");
9347+
if (WaveDone && !WaveRelease) {
9348+
// TODO: Move this to IR verifier
9349+
const Function &Fn = DAG.getMachineFunction().getFunction();
9350+
DAG.getContext()->diagnose(DiagnosticInfoUnsupported(
9351+
Fn, "ds_ordered_count: wave_done requires wave_release",
9352+
DL.getDebugLoc()));
9353+
}
93439354

93449355
unsigned Instruction = IntrID == Intrinsic::amdgcn_ds_ordered_add ? 0 : 1;
93459356
unsigned ShaderType =
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
; RUN: not llc -global-isel=0 -mtriple=amdgcn -mcpu=gfx1010 -filetype=null %s 2>&1 | FileCheck %s
2+
; RUN: not llc -global-isel=1 -mtriple=amdgcn -mcpu=gfx1010 -filetype=null %s 2>&1 | FileCheck %s
3+
4+
; CHECK: error: <unknown>:0:0: in function ds_ordered_add_dword_count_too_low void (ptr addrspace(2), ptr addrspace(1)): ds_ordered_count: dword count must be between 1 and 4
5+
define amdgpu_kernel void @ds_ordered_add_dword_count_too_low(ptr addrspace(2) inreg %gds, ptr addrspace(1) %out) {
6+
%val = call i32 @llvm.amdgcn.ds.ordered.add(ptr addrspace(2) %gds, i32 31, i32 0, i32 0, i1 false, i32 0, i1 true, i1 true)
7+
store i32 %val, ptr addrspace(1) %out
8+
ret void
9+
}
10+
11+
; CHECK: error: <unknown>:0:0: in function ds_ordered_add_dword_count_too_high void (ptr addrspace(2), ptr addrspace(1)): ds_ordered_count: dword count must be between 1 and 4
12+
define amdgpu_kernel void @ds_ordered_add_dword_count_too_high(ptr addrspace(2) inreg %gds, ptr addrspace(1) %out) {
13+
%val = call i32 @llvm.amdgcn.ds.ordered.add(ptr addrspace(2) %gds, i32 31, i32 0, i32 0, i1 false, i32 5, i1 true, i1 true)
14+
store i32 %val, ptr addrspace(1) %out
15+
ret void
16+
}
17+
18+
; CHECK: error: <unknown>:0:0: in function ds_ordered_add_bad_index_operand void (ptr addrspace(2), ptr addrspace(1)): ds_ordered_count: bad index operand
19+
define amdgpu_kernel void @ds_ordered_add_bad_index_operand(ptr addrspace(2) inreg %gds, ptr addrspace(1) %out) {
20+
%val = call i32 @llvm.amdgcn.ds.ordered.add(ptr addrspace(2) %gds, i32 31, i32 0, i32 1, i1 false, i32 -1, i1 true, i1 true)
21+
store i32 %val, ptr addrspace(1) %out
22+
ret void
23+
}
24+
25+
; CHECK: error: <unknown>:0:0: in function ds_ordered_add_dword_count_wave_done_without_wave_release void (ptr addrspace(2), ptr addrspace(1)): ds_ordered_count: wave_done requires wave_release
26+
define amdgpu_kernel void @ds_ordered_add_dword_count_wave_done_without_wave_release(ptr addrspace(2) inreg %gds, ptr addrspace(1) %out) {
27+
%val = call i32 @llvm.amdgcn.ds.ordered.add(ptr addrspace(2) %gds, i32 31, i32 0, i32 0, i1 false, i32 1, i1 false, i1 true)
28+
store i32 %val, ptr addrspace(1) %out
29+
ret void
30+
}

0 commit comments

Comments
 (0)