1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -slp-vectorizer -S -slp-threshold=-100 -slp-vectorize-hor-store -dce | FileCheck %s --check-prefix=GFX9
3
4@arr = local_unnamed_addr global [32 x i32] zeroinitializer, align 16
5@arr64 = local_unnamed_addr global [32 x i64] zeroinitializer, align 16
6@var = global i32 zeroinitializer, align 8
7@var64 = global i64 zeroinitializer, align 8
8
9@farr = local_unnamed_addr global [32 x float] zeroinitializer, align 16
10@fvar = global float zeroinitializer, align 8
11
12@darr = local_unnamed_addr global [32 x double] zeroinitializer, align 16
13@dvar = global double zeroinitializer, align 8
14
15; Tests whether the min/max reduction pattern is vectorized if SLP starts at the store.
16define i32 @smaxv6() {
17; GFX9-LABEL: @smaxv6(
18; GFX9-NEXT:    [[TMP1:%.*]] = load <2 x i32>, <2 x i32>* bitcast ([32 x i32]* @arr to <2 x i32>*), align 16
19; GFX9-NEXT:    [[TMP2:%.*]] = extractelement <2 x i32> [[TMP1]], i32 0
20; GFX9-NEXT:    [[TMP3:%.*]] = extractelement <2 x i32> [[TMP1]], i32 1
21; GFX9-NEXT:    [[CMP1:%.*]] = icmp sgt i32 [[TMP2]], [[TMP3]]
22; GFX9-NEXT:    [[SELECT1:%.*]] = select i1 [[CMP1]], i32 [[TMP2]], i32 [[TMP3]]
23; GFX9-NEXT:    [[LOAD3:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr, i64 0, i64 2), align 8
24; GFX9-NEXT:    [[CMP2:%.*]] = icmp sgt i32 [[SELECT1]], [[LOAD3]]
25; GFX9-NEXT:    [[SELECT2:%.*]] = select i1 [[CMP2]], i32 [[SELECT1]], i32 [[LOAD3]]
26; GFX9-NEXT:    [[LOAD4:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr, i64 0, i64 3), align 4
27; GFX9-NEXT:    [[CMP3:%.*]] = icmp sgt i32 [[SELECT2]], [[LOAD4]]
28; GFX9-NEXT:    [[SELECT3:%.*]] = select i1 [[CMP3]], i32 [[SELECT2]], i32 [[LOAD4]]
29; GFX9-NEXT:    [[LOAD5:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr, i64 0, i64 4), align 16
30; GFX9-NEXT:    [[CMP4:%.*]] = icmp sgt i32 [[SELECT3]], [[LOAD5]]
31; GFX9-NEXT:    [[SELECT4:%.*]] = select i1 [[CMP4]], i32 [[SELECT3]], i32 [[LOAD5]]
32; GFX9-NEXT:    [[LOAD6:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr, i64 0, i64 5), align 4
33; GFX9-NEXT:    [[CMP5:%.*]] = icmp sgt i32 [[SELECT4]], [[LOAD6]]
34; GFX9-NEXT:    [[SELECT5:%.*]] = select i1 [[CMP5]], i32 [[SELECT4]], i32 [[LOAD6]]
35; GFX9-NEXT:    [[STORE_SELECT:%.*]] = select i1 [[CMP1]], i32 3, i32 4
36; GFX9-NEXT:    store i32 [[STORE_SELECT]], i32* @var, align 8
37; GFX9-NEXT:    ret i32 [[SELECT5]]
38;
39  %load1 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr, i64 0, i64 0), align 16
40  %load2 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr, i64 0, i64 1), align 4
41  %cmp1 = icmp sgt i32 %load1, %load2
42  %select1 = select i1 %cmp1, i32 %load1, i32 %load2
43
44  %load3 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr, i64 0, i64 2), align 8
45  %cmp2 = icmp sgt i32 %select1, %load3
46  %select2 = select i1 %cmp2, i32 %select1, i32 %load3
47
48  %load4 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr, i64 0, i64 3), align 4
49  %cmp3 = icmp sgt i32 %select2, %load4
50  %select3 = select i1 %cmp3, i32 %select2, i32 %load4
51
52  %load5 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr, i64 0, i64 4), align 16
53  %cmp4 = icmp sgt i32 %select3, %load5
54  %select4 = select i1 %cmp4, i32 %select3, i32 %load5
55
56  %load6 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr, i64 0, i64 5), align 4
57  %cmp5 = icmp sgt i32 %select4, %load6
58  %select5 = select i1 %cmp5, i32 %select4, i32 %load6
59
60  %store-select = select i1 %cmp1, i32 3, i32 4
61  store i32 %store-select, i32* @var, align 8
62  ret i32 %select5
63}
64
65define i64 @sminv6() {
66; GFX9-LABEL: @sminv6(
67; GFX9-NEXT:    [[TMP1:%.*]] = load <2 x i64>, <2 x i64>* bitcast ([32 x i64]* @arr64 to <2 x i64>*), align 16
68; GFX9-NEXT:    [[TMP2:%.*]] = extractelement <2 x i64> [[TMP1]], i32 0
69; GFX9-NEXT:    [[TMP3:%.*]] = extractelement <2 x i64> [[TMP1]], i32 1
70; GFX9-NEXT:    [[CMP1:%.*]] = icmp slt i64 [[TMP2]], [[TMP3]]
71; GFX9-NEXT:    [[SELECT1:%.*]] = select i1 [[CMP1]], i64 [[TMP2]], i64 [[TMP3]]
72; GFX9-NEXT:    [[LOAD3:%.*]] = load i64, i64* getelementptr inbounds ([32 x i64], [32 x i64]* @arr64, i64 0, i64 2), align 16
73; GFX9-NEXT:    [[CMP2:%.*]] = icmp slt i64 [[SELECT1]], [[LOAD3]]
74; GFX9-NEXT:    [[SELECT2:%.*]] = select i1 [[CMP2]], i64 [[SELECT1]], i64 [[LOAD3]]
75; GFX9-NEXT:    [[LOAD4:%.*]] = load i64, i64* getelementptr inbounds ([32 x i64], [32 x i64]* @arr64, i64 0, i64 3), align 8
76; GFX9-NEXT:    [[CMP3:%.*]] = icmp slt i64 [[SELECT2]], [[LOAD4]]
77; GFX9-NEXT:    [[SELECT3:%.*]] = select i1 [[CMP3]], i64 [[SELECT2]], i64 [[LOAD4]]
78; GFX9-NEXT:    [[LOAD5:%.*]] = load i64, i64* getelementptr inbounds ([32 x i64], [32 x i64]* @arr64, i64 0, i64 4), align 16
79; GFX9-NEXT:    [[CMP4:%.*]] = icmp slt i64 [[SELECT3]], [[LOAD5]]
80; GFX9-NEXT:    [[SELECT4:%.*]] = select i1 [[CMP4]], i64 [[SELECT3]], i64 [[LOAD5]]
81; GFX9-NEXT:    [[LOAD6:%.*]] = load i64, i64* getelementptr inbounds ([32 x i64], [32 x i64]* @arr64, i64 0, i64 5), align 8
82; GFX9-NEXT:    [[CMP5:%.*]] = icmp slt i64 [[SELECT4]], [[LOAD6]]
83; GFX9-NEXT:    [[SELECT5:%.*]] = select i1 [[CMP5]], i64 [[SELECT4]], i64 [[LOAD6]]
84; GFX9-NEXT:    [[STORE_SELECT:%.*]] = select i1 [[CMP1]], i64 3, i64 4
85; GFX9-NEXT:    store i64 [[STORE_SELECT]], i64* @var64, align 8
86; GFX9-NEXT:    ret i64 [[SELECT5]]
87;
88  %load1 = load i64, i64* getelementptr inbounds ([32 x i64], [32 x i64]* @arr64, i64 0, i64 0), align 16
89  %load2 = load i64, i64* getelementptr inbounds ([32 x i64], [32 x i64]* @arr64, i64 0, i64 1), align 8
90  %cmp1 = icmp slt i64 %load1, %load2
91  %select1 = select i1 %cmp1, i64 %load1, i64 %load2
92
93  %load3 = load i64, i64* getelementptr inbounds ([32 x i64], [32 x i64]* @arr64, i64 0, i64 2), align 16
94  %cmp2 = icmp slt i64 %select1, %load3
95  %select2 = select i1 %cmp2, i64 %select1, i64 %load3
96
97  %load4 = load i64, i64* getelementptr inbounds ([32 x i64], [32 x i64]* @arr64, i64 0, i64 3), align 8
98  %cmp3 = icmp slt i64 %select2, %load4
99  %select3 = select i1 %cmp3, i64 %select2, i64 %load4
100
101  %load5 = load i64, i64* getelementptr inbounds ([32 x i64], [32 x i64]* @arr64, i64 0, i64 4), align 16
102  %cmp4 = icmp slt i64 %select3, %load5
103  %select4 = select i1 %cmp4, i64 %select3, i64 %load5
104
105  %load6 = load i64, i64* getelementptr inbounds ([32 x i64], [32 x i64]* @arr64, i64 0, i64 5), align 8
106  %cmp5 = icmp slt i64 %select4, %load6
107  %select5 = select i1 %cmp5, i64 %select4, i64 %load6
108
109  %store-select = select i1 %cmp1, i64 3, i64 4
110  store i64 %store-select, i64* @var64, align 8
111  ret i64 %select5
112}
113
114define float @fmaxv6() {
115; GFX9-LABEL: @fmaxv6(
116; GFX9-NEXT:    [[TMP1:%.*]] = load <2 x float>, <2 x float>* bitcast ([32 x float]* @farr to <2 x float>*), align 16
117; GFX9-NEXT:    [[TMP2:%.*]] = extractelement <2 x float> [[TMP1]], i32 0
118; GFX9-NEXT:    [[TMP3:%.*]] = extractelement <2 x float> [[TMP1]], i32 1
119; GFX9-NEXT:    [[CMP1:%.*]] = fcmp fast ogt float [[TMP2]], [[TMP3]]
120; GFX9-NEXT:    [[SELECT1:%.*]] = select i1 [[CMP1]], float [[TMP2]], float [[TMP3]]
121; GFX9-NEXT:    [[LOAD3:%.*]] = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @farr, i64 0, i64 2), align 8
122; GFX9-NEXT:    [[CMP2:%.*]] = fcmp fast ogt float [[SELECT1]], [[LOAD3]]
123; GFX9-NEXT:    [[SELECT2:%.*]] = select i1 [[CMP2]], float [[SELECT1]], float [[LOAD3]]
124; GFX9-NEXT:    [[LOAD4:%.*]] = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @farr, i64 0, i64 3), align 4
125; GFX9-NEXT:    [[CMP3:%.*]] = fcmp fast ogt float [[SELECT2]], [[LOAD4]]
126; GFX9-NEXT:    [[SELECT3:%.*]] = select i1 [[CMP3]], float [[SELECT2]], float [[LOAD4]]
127; GFX9-NEXT:    [[LOAD5:%.*]] = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @farr, i64 0, i64 4), align 16
128; GFX9-NEXT:    [[CMP4:%.*]] = fcmp fast ogt float [[SELECT3]], [[LOAD5]]
129; GFX9-NEXT:    [[SELECT4:%.*]] = select i1 [[CMP4]], float [[SELECT3]], float [[LOAD5]]
130; GFX9-NEXT:    [[LOAD6:%.*]] = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @farr, i64 0, i64 5), align 4
131; GFX9-NEXT:    [[CMP5:%.*]] = fcmp fast ogt float [[SELECT4]], [[LOAD6]]
132; GFX9-NEXT:    [[SELECT5:%.*]] = select i1 [[CMP5]], float [[SELECT4]], float [[LOAD6]]
133; GFX9-NEXT:    [[STORE_SELECT:%.*]] = select i1 [[CMP1]], float 3.000000e+00, float 4.000000e+00
134; GFX9-NEXT:    store float [[STORE_SELECT]], float* @fvar, align 8
135; GFX9-NEXT:    ret float [[SELECT5]]
136;
137  %load1 = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @farr, i64 0, i64 0), align 16
138  %load2 = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @farr, i64 0, i64 1), align 4
139  %cmp1 = fcmp fast ogt float %load1, %load2
140  %select1 = select i1 %cmp1, float %load1, float %load2
141
142  %load3 = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @farr, i64 0, i64 2), align 8
143  %cmp2 = fcmp fast ogt float %select1, %load3
144  %select2 = select i1 %cmp2, float %select1, float %load3
145
146  %load4 = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @farr, i64 0, i64 3), align 4
147  %cmp3 = fcmp fast ogt float %select2, %load4
148  %select3 = select i1 %cmp3, float %select2, float %load4
149
150  %load5 = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @farr, i64 0, i64 4), align 16
151  %cmp4 = fcmp fast ogt float %select3, %load5
152  %select4 = select i1 %cmp4, float %select3, float %load5
153
154  %load6 = load float, float* getelementptr inbounds ([32 x float], [32 x float]* @farr, i64 0, i64 5), align 4
155  %cmp5 = fcmp fast ogt float %select4, %load6
156  %select5 = select i1 %cmp5, float %select4, float %load6
157
158  %store-select = select i1 %cmp1, float 3.0, float 4.0
159  store float %store-select, float* @fvar, align 8
160  ret float %select5
161}
162
163define double @dminv6() {
164; GFX9-LABEL: @dminv6(
165; GFX9-NEXT:    [[TMP1:%.*]] = load <2 x double>, <2 x double>* bitcast ([32 x double]* @darr to <2 x double>*), align 16
166; GFX9-NEXT:    [[TMP2:%.*]] = extractelement <2 x double> [[TMP1]], i32 0
167; GFX9-NEXT:    [[TMP3:%.*]] = extractelement <2 x double> [[TMP1]], i32 1
168; GFX9-NEXT:    [[CMP1:%.*]] = fcmp fast olt double [[TMP2]], [[TMP3]]
169; GFX9-NEXT:    [[SELECT1:%.*]] = select i1 [[CMP1]], double [[TMP2]], double [[TMP3]]
170; GFX9-NEXT:    [[LOAD3:%.*]] = load double, double* getelementptr inbounds ([32 x double], [32 x double]* @darr, i64 0, i64 2), align 8
171; GFX9-NEXT:    [[CMP2:%.*]] = fcmp fast olt double [[SELECT1]], [[LOAD3]]
172; GFX9-NEXT:    [[SELECT2:%.*]] = select i1 [[CMP2]], double [[SELECT1]], double [[LOAD3]]
173; GFX9-NEXT:    [[LOAD4:%.*]] = load double, double* getelementptr inbounds ([32 x double], [32 x double]* @darr, i64 0, i64 3), align 4
174; GFX9-NEXT:    [[CMP3:%.*]] = fcmp fast olt double [[SELECT2]], [[LOAD4]]
175; GFX9-NEXT:    [[SELECT3:%.*]] = select i1 [[CMP3]], double [[SELECT2]], double [[LOAD4]]
176; GFX9-NEXT:    [[LOAD5:%.*]] = load double, double* getelementptr inbounds ([32 x double], [32 x double]* @darr, i64 0, i64 4), align 16
177; GFX9-NEXT:    [[CMP4:%.*]] = fcmp fast olt double [[SELECT3]], [[LOAD5]]
178; GFX9-NEXT:    [[SELECT4:%.*]] = select i1 [[CMP4]], double [[SELECT3]], double [[LOAD5]]
179; GFX9-NEXT:    [[LOAD6:%.*]] = load double, double* getelementptr inbounds ([32 x double], [32 x double]* @darr, i64 0, i64 5), align 4
180; GFX9-NEXT:    [[CMP5:%.*]] = fcmp fast olt double [[SELECT4]], [[LOAD6]]
181; GFX9-NEXT:    [[SELECT5:%.*]] = select i1 [[CMP5]], double [[SELECT4]], double [[LOAD6]]
182; GFX9-NEXT:    [[STORE_SELECT:%.*]] = select i1 [[CMP1]], double 3.000000e+00, double 4.000000e+00
183; GFX9-NEXT:    store double [[STORE_SELECT]], double* @dvar, align 8
184; GFX9-NEXT:    ret double [[SELECT5]]
185;
186  %load1 = load double, double* getelementptr inbounds ([32 x double], [32 x double]* @darr, i64 0, i64 0), align 16
187  %load2 = load double, double* getelementptr inbounds ([32 x double], [32 x double]* @darr, i64 0, i64 1), align 4
188  %cmp1 = fcmp fast olt double %load1, %load2
189  %select1 = select i1 %cmp1, double %load1, double %load2
190
191  %load3 = load double, double* getelementptr inbounds ([32 x double], [32 x double]* @darr, i64 0, i64 2), align 8
192  %cmp2 = fcmp fast olt double %select1, %load3
193  %select2 = select i1 %cmp2, double %select1, double %load3
194
195  %load4 = load double, double* getelementptr inbounds ([32 x double], [32 x double]* @darr, i64 0, i64 3), align 4
196  %cmp3 = fcmp fast olt double %select2, %load4
197  %select3 = select i1 %cmp3, double %select2, double %load4
198
199  %load5 = load double, double* getelementptr inbounds ([32 x double], [32 x double]* @darr, i64 0, i64 4), align 16
200  %cmp4 = fcmp fast olt double %select3, %load5
201  %select4 = select i1 %cmp4, double %select3, double %load5
202
203  %load6 = load double, double* getelementptr inbounds ([32 x double], [32 x double]* @darr, i64 0, i64 5), align 4
204  %cmp5 = fcmp fast olt double %select4, %load6
205  %select5 = select i1 %cmp5, double %select4, double %load6
206
207  %store-select = select i1 %cmp1, double 3.0, double 4.0
208  store double %store-select, double* @dvar, align 8
209  ret double %select5
210}
211
212define i32 @smax_wdiff_valuenum(i32, i32 %v1) {
213; GFX9-LABEL: @smax_wdiff_valuenum(
214; GFX9-NEXT:    [[VLOAD:%.*]] = load <2 x i32>, <2 x i32>* bitcast ([32 x i32]* @arr to <2 x i32>*), align 16
215; GFX9-NEXT:    [[ELT1:%.*]] = extractelement <2 x i32> [[VLOAD]], i32 0
216; GFX9-NEXT:    [[CMP1:%.*]] = icmp sgt i32 [[ELT1]], [[V1:%.*]]
217; GFX9-NEXT:    [[EX0:%.*]] = extractelement <2 x i32> [[VLOAD]], i32 0
218; GFX9-NEXT:    [[SELECT1:%.*]] = select i1 [[CMP1]], i32 [[EX0]], i32 [[V1]]
219; GFX9-NEXT:    [[LOAD3:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr, i64 0, i64 2), align 8
220; GFX9-NEXT:    [[CMP2:%.*]] = icmp sgt i32 [[SELECT1]], [[LOAD3]]
221; GFX9-NEXT:    [[SELECT2:%.*]] = select i1 [[CMP2]], i32 [[SELECT1]], i32 [[LOAD3]]
222; GFX9-NEXT:    [[LOAD4:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr, i64 0, i64 3), align 4
223; GFX9-NEXT:    [[CMP3:%.*]] = icmp sgt i32 [[SELECT2]], [[LOAD4]]
224; GFX9-NEXT:    [[SELECT3:%.*]] = select i1 [[CMP3]], i32 [[SELECT2]], i32 [[LOAD4]]
225; GFX9-NEXT:    [[LOAD5:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr, i64 0, i64 4), align 16
226; GFX9-NEXT:    [[CMP4:%.*]] = icmp sgt i32 [[SELECT3]], [[LOAD5]]
227; GFX9-NEXT:    [[SELECT4:%.*]] = select i1 [[CMP4]], i32 [[SELECT3]], i32 [[LOAD5]]
228; GFX9-NEXT:    [[LOAD6:%.*]] = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr, i64 0, i64 5), align 4
229; GFX9-NEXT:    [[CMP5:%.*]] = icmp sgt i32 [[SELECT4]], [[LOAD6]]
230; GFX9-NEXT:    [[SELECT5:%.*]] = select i1 [[CMP5]], i32 [[SELECT4]], i32 [[LOAD6]]
231; GFX9-NEXT:    [[STOREVAL:%.*]] = select i1 [[CMP1]], i32 3, i32 4
232; GFX9-NEXT:    store i32 [[STOREVAL]], i32* @var, align 8
233; GFX9-NEXT:    ret i32 [[SELECT5]]
234;
235  %vload = load <2 x i32>, <2 x i32>* bitcast ([32 x i32]* @arr to <2 x i32>*), align 16
236  %elt1 = extractelement <2 x i32> %vload, i32 0
237  %cmp1 = icmp sgt i32 %elt1, %v1
238  %ex0 = extractelement <2 x i32> %vload, i32 0
239  %select1 = select i1 %cmp1, i32 %ex0, i32 %v1
240
241  %load3 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr, i64 0, i64 2), align 8
242  %cmp2 = icmp sgt i32 %select1, %load3
243  %select2 = select i1 %cmp2, i32 %select1, i32 %load3
244
245  %load4 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr, i64 0, i64 3), align 4
246  %cmp3 = icmp sgt i32 %select2, %load4
247  %select3 = select i1 %cmp3, i32 %select2, i32 %load4
248
249  %load5 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr, i64 0, i64 4), align 16
250  %cmp4 = icmp sgt i32 %select3, %load5
251  %select4 = select i1 %cmp4, i32 %select3, i32 %load5
252
253  %load6 = load i32, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @arr, i64 0, i64 5), align 4
254  %cmp5 = icmp sgt i32 %select4, %load6
255  %select5 = select i1 %cmp5, i32 %select4, i32 %load6
256
257  %storeval = select i1 %cmp1, i32 3, i32 4
258  store i32 %storeval, i32* @var, align 8
259  ret i32 %select5
260}
261