xref: /llvm-project/llvm/test/CodeGen/SPIRV/opencl/get_global_id.ll (revision ec7baca17e78d47c1571d1c06b95f920562293da)
1; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
2
3;; The set of valid inputs for get_global_id depends on the runtime NDRange,
4;; but inputs outside of [0, 2] always return 0.
5;; Here we assume Itanium mangling for function name.
6declare i64 @_Z13get_global_idj(i32)
7
8define i64 @foo(i32 %dim) {
9  %x = call i64 @_Z13get_global_idj(i32 0)
10  %zero = call i64 @_Z13get_global_idj(i32 5)
11  %unknown = call i64 @_Z13get_global_idj(i32 %dim)
12  %acc = add i64 %x, %zero
13  %ret = add i64 %acc, %unknown
14  ret i64 %ret
15}
16
17;; Capabilities:
18; CHECK-DAG: OpCapability Kernel
19; CHECK-DAG: OpCapability Int64
20
21; CHECK-NOT: DAG-FENCE
22
23;; Decorations:
24; CHECK-DAG: OpDecorate %[[#GET_GLOBAL_ID:]] BuiltIn GlobalInvocationId
25; CHECK-DAG: OpDecorate %[[#GET_GLOBAL_ID]] Constant
26
27; CHECK-NOT: DAG-FENCE
28
29;; Types, Constants and Variables:
30; CHECK-DAG: %[[#BOOL:]] = OpTypeBool
31; CHECK-DAG: %[[#I32:]] = OpTypeInt 32 0
32; CHECK-DAG: %[[#I64:]] = OpTypeInt 64 0
33; CHECK-DAG: %[[#VEC:]] = OpTypeVector %[[#I64]] 3
34; CHECK-DAG: %[[#PTR:]] = OpTypePointer Input %[[#VEC]]
35; CHECK-DAG: %[[#FN:]] = OpTypeFunction %[[#I64]] %[[#I32]]
36; CHECK-DAG: %[[#GET_GLOBAL_ID]] = OpVariable %[[#PTR]] Input
37; CHECK-DAG: %[[#ZERO:]] = OpConstantNull %[[#I64]]
38; CHECK-DAG: %[[#THREE:]] = OpConstant %[[#I32]] 3
39
40;; Functions:
41; CHECK:     OpFunction %[[#I64]] None %[[#FN]]
42; CHECK:     %[[#DIM:]] = OpFunctionParameter %[[#I32]]
43
44;; get_global_id(0): OpLoad + OpCompositeExtract.
45; CHECK:     %[[#TMP1:]] = OpLoad %[[#VEC]] %[[#GET_GLOBAL_ID]]
46; CHECK:     %[[#X:]] = OpCompositeExtract %[[#I64]] %[[#TMP1]] 0
47
48;; get_global_id(5): OpConstant (above) of zero.
49;; get_global_id(dim): Here we assume a specific implementation using select.
50; CHECK-DAG: %[[#TMP2:]] = OpLoad %[[#VEC]] %[[#GET_GLOBAL_ID]]
51; CHECK-DAG: %[[#TMP3:]] = OpVectorExtractDynamic %[[#I64]] %[[#TMP2]] %[[#DIM]]
52; CHECK-DAG: %[[#COND:]] = OpULessThan %[[#BOOL]] %[[#DIM]] %[[#THREE]]
53; CHECK:     %[[#UNKNOWN:]] = OpSelect %[[#I64]] %[[#COND]] %[[#TMP3]] %[[#ZERO]]
54