1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=slp-vectorizer -S -mtriple=x86_64-unknown-linux-gnu -mcpu=skylake-avx512 | FileCheck %s
4 %struct.S = type { [8 x i32], [8 x i32], [16 x i32] }
6 define dso_local void @_Z4testP1S(ptr %p) local_unnamed_addr {
7 ; CHECK-LABEL: @_Z4testP1S(
9 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds [[STRUCT_S:%.*]], ptr [[P:%.*]], i64 0, i32 1, i64 0
10 ; CHECK-NEXT: [[ARRAYIDX1:%.*]] = getelementptr inbounds [[STRUCT_S]], ptr [[P]], i64 0, i32 2, i64 15
11 ; CHECK-NEXT: [[ARRAYIDX6:%.*]] = getelementptr inbounds [[STRUCT_S]], ptr [[P]], i64 0, i32 2, i64 7
12 ; CHECK-NEXT: [[ARRAYIDX13:%.*]] = getelementptr inbounds [[STRUCT_S]], ptr [[P]], i64 0, i32 2, i64 6
13 ; CHECK-NEXT: [[ARRAYIDX20:%.*]] = getelementptr inbounds [[STRUCT_S]], ptr [[P]], i64 0, i32 2, i64 4
14 ; CHECK-NEXT: [[ARRAYIDX27:%.*]] = getelementptr inbounds [[STRUCT_S]], ptr [[P]], i64 0, i32 2, i64 12
15 ; CHECK-NEXT: [[ARRAYIDX34:%.*]] = getelementptr inbounds [[STRUCT_S]], ptr [[P]], i64 0, i32 2, i64 13
16 ; CHECK-NEXT: [[ARRAYIDX41:%.*]] = getelementptr inbounds [[STRUCT_S]], ptr [[P]], i64 0, i32 2, i64 14
17 ; CHECK-NEXT: [[ARRAYIDX48:%.*]] = getelementptr inbounds [[STRUCT_S]], ptr [[P]], i64 0, i32 2, i64 5
18 ; CHECK-NEXT: [[TMP1:%.*]] = load <8 x i32>, ptr [[ARRAYIDX]], align 4
19 ; CHECK-NEXT: [[TMP2:%.*]] = insertelement <8 x ptr> poison, ptr [[ARRAYIDX1]], i32 0
20 ; CHECK-NEXT: [[TMP3:%.*]] = insertelement <8 x ptr> [[TMP2]], ptr [[ARRAYIDX6]], i32 1
21 ; CHECK-NEXT: [[TMP4:%.*]] = insertelement <8 x ptr> [[TMP3]], ptr [[ARRAYIDX13]], i32 2
22 ; CHECK-NEXT: [[TMP5:%.*]] = insertelement <8 x ptr> [[TMP4]], ptr [[ARRAYIDX20]], i32 3
23 ; CHECK-NEXT: [[TMP6:%.*]] = insertelement <8 x ptr> [[TMP5]], ptr [[ARRAYIDX27]], i32 4
24 ; CHECK-NEXT: [[TMP7:%.*]] = insertelement <8 x ptr> [[TMP6]], ptr [[ARRAYIDX34]], i32 5
25 ; CHECK-NEXT: [[TMP8:%.*]] = insertelement <8 x ptr> [[TMP7]], ptr [[ARRAYIDX41]], i32 6
26 ; CHECK-NEXT: [[TMP9:%.*]] = insertelement <8 x ptr> [[TMP8]], ptr [[ARRAYIDX48]], i32 7
27 ; CHECK-NEXT: [[TMP10:%.*]] = call <8 x i32> @llvm.masked.gather.v8i32.v8p0(<8 x ptr> [[TMP9]], i32 4, <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>, <8 x i32> poison)
28 ; CHECK-NEXT: [[TMP11:%.*]] = add nsw <8 x i32> [[TMP10]], [[TMP1]]
29 ; CHECK-NEXT: store <8 x i32> [[TMP11]], ptr [[P]], align 4
30 ; CHECK-NEXT: ret void
33 %arrayidx = getelementptr inbounds %struct.S, ptr %p, i64 0, i32 1, i64 0
34 %i = load i32, ptr %arrayidx, align 4
35 %arrayidx1 = getelementptr inbounds %struct.S, ptr %p, i64 0, i32 2, i64 15
36 %i1 = load i32, ptr %arrayidx1, align 4
37 %add = add nsw i32 %i1, %i
38 store i32 %add, ptr %p, align 4
39 %arrayidx4 = getelementptr inbounds %struct.S, ptr %p, i64 0, i32 1, i64 1
40 %i2 = load i32, ptr %arrayidx4, align 4
41 %arrayidx6 = getelementptr inbounds %struct.S, ptr %p, i64 0, i32 2, i64 7
42 %i3 = load i32, ptr %arrayidx6, align 4
43 %add7 = add nsw i32 %i3, %i2
44 %arrayidx9 = getelementptr inbounds %struct.S, ptr %p, i64 0, i32 0, i64 1
45 store i32 %add7, ptr %arrayidx9, align 4
46 %arrayidx11 = getelementptr inbounds %struct.S, ptr %p, i64 0, i32 1, i64 2
47 %i4 = load i32, ptr %arrayidx11, align 4
48 %arrayidx13 = getelementptr inbounds %struct.S, ptr %p, i64 0, i32 2, i64 6
49 %i5 = load i32, ptr %arrayidx13, align 4
50 %add14 = add nsw i32 %i5, %i4
51 %arrayidx16 = getelementptr inbounds %struct.S, ptr %p, i64 0, i32 0, i64 2
52 store i32 %add14, ptr %arrayidx16, align 4
53 %arrayidx18 = getelementptr inbounds %struct.S, ptr %p, i64 0, i32 1, i64 3
54 %i6 = load i32, ptr %arrayidx18, align 4
55 %arrayidx20 = getelementptr inbounds %struct.S, ptr %p, i64 0, i32 2, i64 4
56 %i7 = load i32, ptr %arrayidx20, align 4
57 %add21 = add nsw i32 %i7, %i6
58 %arrayidx23 = getelementptr inbounds %struct.S, ptr %p, i64 0, i32 0, i64 3
59 store i32 %add21, ptr %arrayidx23, align 4
60 %arrayidx25 = getelementptr inbounds %struct.S, ptr %p, i64 0, i32 1, i64 4
61 %i8 = load i32, ptr %arrayidx25, align 4
62 %arrayidx27 = getelementptr inbounds %struct.S, ptr %p, i64 0, i32 2, i64 12
63 %i9 = load i32, ptr %arrayidx27, align 4
64 %add28 = add nsw i32 %i9, %i8
65 %arrayidx30 = getelementptr inbounds %struct.S, ptr %p, i64 0, i32 0, i64 4
66 store i32 %add28, ptr %arrayidx30, align 4
67 %arrayidx32 = getelementptr inbounds %struct.S, ptr %p, i64 0, i32 1, i64 5
68 %i10 = load i32, ptr %arrayidx32, align 4
69 %arrayidx34 = getelementptr inbounds %struct.S, ptr %p, i64 0, i32 2, i64 13
70 %i11 = load i32, ptr %arrayidx34, align 4
71 %add35 = add nsw i32 %i11, %i10
72 %arrayidx37 = getelementptr inbounds %struct.S, ptr %p, i64 0, i32 0, i64 5
73 store i32 %add35, ptr %arrayidx37, align 4
74 %arrayidx39 = getelementptr inbounds %struct.S, ptr %p, i64 0, i32 1, i64 6
75 %i12 = load i32, ptr %arrayidx39, align 4
76 %arrayidx41 = getelementptr inbounds %struct.S, ptr %p, i64 0, i32 2, i64 14
77 %i13 = load i32, ptr %arrayidx41, align 4
78 %add42 = add nsw i32 %i13, %i12
79 %arrayidx44 = getelementptr inbounds %struct.S, ptr %p, i64 0, i32 0, i64 6
80 store i32 %add42, ptr %arrayidx44, align 4
81 %arrayidx46 = getelementptr inbounds %struct.S, ptr %p, i64 0, i32 1, i64 7
82 %i14 = load i32, ptr %arrayidx46, align 4
83 %arrayidx48 = getelementptr inbounds %struct.S, ptr %p, i64 0, i32 2, i64 5
84 %i15 = load i32, ptr %arrayidx48, align 4
85 %add49 = add nsw i32 %i15, %i14
86 %arrayidx51 = getelementptr inbounds %struct.S, ptr %p, i64 0, i32 0, i64 7
87 store i32 %add49, ptr %arrayidx51, align 4
91 ; Test for 2 load groups 4 elements each against different base pointers.
92 ; Both loaded groups are not ordered thus here are few specific points:
93 ; (1) these groups are detected, (2) reordereing shuffles generated and
94 ; (3) these loads vectorized as a part of tree that is seeded by stores
97 define dso_local void @test_unordered_splits(ptr nocapture %p) local_unnamed_addr {
98 ; CHECK-LABEL: @test_unordered_splits(
100 ; CHECK-NEXT: [[P1:%.*]] = alloca [16 x i32], align 16
101 ; CHECK-NEXT: [[P2:%.*]] = alloca [16 x i32], align 16
102 ; CHECK-NEXT: [[G10:%.*]] = getelementptr inbounds [16 x i32], ptr [[P1]], i32 0, i64 4
103 ; CHECK-NEXT: [[G20:%.*]] = getelementptr inbounds [16 x i32], ptr [[P2]], i32 0, i64 12
104 ; CHECK-NEXT: [[TMP1:%.*]] = load <4 x i32>, ptr [[G10]], align 4
105 ; CHECK-NEXT: [[TMP3:%.*]] = load <4 x i32>, ptr [[G20]], align 4
106 ; CHECK-NEXT: [[TMP4:%.*]] = shufflevector <4 x i32> [[TMP1]], <4 x i32> poison, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 poison, i32 poison, i32 poison, i32 poison>
107 ; CHECK-NEXT: [[TMP5:%.*]] = shufflevector <4 x i32> [[TMP3]], <4 x i32> poison, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 poison, i32 poison, i32 poison, i32 poison>
108 ; CHECK-NEXT: [[TMP6:%.*]] = shufflevector <8 x i32> [[TMP4]], <8 x i32> [[TMP5]], <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 8, i32 9, i32 10, i32 11>
109 ; CHECK-NEXT: [[SHUFFLE:%.*]] = shufflevector <8 x i32> [[TMP6]], <8 x i32> poison, <8 x i32> <i32 1, i32 0, i32 2, i32 3, i32 7, i32 5, i32 6, i32 4>
110 ; CHECK-NEXT: store <8 x i32> [[SHUFFLE]], ptr [[P:%.*]], align 4
111 ; CHECK-NEXT: ret void
114 %p1 = alloca [16 x i32], align 16
115 %p2 = alloca [16 x i32], align 16
116 %g10 = getelementptr inbounds [16 x i32], ptr %p1, i32 0, i64 4
117 %g11 = getelementptr inbounds [16 x i32], ptr %p1, i32 0, i64 5
118 %g12 = getelementptr inbounds [16 x i32], ptr %p1, i32 0, i64 6
119 %g13 = getelementptr inbounds [16 x i32], ptr %p1, i32 0, i64 7
120 %g20 = getelementptr inbounds [16 x i32], ptr %p2, i32 0, i64 12
121 %g21 = getelementptr inbounds [16 x i32], ptr %p2, i32 0, i64 13
122 %g22 = getelementptr inbounds [16 x i32], ptr %p2, i32 0, i64 14
123 %g23 = getelementptr inbounds [16 x i32], ptr %p2, i32 0, i64 15
124 %i1 = load i32, ptr %g11, align 4
125 store i32 %i1, ptr %p, align 4
126 %i3 = load i32, ptr %g10, align 4
127 %arrayidx9 = getelementptr inbounds %struct.S, ptr %p, i64 0, i32 0, i64 1
128 store i32 %i3, ptr %arrayidx9, align 4
129 %i5 = load i32, ptr %g12, align 4
130 %arrayidx16 = getelementptr inbounds %struct.S, ptr %p, i64 0, i32 0, i64 2
131 store i32 %i5, ptr %arrayidx16, align 4
132 %i7 = load i32, ptr %g13, align 4
133 %arrayidx23 = getelementptr inbounds %struct.S, ptr %p, i64 0, i32 0, i64 3
134 store i32 %i7, ptr %arrayidx23, align 4
135 %i9 = load i32, ptr %g23, align 4
136 %arrayidx30 = getelementptr inbounds %struct.S, ptr %p, i64 0, i32 0, i64 4
137 store i32 %i9, ptr %arrayidx30, align 4
138 %i11 = load i32, ptr %g21, align 4
139 %arrayidx37 = getelementptr inbounds %struct.S, ptr %p, i64 0, i32 0, i64 5
140 store i32 %i11, ptr %arrayidx37, align 4
141 %i13 = load i32, ptr %g22, align 4
142 %arrayidx44 = getelementptr inbounds %struct.S, ptr %p, i64 0, i32 0, i64 6
143 store i32 %i13, ptr %arrayidx44, align 4
144 %i15 = load i32, ptr %g20, align 4
145 %arrayidx51 = getelementptr inbounds %struct.S, ptr %p, i64 0, i32 0, i64 7
146 store i32 %i15, ptr %arrayidx51, align 4
150 define dso_local void @test_cost_splits(ptr nocapture %p) local_unnamed_addr {
151 ; CHECK-LABEL: @test_cost_splits(
153 ; CHECK-NEXT: [[P1:%.*]] = alloca [16 x i32], align 16
154 ; CHECK-NEXT: [[P2:%.*]] = alloca [16 x i32], align 16
155 ; CHECK-NEXT: [[P3:%.*]] = alloca [16 x i32], align 16
156 ; CHECK-NEXT: [[P4:%.*]] = alloca [16 x i32], align 16
157 ; CHECK-NEXT: [[G10:%.*]] = getelementptr inbounds [16 x i32], ptr [[P1]], i32 0, i64 4
158 ; CHECK-NEXT: [[G12:%.*]] = getelementptr inbounds [16 x i32], ptr [[P2]], i32 0, i64 6
159 ; CHECK-NEXT: [[G20:%.*]] = getelementptr inbounds [16 x i32], ptr [[P3]], i32 0, i64 12
160 ; CHECK-NEXT: [[G22:%.*]] = getelementptr inbounds [16 x i32], ptr [[P4]], i32 0, i64 14
161 ; CHECK-NEXT: [[TMP1:%.*]] = load <2 x i32>, ptr [[G10]], align 4
162 ; CHECK-NEXT: [[TMP3:%.*]] = load <2 x i32>, ptr [[G12]], align 4
163 ; CHECK-NEXT: [[TMP5:%.*]] = load <2 x i32>, ptr [[G20]], align 4
164 ; CHECK-NEXT: [[TMP7:%.*]] = load <2 x i32>, ptr [[G22]], align 4
165 ; CHECK-NEXT: [[TMP8:%.*]] = shufflevector <2 x i32> [[TMP1]], <2 x i32> poison, <8 x i32> <i32 0, i32 1, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
166 ; CHECK-NEXT: [[TMP9:%.*]] = shufflevector <2 x i32> [[TMP3]], <2 x i32> poison, <8 x i32> <i32 0, i32 1, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
167 ; CHECK-NEXT: [[TMP10:%.*]] = shufflevector <8 x i32> [[TMP8]], <8 x i32> [[TMP9]], <8 x i32> <i32 0, i32 1, i32 8, i32 9, i32 poison, i32 poison, i32 poison, i32 poison>
168 ; CHECK-NEXT: [[TMP11:%.*]] = shufflevector <2 x i32> [[TMP5]], <2 x i32> poison, <8 x i32> <i32 0, i32 1, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
169 ; CHECK-NEXT: [[TMP12:%.*]] = shufflevector <8 x i32> [[TMP10]], <8 x i32> [[TMP11]], <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 8, i32 9, i32 poison, i32 poison>
170 ; CHECK-NEXT: [[TMP13:%.*]] = shufflevector <2 x i32> [[TMP7]], <2 x i32> poison, <8 x i32> <i32 0, i32 1, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
171 ; CHECK-NEXT: [[TMP14:%.*]] = shufflevector <8 x i32> [[TMP12]], <8 x i32> [[TMP13]], <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 8, i32 9>
172 ; CHECK-NEXT: store <8 x i32> [[TMP14]], ptr [[P:%.*]], align 4
173 ; CHECK-NEXT: ret void
176 %p1 = alloca [16 x i32], align 16
177 %p2 = alloca [16 x i32], align 16
178 %p3 = alloca [16 x i32], align 16
179 %p4 = alloca [16 x i32], align 16
180 %g10 = getelementptr inbounds [16 x i32], ptr %p1, i32 0, i64 4
181 %g11 = getelementptr inbounds [16 x i32], ptr %p1, i32 0, i64 5
182 %g12 = getelementptr inbounds [16 x i32], ptr %p2, i32 0, i64 6
183 %g13 = getelementptr inbounds [16 x i32], ptr %p2, i32 0, i64 7
184 %g20 = getelementptr inbounds [16 x i32], ptr %p3, i32 0, i64 12
185 %g21 = getelementptr inbounds [16 x i32], ptr %p3, i32 0, i64 13
186 %g22 = getelementptr inbounds [16 x i32], ptr %p4, i32 0, i64 14
187 %g23 = getelementptr inbounds [16 x i32], ptr %p4, i32 0, i64 15
188 %i1 = load i32, ptr %g10, align 4
189 store i32 %i1, ptr %p, align 4
190 %i3 = load i32, ptr %g11, align 4
191 %arrayidx9 = getelementptr inbounds %struct.S, ptr %p, i64 0, i32 0, i64 1
192 store i32 %i3, ptr %arrayidx9, align 4
193 %i5 = load i32, ptr %g12, align 4
194 %arrayidx16 = getelementptr inbounds %struct.S, ptr %p, i64 0, i32 0, i64 2
195 store i32 %i5, ptr %arrayidx16, align 4
196 %i7 = load i32, ptr %g13, align 4
197 %arrayidx23 = getelementptr inbounds %struct.S, ptr %p, i64 0, i32 0, i64 3
198 store i32 %i7, ptr %arrayidx23, align 4
199 %i9 = load i32, ptr %g20, align 4
200 %arrayidx30 = getelementptr inbounds %struct.S, ptr %p, i64 0, i32 0, i64 4
201 store i32 %i9, ptr %arrayidx30, align 4
202 %i11 = load i32, ptr %g21, align 4
203 %arrayidx37 = getelementptr inbounds %struct.S, ptr %p, i64 0, i32 0, i64 5
204 store i32 %i11, ptr %arrayidx37, align 4
205 %i13 = load i32, ptr %g22, align 4
206 %arrayidx44 = getelementptr inbounds %struct.S, ptr %p, i64 0, i32 0, i64 6
207 store i32 %i13, ptr %arrayidx44, align 4
208 %i15 = load i32, ptr %g23, align 4
209 %arrayidx51 = getelementptr inbounds %struct.S, ptr %p, i64 0, i32 0, i64 7
210 store i32 %i15, ptr %arrayidx51, align 4