Skip to content

Commit 41faaac

Browse files
committed
[SPIR-V] Fix emit intrinsic for resource type
This is a quick fix to make progress to the backend until we get a proper type scavenging system. The previous code was only checking the type if the resource was used once. Slightly changed the code to look to all usages, and get the first type. This will certainly break in other cases, but it allows us to move forward for now until we rewrite the type scavenging to handle untyped GEP/ptradd correctly. Related to #145002
1 parent 2147e29 commit 41faaac

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -665,10 +665,10 @@ Type *SPIRVEmitIntrinsics::deduceElementTypeHelper(
665665
auto *HandleType = cast<TargetExtType>(II->getOperand(0)->getType());
666666
if (HandleType->getTargetExtName() == "spirv.Image" ||
667667
HandleType->getTargetExtName() == "spirv.SignedImage") {
668-
if (II->hasOneUse()) {
669-
auto *U = *II->users().begin();
668+
for (User *U : II->users()) {
670669
Ty = cast<Instruction>(U)->getAccessType();
671-
assert(Ty && "Unable to get type for resource pointer.");
670+
if (Ty)
671+
break;
672672
}
673673
} else if (HandleType->getTargetExtName() == "spirv.VulkanBuffer") {
674674
// This call is supposed to index into an array
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc -verify-machineinstrs -O3 -mtriple=spirv1.6-unknown-vulkan1.3-compute %s -o - | FileCheck %s --match-full-lines
3+
; RUN: %if spirv-tools %{ llc -O3 -mtriple=spirv1.6-unknown-vulkan1.3-compute %s -o - -filetype=obj | spirv-val %}
4+
5+
@.str = private unnamed_addr constant [7 x i8] c"buffer\00", align 1
6+
7+
define void @main() "hlsl.shader"="pixel" {
8+
; CHECK: %25 = OpFunction %2 None %3 ; -- Begin function main
9+
; CHECK-NEXT: %1 = OpLabel
10+
; CHECK-NEXT: %26 = OpVariable %14 Function %23
11+
; CHECK-NEXT: %27 = OpLoad %7 %24
12+
; CHECK-NEXT: %28 = OpImageRead %5 %27 %16
13+
; CHECK-NEXT: %29 = OpCompositeExtract %4 %28 0
14+
; CHECK-NEXT: %30 = OpCompositeExtract %4 %28 1
15+
; CHECK-NEXT: %31 = OpFAdd %4 %30 %29
16+
; CHECK-NEXT: %32 = OpCompositeInsert %5 %31 %28 0
17+
; CHECK-NEXT: %33 = OpLoad %7 %24
18+
; CHECK-NEXT: OpImageWrite %33 %16 %32
19+
; CHECK-NEXT: OpReturn
20+
; CHECK-NEXT: OpFunctionEnd
21+
entry:
22+
%0 = tail call target("spirv.Image", float, 5, 2, 0, 0, 2, 0) @llvm.spv.resource.handlefrombinding.tspirv.Image_f32_5_2_0_0_2_0t(i32 0, i32 0, i32 1, i32 0, i1 false, ptr nonnull @.str)
23+
%1 = tail call noundef align 16 dereferenceable(16) ptr addrspace(11) @llvm.spv.resource.getpointer.p11.tspirv.Image_f32_5_2_0_0_2_0t(target("spirv.Image", float, 5, 2, 0, 0, 2, 0) %0, i32 0)
24+
%2 = load <4 x float>, ptr addrspace(11) %1, align 16
25+
%3 = extractelement <4 x float> %2, i64 0
26+
%4 = extractelement <4 x float> %2, i64 1
27+
%add.i = fadd reassoc nnan ninf nsz arcp afn float %4, %3
28+
%5 = insertelement <4 x float> %2, float %add.i, i64 0
29+
store <4 x float> %5, ptr addrspace(11) %1, align 16
30+
ret void
31+
}
32+
33+
; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(none)
34+
declare target("spirv.Image", float, 5, 2, 0, 0, 2, 0) @llvm.spv.resource.handlefrombinding.tspirv.Image_f32_5_2_0_0_2_0t(i32, i32, i32, i32, i1, ptr) #0
35+
36+
; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(none)
37+
declare ptr addrspace(11) @llvm.spv.resource.getpointer.p11.tspirv.Image_f32_5_2_0_0_2_0t(target("spirv.Image", float, 5, 2, 0, 0, 2, 0), i32) #0
38+
39+
attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(none) }

0 commit comments

Comments
 (0)