xref: /llvm-project/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/SV_DispatchThreadID.ll (revision cf3d6fded9eaf1372ccfde1d49dd91df6762d98c)
1; RUN: llc -O0 -verify-machineinstrs -mtriple=spirv-vulkan-unknown %s -o - | FileCheck %s
2; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-vulkan-unknown %s -o - -filetype=obj | spirv-val %}
3
4; This file generated from the following command:
5; clang -cc1 -triple spirv-vulkan-library -x hlsl -emit-llvm -disable-llvm-passes -finclude-default-header - -o - <<EOF
6; [shader("compute")]
7; [numthreads(1,1,1)]
8; void main(uint3 ID : SV_DispatchThreadID) {}
9; EOF
10
11; CHECK-DAG:        %[[#int:]] = OpTypeInt 32 0
12; CHECK-DAG:        %[[#v3int:]] = OpTypeVector %[[#int]] 3
13; CHECK-DAG:        %[[#ptr_Input_v3int:]] = OpTypePointer Input %[[#v3int]]
14; CHECK-DAG:        %[[#tempvar:]] = OpUndef %[[#v3int]]
15; CHECK-DAG:        %[[#GlobalInvocationId:]] = OpVariable %[[#ptr_Input_v3int]] Input
16
17; CHECK-DAG:        OpEntryPoint GLCompute {{.*}} %[[#GlobalInvocationId]]
18; CHECK-DAG:        OpName %[[#GlobalInvocationId]] "__spirv_BuiltInGlobalInvocationId"
19; CHECK-DAG:        OpDecorate %[[#GlobalInvocationId]] LinkageAttributes "__spirv_BuiltInGlobalInvocationId" Import
20; CHECK-DAG:        OpDecorate %[[#GlobalInvocationId]] BuiltIn GlobalInvocationId
21
22; ModuleID = '-'
23source_filename = "-"
24target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
25target triple = "spirv-unknown-vulkan-library"
26
27; Function Attrs: noinline norecurse nounwind optnone
28define internal spir_func void @main(<3 x i32> noundef %ID) #0 {
29entry:
30  %ID.addr = alloca <3 x i32>, align 16
31  store <3 x i32> %ID, ptr %ID.addr, align 16
32  ret void
33}
34
35; Function Attrs: norecurse
36define void @main.1() #1 {
37entry:
38
39; CHECK:        %[[#load:]] = OpLoad %[[#v3int]] %[[#GlobalInvocationId]]
40; CHECK:        %[[#load0:]] = OpCompositeExtract %[[#int]] %[[#load]] 0
41  %0 = call i32 @llvm.spv.thread.id(i32 0)
42
43; CHECK:        %[[#tempvar:]] = OpCompositeInsert %[[#v3int]] %[[#load0]] %[[#tempvar]] 0
44  %1 = insertelement <3 x i32> poison, i32 %0, i64 0
45
46; CHECK:        %[[#load:]] = OpLoad %[[#v3int]] %[[#GlobalInvocationId]]
47; CHECK:        %[[#load1:]] = OpCompositeExtract %[[#int]] %[[#load]] 1
48  %2 = call i32 @llvm.spv.thread.id(i32 1)
49
50; CHECK:        %[[#tempvar:]] = OpCompositeInsert %[[#v3int]] %[[#load1]] %[[#tempvar]] 1
51  %3 = insertelement <3 x i32> %1, i32 %2, i64 1
52
53; CHECK:        %[[#load:]] = OpLoad %[[#v3int]] %[[#GlobalInvocationId]]
54; CHECK:        %[[#load2:]] = OpCompositeExtract %[[#int]] %[[#load]] 2
55  %4 = call i32 @llvm.spv.thread.id(i32 2)
56
57; CHECK:        %[[#tempvar:]] = OpCompositeInsert %[[#v3int]] %[[#load2]] %[[#tempvar]] 2
58  %5 = insertelement <3 x i32> %3, i32 %4, i64 2
59
60  call void @main(<3 x i32> %5)
61  ret void
62}
63
64; Function Attrs: nounwind willreturn memory(none)
65declare i32 @llvm.spv.thread.id(i32) #2
66
67attributes #0 = { noinline norecurse nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
68attributes #1 = { norecurse "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
69attributes #2 = { nounwind willreturn memory(none) }
70
71!llvm.module.flags = !{!0, !1}
72!llvm.ident = !{!2}
73
74!0 = !{i32 1, !"wchar_size", i32 4}
75!1 = !{i32 4, !"dx.disable_optimizations", i32 1}
76!2 = !{!"clang version 19.0.0git (git@github.com:llvm/llvm-project.git 91600507765679e92434ec7c5edb883bf01f847f)"}
77