@@ -293,6 +293,79 @@ module attributes {gpu.container_module} {
293293 }
294294}
295295
296+ // -----
297+
298+ module attributes {gpu.container_module } {
299+ func @builtin () {
300+ %c0 = arith.constant 1 : index
301+ gpu.launch_func @kernels ::@builtin_global_id_x
302+ blocks in (%c0 , %c0 , %c0 ) threads in (%c0 , %c0 , %c0 )
303+ return
304+ }
305+
306+ // CHECK-LABEL: spv.module @{{.*}} Logical GLSL450
307+ // CHECK: spv.GlobalVariable [[GLOBALINVOCATIONID:@.*]] built_in("GlobalInvocationId")
308+ gpu.module @kernels {
309+ gpu.func @builtin_global_id_x () kernel
310+ attributes {spv.entry_point_abi = {local_size = dense <[16 , 1 , 1 ]>: vector <3 xi32 >}} {
311+ // CHECK: [[ADDRESS:%.*]] = spv.mlir.addressof [[GLOBALINVOCATIONID]]
312+ // CHECK-NEXT: [[VEC:%.*]] = spv.Load "Input" [[ADDRESS]]
313+ // CHECK-NEXT: {{%.*}} = spv.CompositeExtract [[VEC]]{{\[}}0 : i32{{\]}}
314+ %0 = gpu.global_id x
315+ gpu.return
316+ }
317+ }
318+ }
319+
320+ // -----
321+
322+ module attributes {gpu.container_module } {
323+ func @builtin () {
324+ %c0 = arith.constant 1 : index
325+ gpu.launch_func @kernels ::@builtin_global_id_y
326+ blocks in (%c0 , %c0 , %c0 ) threads in (%c0 , %c0 , %c0 )
327+ return
328+ }
329+
330+ // CHECK-LABEL: spv.module @{{.*}} Logical GLSL450
331+ // CHECK: spv.GlobalVariable [[GLOBALINVOCATIONID:@.*]] built_in("GlobalInvocationId")
332+ gpu.module @kernels {
333+ gpu.func @builtin_global_id_y () kernel
334+ attributes {spv.entry_point_abi = {local_size = dense <[16 , 1 , 1 ]>: vector <3 xi32 >}} {
335+ // CHECK: [[ADDRESS:%.*]] = spv.mlir.addressof [[GLOBALINVOCATIONID]]
336+ // CHECK-NEXT: [[VEC:%.*]] = spv.Load "Input" [[ADDRESS]]
337+ // CHECK-NEXT: {{%.*}} = spv.CompositeExtract [[VEC]]{{\[}}1 : i32{{\]}}
338+ %0 = gpu.global_id y
339+ gpu.return
340+ }
341+ }
342+ }
343+
344+ // -----
345+
346+ module attributes {gpu.container_module } {
347+ func @builtin () {
348+ %c0 = arith.constant 1 : index
349+ gpu.launch_func @kernels ::@builtin_global_id_z
350+ blocks in (%c0 , %c0 , %c0 ) threads in (%c0 , %c0 , %c0 )
351+ return
352+ }
353+
354+ // CHECK-LABEL: spv.module @{{.*}} Logical GLSL450
355+ // CHECK: spv.GlobalVariable [[GLOBALINVOCATIONID:@.*]] built_in("GlobalInvocationId")
356+ gpu.module @kernels {
357+ gpu.func @builtin_global_id_z () kernel
358+ attributes {spv.entry_point_abi = {local_size = dense <[16 , 1 , 1 ]>: vector <3 xi32 >}} {
359+ // CHECK: [[ADDRESS:%.*]] = spv.mlir.addressof [[GLOBALINVOCATIONID]]
360+ // CHECK-NEXT: [[VEC:%.*]] = spv.Load "Input" [[ADDRESS]]
361+ // CHECK-NEXT: {{%.*}} = spv.CompositeExtract [[VEC]]{{\[}}2 : i32{{\]}}
362+ %0 = gpu.global_id z
363+ gpu.return
364+ }
365+ }
366+ }
367+
368+
296369// -----
297370
298371module attributes {gpu.container_module } {
0 commit comments