Skip to content

Commit 020fefb

Browse files
authored
AMDGPU: Avoid report_fatal_error in image intrinsic lowering (#145201)
1 parent 75de95d commit 020fefb

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

llvm/lib/Target/AMDGPU/SIISelLowering.cpp

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8736,11 +8736,15 @@ SDValue SITargetLowering::lowerImage(SDValue Op,
87368736
: False);
87378737
if (IsGFX10Plus)
87388738
Ops.push_back(IsA16 ? True : False);
8739-
if (!Subtarget->hasGFX90AInsts()) {
8739+
8740+
if (!Subtarget->hasGFX90AInsts())
87408741
Ops.push_back(TFE); // tfe
8741-
} else if (TFE->getAsZExtVal()) {
8742-
report_fatal_error("TFE is not supported on this GPU");
8742+
else if (TFE->getAsZExtVal()) {
8743+
DAG.getContext()->diagnose(DiagnosticInfoUnsupported(
8744+
DAG.getMachineFunction().getFunction(),
8745+
"TFE is not supported on this GPU", DL.getDebugLoc()));
87438746
}
8747+
87448748
if (!IsGFX12Plus || BaseOpcode->Sampler || BaseOpcode->MSAA)
87458749
Ops.push_back(LWE); // lwe
87468750
if (!IsGFX10Plus)
@@ -8771,9 +8775,23 @@ SDValue SITargetLowering::lowerImage(SDValue Op,
87718775
if (Subtarget->hasGFX90AInsts()) {
87728776
Opcode = AMDGPU::getMIMGOpcode(IntrOpcode, AMDGPU::MIMGEncGfx90a,
87738777
NumVDataDwords, NumVAddrDwords);
8774-
if (Opcode == -1)
8775-
report_fatal_error(
8776-
"requested image instruction is not supported on this GPU");
8778+
if (Opcode == -1) {
8779+
DAG.getContext()->diagnose(DiagnosticInfoUnsupported(
8780+
DAG.getMachineFunction().getFunction(),
8781+
"requested image instruction is not supported on this GPU",
8782+
DL.getDebugLoc()));
8783+
8784+
unsigned Idx = 0;
8785+
SmallVector<SDValue, 3> RetValues(OrigResultTypes.size());
8786+
for (EVT VT : OrigResultTypes) {
8787+
if (VT == MVT::Other)
8788+
RetValues[Idx++] = Op.getOperand(0); // Chain
8789+
else
8790+
RetValues[Idx++] = DAG.getPOISON(VT);
8791+
}
8792+
8793+
return DAG.getMergeValues(RetValues, DL);
8794+
}
87778795
}
87788796
if (Opcode == -1 &&
87798797
Subtarget->getGeneration() >= AMDGPUSubtarget::VOLCANIC_ISLANDS)

llvm/test/CodeGen/AMDGPU/unsupported-image-sample.ll

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
; RUN: llc -O0 -mtriple=amdgcn -mcpu=gfx906 -verify-machineinstrs < %s | FileCheck -check-prefixes=GFX9 %s
22
; RUN: llc -O0 -mtriple=amdgcn -mcpu=gfx908 -verify-machineinstrs < %s | FileCheck -check-prefixes=GFX9 %s
33
; RUN: llc -O0 -mtriple=amdgcn -mcpu=gfx9-generic --amdhsa-code-object-version=6 -verify-machineinstrs < %s | FileCheck -check-prefixes=GFX9 %s
4-
; RUN: not --crash llc -O0 -mtriple=amdgcn -mcpu=gfx90a -verify-machineinstrs < %s 2>&1 | FileCheck -check-prefixes=GFX90A %s
5-
; RUN: not --crash llc -O0 -mtriple=amdgcn -mcpu=gfx942 -verify-machineinstrs < %s 2>&1 | FileCheck -check-prefixes=GFX942 %s
4+
; RUN: not llc -O0 -mtriple=amdgcn -mcpu=gfx90a -verify-machineinstrs < %s 2>&1 | FileCheck -check-prefixes=GFX90A %s
5+
; RUN: not llc -O0 -mtriple=amdgcn -mcpu=gfx942 -verify-machineinstrs < %s 2>&1 | FileCheck -check-prefixes=GFX942 %s
66
; RUN: llc -O0 -mtriple=amdgcn -mcpu=gfx1030 -verify-machineinstrs < %s | FileCheck -check-prefixes=GFX1030 %s
77
; RUN: llc -O0 -mtriple=amdgcn -mcpu=gfx1100 -verify-machineinstrs < %s | FileCheck -check-prefixes=GFX1100 %s
88

99
; GFX9-LABEL: image_sample_test:
1010
; GFX9: image_sample_lz
1111

12-
; GFX90A: LLVM ERROR: requested image instruction is not supported on this GPU
13-
14-
; GFX942: LLVM ERROR: requested image instruction is not supported on this GPU
12+
; GFX90A: error: <unknown>:0:0: in function image_sample_test void (ptr addrspace(1), float, float, <8 x i32>, <4 x i32>): requested image instruction is not supported on this GPU
13+
; GFX942: error: <unknown>:0:0: in function image_sample_test void (ptr addrspace(1), float, float, <8 x i32>, <4 x i32>): requested image instruction is not supported on this GPU
1514

1615
; GFX1030-LABEL: image_sample_test:
1716
; GFX1030: image_sample_lz
@@ -28,3 +27,13 @@ define amdgpu_kernel void @image_sample_test(ptr addrspace(1) %out, float %arg1,
2827
}
2928

3029
declare <4 x float> @llvm.amdgcn.image.sample.lz.2d.v4f32.f32(i32 immarg, float, float, <8 x i32>, <4 x i32>, i1 immarg, i32 immarg, i32 immarg)
30+
31+
; GFX90A: error: <unknown>:0:0: in function sample_1d_tfe <4 x float> (<8 x i32>, <4 x i32>, ptr addrspace(1), float): TFE is not supported on this GPU
32+
; GFX942: error: <unknown>:0:0: in function sample_1d_tfe <4 x float> (<8 x i32>, <4 x i32>, ptr addrspace(1), float): TFE is not supported on this GPU
33+
define <4 x float> @sample_1d_tfe(<8 x i32> inreg %rsrc, <4 x i32> inreg %samp, ptr addrspace(1) inreg %out, float %s) {
34+
%v = call {<4 x float>,i32} @llvm.amdgcn.image.sample.1d.v4f32i32.f32(i32 15, float %s, <8 x i32> %rsrc, <4 x i32> %samp, i1 0, i32 1, i32 0)
35+
%v.vec = extractvalue {<4 x float>, i32} %v, 0
36+
%v.err = extractvalue {<4 x float>, i32} %v, 1
37+
store i32 %v.err, ptr addrspace(1) %out, align 4
38+
ret <4 x float> %v.vec
39+
}

0 commit comments

Comments
 (0)