1; RUN: llc -march=amdgcn < %s | FileCheck -check-prefixes=GCN,SI %s
2; RUN: llc -march=amdgcn -mcpu=tonga < %s | FileCheck -check-prefixes=GCN,VI %s
3; RUN: llc -march=amdgcn -mcpu=gfx900 < %s | FileCheck -check-prefixes=GCN,GFX9 %s
4
5; GCN-LABEL: {{^}}v_test_imin3_slt_i32:
6; GCN: v_min3_i32
7define amdgpu_kernel void @v_test_imin3_slt_i32(i32 addrspace(1)* %out, i32 addrspace(1)* %aptr, i32 addrspace(1)* %bptr, i32 addrspace(1)* %cptr) #0 {
8  %tid = call i32 @llvm.amdgcn.workitem.id.x()
9  %gep0 = getelementptr i32, i32 addrspace(1)* %aptr, i32 %tid
10  %gep1 = getelementptr i32, i32 addrspace(1)* %bptr, i32 %tid
11  %gep2 = getelementptr i32, i32 addrspace(1)* %cptr, i32 %tid
12  %outgep = getelementptr i32, i32 addrspace(1)* %out, i32 %tid
13  %a = load i32, i32 addrspace(1)* %gep0
14  %b = load i32, i32 addrspace(1)* %gep1
15  %c = load i32, i32 addrspace(1)* %gep2
16  %icmp0 = icmp slt i32 %a, %b
17  %i0 = select i1 %icmp0, i32 %a, i32 %b
18  %icmp1 = icmp slt i32 %i0, %c
19  %i1 = select i1 %icmp1, i32 %i0, i32 %c
20  store i32 %i1, i32 addrspace(1)* %outgep
21  ret void
22}
23
24; GCN-LABEL: {{^}}v_test_umin3_ult_i32:
25; GCN: v_min3_u32
26define amdgpu_kernel void @v_test_umin3_ult_i32(i32 addrspace(1)* %out, i32 addrspace(1)* %aptr, i32 addrspace(1)* %bptr, i32 addrspace(1)* %cptr) #0 {
27  %tid = call i32 @llvm.amdgcn.workitem.id.x()
28  %gep0 = getelementptr i32, i32 addrspace(1)* %aptr, i32 %tid
29  %gep1 = getelementptr i32, i32 addrspace(1)* %bptr, i32 %tid
30  %gep2 = getelementptr i32, i32 addrspace(1)* %cptr, i32 %tid
31  %outgep = getelementptr i32, i32 addrspace(1)* %out, i32 %tid
32  %a = load i32, i32 addrspace(1)* %gep0
33  %b = load i32, i32 addrspace(1)* %gep1
34  %c = load i32, i32 addrspace(1)* %gep2
35  %icmp0 = icmp ult i32 %a, %b
36  %i0 = select i1 %icmp0, i32 %a, i32 %b
37  %icmp1 = icmp ult i32 %i0, %c
38  %i1 = select i1 %icmp1, i32 %i0, i32 %c
39  store i32 %i1, i32 addrspace(1)* %outgep
40  ret void
41}
42
43; GCN-LABEL: {{^}}v_test_umin_umin_umin:
44; GCN: v_min_i32
45; GCN: v_min3_i32
46define amdgpu_kernel void @v_test_umin_umin_umin(i32 addrspace(1)* %out, i32 addrspace(1)* %aptr, i32 addrspace(1)* %bptr, i32 addrspace(1)* %cptr) #0 {
47  %tid = call i32 @llvm.amdgcn.workitem.id.x()
48  %tid2 = mul i32 %tid, 2
49  %gep0 = getelementptr i32, i32 addrspace(1)* %aptr, i32 %tid
50  %gep1 = getelementptr i32, i32 addrspace(1)* %bptr, i32 %tid
51  %gep2 = getelementptr i32, i32 addrspace(1)* %cptr, i32 %tid
52
53  %gep3 = getelementptr i32, i32 addrspace(1)* %aptr, i32 %tid2
54  %gep4 = getelementptr i32, i32 addrspace(1)* %bptr, i32 %tid2
55  %gep5 = getelementptr i32, i32 addrspace(1)* %cptr, i32 %tid2
56
57  %outgep0 = getelementptr i32, i32 addrspace(1)* %out, i32 %tid
58  %outgep1 = getelementptr i32, i32 addrspace(1)* %out, i32 %tid2
59
60  %a = load i32, i32 addrspace(1)* %gep0
61  %b = load i32, i32 addrspace(1)* %gep1
62  %c = load i32, i32 addrspace(1)* %gep2
63  %d = load i32, i32 addrspace(1)* %gep3
64
65  %icmp0 = icmp slt i32 %a, %b
66  %i0 = select i1 %icmp0, i32 %a, i32 %b
67
68  %icmp1 = icmp slt i32 %c, %d
69  %i1 = select i1 %icmp1, i32 %c, i32 %d
70
71  %icmp2 = icmp slt i32 %i0, %i1
72  %i2 = select i1 %icmp2, i32 %i0, i32 %i1
73
74  store i32 %i2, i32 addrspace(1)* %outgep1
75  ret void
76}
77
78; GCN-LABEL: {{^}}v_test_umin3_2_uses:
79; GCN-NOT: v_min3
80define amdgpu_kernel void @v_test_umin3_2_uses(i32 addrspace(1)* %out, i32 addrspace(1)* %aptr, i32 addrspace(1)* %bptr, i32 addrspace(1)* %cptr) #0 {
81  %tid = call i32 @llvm.amdgcn.workitem.id.x()
82  %tid2 = mul i32 %tid, 2
83  %gep0 = getelementptr i32, i32 addrspace(1)* %aptr, i32 %tid
84  %gep1 = getelementptr i32, i32 addrspace(1)* %bptr, i32 %tid
85  %gep2 = getelementptr i32, i32 addrspace(1)* %cptr, i32 %tid
86
87  %gep3 = getelementptr i32, i32 addrspace(1)* %aptr, i32 %tid2
88  %gep4 = getelementptr i32, i32 addrspace(1)* %bptr, i32 %tid2
89  %gep5 = getelementptr i32, i32 addrspace(1)* %cptr, i32 %tid2
90
91  %outgep0 = getelementptr i32, i32 addrspace(1)* %out, i32 %tid
92  %outgep1 = getelementptr i32, i32 addrspace(1)* %out, i32 %tid2
93
94  %a = load i32, i32 addrspace(1)* %gep0
95  %b = load i32, i32 addrspace(1)* %gep1
96  %c = load i32, i32 addrspace(1)* %gep2
97  %d = load i32, i32 addrspace(1)* %gep3
98
99  %icmp0 = icmp slt i32 %a, %b
100  %i0 = select i1 %icmp0, i32 %a, i32 %b
101
102  %icmp1 = icmp slt i32 %c, %d
103  %i1 = select i1 %icmp1, i32 %c, i32 %d
104
105  %icmp2 = icmp slt i32 %i0, %c
106  %i2 = select i1 %icmp2, i32 %i0, i32 %c
107
108  store i32 %i2, i32 addrspace(1)* %outgep0
109  store i32 %i0, i32 addrspace(1)* %outgep1
110  ret void
111}
112
113; GCN-LABEL: {{^}}v_test_imin3_slt_i16:
114; SI: v_min3_i32
115
116; VI: v_min_i16
117; VI: v_min_i16
118
119; GFX9: v_min3_i16
120define amdgpu_kernel void @v_test_imin3_slt_i16(i16 addrspace(1)* %out, i16 addrspace(1)* %aptr, i16 addrspace(1)* %bptr, i16 addrspace(1)* %cptr) #0 {
121  %tid = call i32 @llvm.amdgcn.workitem.id.x()
122  %gep0 = getelementptr i16, i16 addrspace(1)* %aptr, i32 %tid
123  %gep1 = getelementptr i16, i16 addrspace(1)* %bptr, i32 %tid
124  %gep2 = getelementptr i16, i16 addrspace(1)* %cptr, i32 %tid
125  %outgep = getelementptr i16, i16 addrspace(1)* %out, i32 %tid
126  %a = load i16, i16 addrspace(1)* %gep0
127  %b = load i16, i16 addrspace(1)* %gep1
128  %c = load i16, i16 addrspace(1)* %gep2
129  %icmp0 = icmp slt i16 %a, %b
130  %i0 = select i1 %icmp0, i16 %a, i16 %b
131  %icmp1 = icmp slt i16 %i0, %c
132  %i1 = select i1 %icmp1, i16 %i0, i16 %c
133  store i16 %i1, i16 addrspace(1)* %outgep
134  ret void
135}
136
137; GCN-LABEL: {{^}}v_test_umin3_ult_i16:
138; SI: v_min3_u32
139
140; VI: v_min_u16
141; VI: v_min_u16
142
143; GFX9: v_min3_u16
144define amdgpu_kernel void @v_test_umin3_ult_i16(i16 addrspace(1)* %out, i16 addrspace(1)* %aptr, i16 addrspace(1)* %bptr, i16 addrspace(1)* %cptr) #0 {
145  %tid = call i32 @llvm.amdgcn.workitem.id.x()
146  %gep0 = getelementptr i16, i16 addrspace(1)* %aptr, i32 %tid
147  %gep1 = getelementptr i16, i16 addrspace(1)* %bptr, i32 %tid
148  %gep2 = getelementptr i16, i16 addrspace(1)* %cptr, i32 %tid
149  %outgep = getelementptr i16, i16 addrspace(1)* %out, i32 %tid
150  %a = load i16, i16 addrspace(1)* %gep0
151  %b = load i16, i16 addrspace(1)* %gep1
152  %c = load i16, i16 addrspace(1)* %gep2
153  %icmp0 = icmp ult i16 %a, %b
154  %i0 = select i1 %icmp0, i16 %a, i16 %b
155  %icmp1 = icmp ult i16 %i0, %c
156  %i1 = select i1 %icmp1, i16 %i0, i16 %c
157  store i16 %i1, i16 addrspace(1)* %outgep
158  ret void
159}
160
161declare i32 @llvm.amdgcn.workitem.id.x() #1
162
163attributes #0 = { nounwind }
164attributes #1 = { nounwind readnone speculatable }
165