1// RUN: mlir-opt -test-int-range-inference %s | FileCheck %s
2
3// CHECK-LABEL: func @launch_func
4func.func @launch_func(%arg0 : index) {
5  %0 = test.with_bounds {
6    umin = 3 : index, umax = 5 : index,
7    smin = 3 : index, smax = 5 : index
8  }
9  %1 = test.with_bounds {
10    umin = 7 : index, umax = 11 : index,
11    smin = 7 : index, smax = 11 : index
12  }
13  gpu.launch blocks(%block_id_x, %block_id_y, %block_id_z) in (%grid_dim_x = %0, %grid_dim_y = %1, %grid_dim_z = %arg0)
14      threads(%thread_id_x, %thread_id_y, %thread_id_z) in (%block_dim_x = %arg0, %block_dim_y = %0, %block_dim_z = %1) {
15
16    // CHECK: test.reflect_bounds {smax = 5 : index, smin = 3 : index, umax = 5 : index, umin = 3 : index}
17    // CHECK: test.reflect_bounds {smax = 11 : index, smin = 7 : index, umax = 11 : index, umin = 7 : index}
18    // CHECK: test.reflect_bounds {smax = 4294967295 : index, smin = 1 : index, umax = 4294967295 : index, umin = 1 : index}
19    %grid_dim_x0 = test.reflect_bounds %grid_dim_x
20    %grid_dim_y0 = test.reflect_bounds %grid_dim_y
21    %grid_dim_z0 = test.reflect_bounds %grid_dim_z
22
23    // CHECK: test.reflect_bounds {smax = 4 : index, smin = 0 : index, umax = 4 : index, umin = 0 : index}
24    // CHECK: test.reflect_bounds {smax = 10 : index, smin = 0 : index, umax = 10 : index, umin = 0 : index}
25    // CHECK: test.reflect_bounds {smax = 4294967294 : index, smin = 0 : index, umax = 4294967294 : index, umin = 0 : index}
26    %block_id_x0 = test.reflect_bounds %block_id_x
27    %block_id_y0 = test.reflect_bounds %block_id_y
28    %block_id_z0 = test.reflect_bounds %block_id_z
29
30    // CHECK: test.reflect_bounds {smax = 4294967295 : index, smin = 1 : index, umax = 4294967295 : index, umin = 1 : index}
31    // CHECK: test.reflect_bounds {smax = 5 : index, smin = 3 : index, umax = 5 : index, umin = 3 : index}
32    // CHECK: test.reflect_bounds {smax = 11 : index, smin = 7 : index, umax = 11 : index, umin = 7 : index}
33    %block_dim_x0 = test.reflect_bounds %block_dim_x
34    %block_dim_y0 = test.reflect_bounds %block_dim_y
35    %block_dim_z0 = test.reflect_bounds %block_dim_z
36
37    // CHECK: test.reflect_bounds {smax = 4294967294 : index, smin = 0 : index, umax = 4294967294 : index, umin = 0 : index}
38    // CHECK: test.reflect_bounds {smax = 4 : index, smin = 0 : index, umax = 4 : index, umin = 0 : index}
39    // CHECK: test.reflect_bounds {smax = 10 : index, smin = 0 : index, umax = 10 : index, umin = 0 : index}
40    %thread_id_x0 = test.reflect_bounds %thread_id_x
41    %thread_id_y0 = test.reflect_bounds %thread_id_y
42    %thread_id_z0 = test.reflect_bounds %thread_id_z
43
44    gpu.terminator
45  }
46
47  func.return
48}
49
50// CHECK-LABEL: func @kernel
51module attributes {gpu.container_module} {
52  gpu.module @gpu_module {
53    llvm.func @kernel() attributes {gpu.kernel} {
54
55      %grid_dim_x = gpu.grid_dim x
56      %grid_dim_y = gpu.grid_dim y
57      %grid_dim_z = gpu.grid_dim z
58
59      // CHECK: test.reflect_bounds {smax = 4294967295 : index, smin = 1 : index, umax = 4294967295 : index, umin = 1 : index}
60      // CHECK: test.reflect_bounds {smax = 4294967295 : index, smin = 1 : index, umax = 4294967295 : index, umin = 1 : index}
61      // CHECK: test.reflect_bounds {smax = 4294967295 : index, smin = 1 : index, umax = 4294967295 : index, umin = 1 : index}
62      %grid_dim_x0 = test.reflect_bounds %grid_dim_x
63      %grid_dim_y0 = test.reflect_bounds %grid_dim_y
64      %grid_dim_z0 = test.reflect_bounds %grid_dim_z
65
66      %block_id_x = gpu.block_id x
67      %block_id_y = gpu.block_id y
68      %block_id_z = gpu.block_id z
69
70      // CHECK: test.reflect_bounds {smax = 4294967294 : index, smin = 0 : index, umax = 4294967294 : index, umin = 0 : index}
71      // CHECK: test.reflect_bounds {smax = 4294967294 : index, smin = 0 : index, umax = 4294967294 : index, umin = 0 : index}
72      // CHECK: test.reflect_bounds {smax = 4294967294 : index, smin = 0 : index, umax = 4294967294 : index, umin = 0 : index}
73      %block_id_x0 = test.reflect_bounds %block_id_x
74      %block_id_y0 = test.reflect_bounds %block_id_y
75      %block_id_z0 = test.reflect_bounds %block_id_z
76
77      %block_dim_x = gpu.block_dim x
78      %block_dim_y = gpu.block_dim y
79      %block_dim_z = gpu.block_dim z
80
81      // CHECK: test.reflect_bounds {smax = 4294967295 : index, smin = 1 : index, umax = 4294967295 : index, umin = 1 : index}
82      // CHECK: test.reflect_bounds {smax = 4294967295 : index, smin = 1 : index, umax = 4294967295 : index, umin = 1 : index}
83      // CHECK: test.reflect_bounds {smax = 4294967295 : index, smin = 1 : index, umax = 4294967295 : index, umin = 1 : index}
84      %block_dim_x0 = test.reflect_bounds %block_dim_x
85      %block_dim_y0 = test.reflect_bounds %block_dim_y
86      %block_dim_z0 = test.reflect_bounds %block_dim_z
87
88      %thread_id_x = gpu.thread_id x
89      %thread_id_y = gpu.thread_id y
90      %thread_id_z = gpu.thread_id z
91
92      // CHECK: test.reflect_bounds {smax = 4294967294 : index, smin = 0 : index, umax = 4294967294 : index, umin = 0 : index}
93      // CHECK: test.reflect_bounds {smax = 4294967294 : index, smin = 0 : index, umax = 4294967294 : index, umin = 0 : index}
94      // CHECK: test.reflect_bounds {smax = 4294967294 : index, smin = 0 : index, umax = 4294967294 : index, umin = 0 : index}
95      %thread_id_x0 = test.reflect_bounds %thread_id_x
96      %thread_id_y0 = test.reflect_bounds %thread_id_y
97      %thread_id_z0 = test.reflect_bounds %thread_id_z
98
99      %global_id_x = gpu.global_id x
100      %global_id_y = gpu.global_id y
101      %global_id_z = gpu.global_id z
102
103      // CHECK: test.reflect_bounds {smax = 9223372036854775807 : index, smin = 0 : index, umax = 9223372036854775807 : index, umin = 0 : index}
104      // CHECK: test.reflect_bounds {smax = 9223372036854775807 : index, smin = 0 : index, umax = 9223372036854775807 : index, umin = 0 : index}
105      // CHECK: test.reflect_bounds {smax = 9223372036854775807 : index, smin = 0 : index, umax = 9223372036854775807 : index, umin = 0 : index}
106      %global_id_x0 = test.reflect_bounds %global_id_x
107      %global_id_y0 = test.reflect_bounds %global_id_y
108      %global_id_z0 = test.reflect_bounds %global_id_z
109
110      %subgroup_size = gpu.subgroup_size : index
111      %lane_id = gpu.lane_id
112      %num_subgroups = gpu.num_subgroups : index
113      %subgroup_id = gpu.subgroup_id : index
114
115      // CHECK: test.reflect_bounds {smax = 128 : index, smin = 1 : index, umax = 128 : index, umin = 1 : index}
116      // CHECK: test.reflect_bounds {smax = 127 : index, smin = 0 : index, umax = 127 : index, umin = 0 : index}
117      // CHECK: test.reflect_bounds {smax = 4294967295 : index, smin = 1 : index, umax = 4294967295 : index, umin = 1 : index}
118      // CHECK: test.reflect_bounds {smax = 4294967294 : index, smin = 0 : index, umax = 4294967294 : index, umin = 0 : index}
119      %subgroup_size0 = test.reflect_bounds %subgroup_size
120      %lane_id0 = test.reflect_bounds %lane_id
121      %num_subgroups0 = test.reflect_bounds %num_subgroups
122      %subgroup_id0 = test.reflect_bounds %subgroup_id
123
124      llvm.return
125    }
126  }
127}
128
129