1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=slp-vectorizer -slp-vectorize-hor -S -mtriple=x86_64-unknown-linux-gnu -mcpu=bdver2 -debug-only=SLP < %s 2>&1 | FileCheck %s --check-prefixes=CHECK,AVX
3 ; RUN: opt -passes=slp-vectorizer -slp-vectorize-hor -S -mtriple=x86_64-unknown-linux-gnu -mcpu=core2 -debug-only=SLP < %s 2>&1 | FileCheck %s --check-prefixes=CHECK,SSE
6 ; int test_add(unsigned int *p) {
8 ; for (int i = 0; i < 8; i++)
13 ; Vector cost is 5, Scalar cost is 7
14 ; AVX: Adding cost -2 for reduction of n=8 [ %0 = load i32, ptr %p, align 4, ..] (It is a splitting reduction)
15 ; Vector cost is 4, Scalar cost is 7
16 ; SSE: Adding cost -3 for reduction of n=8 [ %0 = load i32, ptr %p, align 4, ..] (It is a splitting reduction)
17 define i32 @test_add(ptr nocapture readonly %p) {
18 ; CHECK-LABEL: @test_add(
20 ; CHECK-NEXT: [[TMP1:%.*]] = load <8 x i32>, ptr [[P:%.*]], align 4
21 ; CHECK-NEXT: [[TMP2:%.*]] = call i32 @llvm.vector.reduce.add.v8i32(<8 x i32> [[TMP1]])
22 ; CHECK-NEXT: ret i32 [[TMP2]]
25 %0 = load i32, ptr %p, align 4
26 %arrayidx.1 = getelementptr inbounds i32, ptr %p, i64 1
27 %1 = load i32, ptr %arrayidx.1, align 4
28 %mul.18 = add i32 %0, %1
29 %arrayidx.2 = getelementptr inbounds i32, ptr %p, i64 2
30 %2 = load i32, ptr %arrayidx.2, align 4
31 %mul.29 = add i32 %2, %mul.18
32 %arrayidx.3 = getelementptr inbounds i32, ptr %p, i64 3
33 %3 = load i32, ptr %arrayidx.3, align 4
34 %mul.310 = add i32 %3, %mul.29
35 %arrayidx.4 = getelementptr inbounds i32, ptr %p, i64 4
36 %4 = load i32, ptr %arrayidx.4, align 4
37 %mul.411 = add i32 %4, %mul.310
38 %arrayidx.5 = getelementptr inbounds i32, ptr %p, i64 5
39 %5 = load i32, ptr %arrayidx.5, align 4
40 %mul.512 = add i32 %5, %mul.411
41 %arrayidx.6 = getelementptr inbounds i32, ptr %p, i64 6
42 %6 = load i32, ptr %arrayidx.6, align 4
43 %mul.613 = add i32 %6, %mul.512
44 %arrayidx.7 = getelementptr inbounds i32, ptr %p, i64 7
45 %7 = load i32, ptr %arrayidx.7, align 4
46 %mul.714 = add i32 %7, %mul.613
50 ; int test_mul(unsigned int *p) {
52 ; for (int i = 0; i < 8; i++)
57 define i32 @test_mul(ptr nocapture readonly %p) {
58 ; AVX-LABEL: @test_mul(
60 ; AVX-NEXT: [[TMP1:%.*]] = load <8 x i32>, ptr [[P:%.*]], align 4
61 ; AVX-NEXT: [[TMP2:%.*]] = call i32 @llvm.vector.reduce.mul.v8i32(<8 x i32> [[TMP1]])
62 ; AVX-NEXT: ret i32 [[TMP2]]
64 ; SSE-LABEL: @test_mul(
66 ; SSE-NEXT: [[TMP0:%.*]] = load i32, ptr [[P:%.*]], align 4
67 ; SSE-NEXT: [[ARRAYIDX_1:%.*]] = getelementptr inbounds i32, ptr [[P]], i64 1
68 ; SSE-NEXT: [[TMP1:%.*]] = load i32, ptr [[ARRAYIDX_1]], align 4
69 ; SSE-NEXT: [[MUL_18:%.*]] = mul i32 [[TMP1]], [[TMP0]]
70 ; SSE-NEXT: [[ARRAYIDX_2:%.*]] = getelementptr inbounds i32, ptr [[P]], i64 2
71 ; SSE-NEXT: [[TMP2:%.*]] = load i32, ptr [[ARRAYIDX_2]], align 4
72 ; SSE-NEXT: [[MUL_29:%.*]] = mul i32 [[TMP2]], [[MUL_18]]
73 ; SSE-NEXT: [[ARRAYIDX_3:%.*]] = getelementptr inbounds i32, ptr [[P]], i64 3
74 ; SSE-NEXT: [[TMP3:%.*]] = load i32, ptr [[ARRAYIDX_3]], align 4
75 ; SSE-NEXT: [[MUL_310:%.*]] = mul i32 [[TMP3]], [[MUL_29]]
76 ; SSE-NEXT: [[ARRAYIDX_4:%.*]] = getelementptr inbounds i32, ptr [[P]], i64 4
77 ; SSE-NEXT: [[TMP4:%.*]] = load i32, ptr [[ARRAYIDX_4]], align 4
78 ; SSE-NEXT: [[MUL_411:%.*]] = mul i32 [[TMP4]], [[MUL_310]]
79 ; SSE-NEXT: [[ARRAYIDX_5:%.*]] = getelementptr inbounds i32, ptr [[P]], i64 5
80 ; SSE-NEXT: [[TMP5:%.*]] = load i32, ptr [[ARRAYIDX_5]], align 4
81 ; SSE-NEXT: [[MUL_512:%.*]] = mul i32 [[TMP5]], [[MUL_411]]
82 ; SSE-NEXT: [[ARRAYIDX_6:%.*]] = getelementptr inbounds i32, ptr [[P]], i64 6
83 ; SSE-NEXT: [[TMP6:%.*]] = load i32, ptr [[ARRAYIDX_6]], align 4
84 ; SSE-NEXT: [[MUL_613:%.*]] = mul i32 [[TMP6]], [[MUL_512]]
85 ; SSE-NEXT: [[ARRAYIDX_7:%.*]] = getelementptr inbounds i32, ptr [[P]], i64 7
86 ; SSE-NEXT: [[TMP7:%.*]] = load i32, ptr [[ARRAYIDX_7]], align 4
87 ; SSE-NEXT: [[MUL_714:%.*]] = mul i32 [[TMP7]], [[MUL_613]]
88 ; SSE-NEXT: ret i32 [[MUL_714]]
91 %0 = load i32, ptr %p, align 4
92 %arrayidx.1 = getelementptr inbounds i32, ptr %p, i64 1
93 %1 = load i32, ptr %arrayidx.1, align 4
94 %mul.18 = mul i32 %1, %0
95 %arrayidx.2 = getelementptr inbounds i32, ptr %p, i64 2
96 %2 = load i32, ptr %arrayidx.2, align 4
97 %mul.29 = mul i32 %2, %mul.18
98 %arrayidx.3 = getelementptr inbounds i32, ptr %p, i64 3
99 %3 = load i32, ptr %arrayidx.3, align 4
100 %mul.310 = mul i32 %3, %mul.29
101 %arrayidx.4 = getelementptr inbounds i32, ptr %p, i64 4
102 %4 = load i32, ptr %arrayidx.4, align 4
103 %mul.411 = mul i32 %4, %mul.310
104 %arrayidx.5 = getelementptr inbounds i32, ptr %p, i64 5
105 %5 = load i32, ptr %arrayidx.5, align 4
106 %mul.512 = mul i32 %5, %mul.411
107 %arrayidx.6 = getelementptr inbounds i32, ptr %p, i64 6
108 %6 = load i32, ptr %arrayidx.6, align 4
109 %mul.613 = mul i32 %6, %mul.512
110 %arrayidx.7 = getelementptr inbounds i32, ptr %p, i64 7
111 %7 = load i32, ptr %arrayidx.7, align 4
112 %mul.714 = mul i32 %7, %mul.613
116 ; int test_and(unsigned int *p) {
118 ; for (int i = 0; i < 8; i++)
123 define i32 @test_and(ptr nocapture readonly %p) {
124 ; CHECK-LABEL: @test_and(
126 ; CHECK-NEXT: [[TMP1:%.*]] = load <8 x i32>, ptr [[P:%.*]], align 4
127 ; CHECK-NEXT: [[TMP2:%.*]] = call i32 @llvm.vector.reduce.and.v8i32(<8 x i32> [[TMP1]])
128 ; CHECK-NEXT: ret i32 [[TMP2]]
131 %0 = load i32, ptr %p, align 4
132 %arrayidx.1 = getelementptr inbounds i32, ptr %p, i64 1
133 %1 = load i32, ptr %arrayidx.1, align 4
134 %mul.18 = and i32 %1, %0
135 %arrayidx.2 = getelementptr inbounds i32, ptr %p, i64 2
136 %2 = load i32, ptr %arrayidx.2, align 4
137 %mul.29 = and i32 %2, %mul.18
138 %arrayidx.3 = getelementptr inbounds i32, ptr %p, i64 3
139 %3 = load i32, ptr %arrayidx.3, align 4
140 %mul.310 = and i32 %3, %mul.29
141 %arrayidx.4 = getelementptr inbounds i32, ptr %p, i64 4
142 %4 = load i32, ptr %arrayidx.4, align 4
143 %mul.411 = and i32 %4, %mul.310
144 %arrayidx.5 = getelementptr inbounds i32, ptr %p, i64 5
145 %5 = load i32, ptr %arrayidx.5, align 4
146 %mul.512 = and i32 %5, %mul.411
147 %arrayidx.6 = getelementptr inbounds i32, ptr %p, i64 6
148 %6 = load i32, ptr %arrayidx.6, align 4
149 %mul.613 = and i32 %6, %mul.512
150 %arrayidx.7 = getelementptr inbounds i32, ptr %p, i64 7
151 %7 = load i32, ptr %arrayidx.7, align 4
152 %mul.714 = and i32 %7, %mul.613
156 ; int test_or(unsigned int *p) {
158 ; for (int i = 0; i < 8; i++)
163 define i32 @test_or(ptr nocapture readonly %p) {
164 ; CHECK-LABEL: @test_or(
166 ; CHECK-NEXT: [[TMP1:%.*]] = load <8 x i32>, ptr [[P:%.*]], align 4
167 ; CHECK-NEXT: [[TMP2:%.*]] = call i32 @llvm.vector.reduce.or.v8i32(<8 x i32> [[TMP1]])
168 ; CHECK-NEXT: ret i32 [[TMP2]]
171 %0 = load i32, ptr %p, align 4
172 %arrayidx.1 = getelementptr inbounds i32, ptr %p, i64 1
173 %1 = load i32, ptr %arrayidx.1, align 4
174 %mul.18 = or i32 %1, %0
175 %arrayidx.2 = getelementptr inbounds i32, ptr %p, i64 2
176 %2 = load i32, ptr %arrayidx.2, align 4
177 %mul.29 = or i32 %2, %mul.18
178 %arrayidx.3 = getelementptr inbounds i32, ptr %p, i64 3
179 %3 = load i32, ptr %arrayidx.3, align 4
180 %mul.310 = or i32 %3, %mul.29
181 %arrayidx.4 = getelementptr inbounds i32, ptr %p, i64 4
182 %4 = load i32, ptr %arrayidx.4, align 4
183 %mul.411 = or i32 %4, %mul.310
184 %arrayidx.5 = getelementptr inbounds i32, ptr %p, i64 5
185 %5 = load i32, ptr %arrayidx.5, align 4
186 %mul.512 = or i32 %5, %mul.411
187 %arrayidx.6 = getelementptr inbounds i32, ptr %p, i64 6
188 %6 = load i32, ptr %arrayidx.6, align 4
189 %mul.613 = or i32 %6, %mul.512
190 %arrayidx.7 = getelementptr inbounds i32, ptr %p, i64 7
191 %7 = load i32, ptr %arrayidx.7, align 4
192 %mul.714 = or i32 %7, %mul.613
196 ; int test_xor(unsigned int *p) {
198 ; for (int i = 0; i < 8; i++)
203 define i32 @test_xor(ptr nocapture readonly %p) {
204 ; CHECK-LABEL: @test_xor(
206 ; CHECK-NEXT: [[TMP1:%.*]] = load <8 x i32>, ptr [[P:%.*]], align 4
207 ; CHECK-NEXT: [[TMP2:%.*]] = call i32 @llvm.vector.reduce.xor.v8i32(<8 x i32> [[TMP1]])
208 ; CHECK-NEXT: ret i32 [[TMP2]]
211 %0 = load i32, ptr %p, align 4
212 %arrayidx.1 = getelementptr inbounds i32, ptr %p, i64 1
213 %1 = load i32, ptr %arrayidx.1, align 4
214 %mul.18 = xor i32 %1, %0
215 %arrayidx.2 = getelementptr inbounds i32, ptr %p, i64 2
216 %2 = load i32, ptr %arrayidx.2, align 4
217 %mul.29 = xor i32 %2, %mul.18
218 %arrayidx.3 = getelementptr inbounds i32, ptr %p, i64 3
219 %3 = load i32, ptr %arrayidx.3, align 4
220 %mul.310 = xor i32 %3, %mul.29
221 %arrayidx.4 = getelementptr inbounds i32, ptr %p, i64 4
222 %4 = load i32, ptr %arrayidx.4, align 4
223 %mul.411 = xor i32 %4, %mul.310
224 %arrayidx.5 = getelementptr inbounds i32, ptr %p, i64 5
225 %5 = load i32, ptr %arrayidx.5, align 4
226 %mul.512 = xor i32 %5, %mul.411
227 %arrayidx.6 = getelementptr inbounds i32, ptr %p, i64 6
228 %6 = load i32, ptr %arrayidx.6, align 4
229 %mul.613 = xor i32 %6, %mul.512
230 %arrayidx.7 = getelementptr inbounds i32, ptr %p, i64 7
231 %7 = load i32, ptr %arrayidx.7, align 4
232 %mul.714 = xor i32 %7, %mul.613
236 define i32 @PR37731(ptr noalias nocapture dereferenceable(16) %self) unnamed_addr #0 {
237 ; CHECK-LABEL: @PR37731(
239 ; CHECK-NEXT: [[TMP0:%.*]] = load <4 x i32>, ptr [[SELF:%.*]], align 16
240 ; CHECK-NEXT: [[TMP1:%.*]] = shl <4 x i32> [[TMP0]], <i32 6, i32 2, i32 13, i32 3>
241 ; CHECK-NEXT: [[TMP2:%.*]] = xor <4 x i32> [[TMP1]], [[TMP0]]
242 ; CHECK-NEXT: [[TMP3:%.*]] = lshr <4 x i32> [[TMP2]], <i32 13, i32 27, i32 21, i32 12>
243 ; CHECK-NEXT: [[TMP4:%.*]] = and <4 x i32> [[TMP0]], <i32 -2, i32 -8, i32 -16, i32 -128>
244 ; CHECK-NEXT: [[TMP5:%.*]] = shl <4 x i32> [[TMP4]], <i32 18, i32 2, i32 7, i32 13>
245 ; CHECK-NEXT: [[TMP6:%.*]] = xor <4 x i32> [[TMP3]], [[TMP5]]
246 ; CHECK-NEXT: store <4 x i32> [[TMP6]], ptr [[SELF]], align 16
247 ; CHECK-NEXT: [[TMP7:%.*]] = call i32 @llvm.vector.reduce.xor.v4i32(<4 x i32> [[TMP6]])
248 ; CHECK-NEXT: ret i32 [[TMP7]]
251 %0 = load <4 x i32>, ptr %self, align 16
252 %1 = shl <4 x i32> %0, <i32 6, i32 2, i32 13, i32 3>
253 %2 = xor <4 x i32> %1, %0
254 %3 = lshr <4 x i32> %2, <i32 13, i32 27, i32 21, i32 12>
255 %4 = and <4 x i32> %0, <i32 -2, i32 -8, i32 -16, i32 -128>
256 %5 = shl <4 x i32> %4, <i32 18, i32 2, i32 7, i32 13>
257 %6 = xor <4 x i32> %3, %5
258 store <4 x i32> %6, ptr %self, align 16
259 %7 = extractelement <4 x i32> %6, i32 0
260 %8 = extractelement <4 x i32> %6, i32 1
262 %10 = extractelement <4 x i32> %6, i32 2
263 %11 = xor i32 %9, %10
264 %12 = extractelement <4 x i32> %6, i32 3
265 %13 = xor i32 %11, %12