1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -codegenprepare -mcpu=corei7 %s | FileCheck %s --check-prefixes=CHECK,CHECK-SSE2
3 ; RUN: opt -S -codegenprepare -mcpu=bdver2 %s | FileCheck %s --check-prefixes=CHECK,CHECK-XOP
4 ; RUN: opt -S -codegenprepare -mcpu=core-avx2 %s | FileCheck %s --check-prefixes=CHECK,CHECK-AVX,CHECK-AVX2
5 ; RUN: opt -S -codegenprepare -mcpu=skylake-avx512 %s | FileCheck %s --check-prefixes=CHECK,CHECK-AVX,CHECK-AVX512BW
7 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
8 target triple = "x86_64-apple-darwin10.9.0"
10 define <16 x i8> @test_8bit(<16 x i8> %lhs, <16 x i8> %tmp, i1 %tst) {
11 ; CHECK-LABEL: @test_8bit(
12 ; CHECK-NEXT: [[MASK:%.*]] = shufflevector <16 x i8> [[TMP:%.*]], <16 x i8> poison, <16 x i32> zeroinitializer
13 ; CHECK-NEXT: br i1 [[TST:%.*]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
15 ; CHECK-NEXT: ret <16 x i8> [[MASK]]
17 ; CHECK-NEXT: [[RES:%.*]] = shl <16 x i8> [[LHS:%.*]], [[MASK]]
18 ; CHECK-NEXT: ret <16 x i8> [[RES]]
20 %mask = shufflevector <16 x i8> %tmp, <16 x i8> poison, <16 x i32> zeroinitializer
21 br i1 %tst, label %if_true, label %if_false
27 %res = shl <16 x i8> %lhs, %mask
31 define <8 x i16> @test_16bit(<8 x i16> %lhs, <8 x i16> %tmp, i1 %tst) {
32 ; CHECK-SSE2-LABEL: @test_16bit(
33 ; CHECK-SSE2-NEXT: [[MASK:%.*]] = shufflevector <8 x i16> [[TMP:%.*]], <8 x i16> poison, <8 x i32> zeroinitializer
34 ; CHECK-SSE2-NEXT: br i1 [[TST:%.*]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
35 ; CHECK-SSE2: if_true:
36 ; CHECK-SSE2-NEXT: ret <8 x i16> [[MASK]]
37 ; CHECK-SSE2: if_false:
38 ; CHECK-SSE2-NEXT: [[TMP1:%.*]] = shufflevector <8 x i16> [[TMP]], <8 x i16> poison, <8 x i32> zeroinitializer
39 ; CHECK-SSE2-NEXT: [[RES:%.*]] = shl <8 x i16> [[LHS:%.*]], [[TMP1]]
40 ; CHECK-SSE2-NEXT: ret <8 x i16> [[RES]]
42 ; CHECK-XOP-LABEL: @test_16bit(
43 ; CHECK-XOP-NEXT: [[MASK:%.*]] = shufflevector <8 x i16> [[TMP:%.*]], <8 x i16> poison, <8 x i32> zeroinitializer
44 ; CHECK-XOP-NEXT: br i1 [[TST:%.*]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
46 ; CHECK-XOP-NEXT: ret <8 x i16> [[MASK]]
47 ; CHECK-XOP: if_false:
48 ; CHECK-XOP-NEXT: [[RES:%.*]] = shl <8 x i16> [[LHS:%.*]], [[MASK]]
49 ; CHECK-XOP-NEXT: ret <8 x i16> [[RES]]
51 ; CHECK-AVX2-LABEL: @test_16bit(
52 ; CHECK-AVX2-NEXT: [[MASK:%.*]] = shufflevector <8 x i16> [[TMP:%.*]], <8 x i16> poison, <8 x i32> zeroinitializer
53 ; CHECK-AVX2-NEXT: br i1 [[TST:%.*]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
54 ; CHECK-AVX2: if_true:
55 ; CHECK-AVX2-NEXT: ret <8 x i16> [[MASK]]
56 ; CHECK-AVX2: if_false:
57 ; CHECK-AVX2-NEXT: [[TMP1:%.*]] = shufflevector <8 x i16> [[TMP]], <8 x i16> poison, <8 x i32> zeroinitializer
58 ; CHECK-AVX2-NEXT: [[RES:%.*]] = shl <8 x i16> [[LHS:%.*]], [[TMP1]]
59 ; CHECK-AVX2-NEXT: ret <8 x i16> [[RES]]
61 ; CHECK-AVX512BW-LABEL: @test_16bit(
62 ; CHECK-AVX512BW-NEXT: [[MASK:%.*]] = shufflevector <8 x i16> [[TMP:%.*]], <8 x i16> poison, <8 x i32> zeroinitializer
63 ; CHECK-AVX512BW-NEXT: br i1 [[TST:%.*]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
64 ; CHECK-AVX512BW: if_true:
65 ; CHECK-AVX512BW-NEXT: ret <8 x i16> [[MASK]]
66 ; CHECK-AVX512BW: if_false:
67 ; CHECK-AVX512BW-NEXT: [[RES:%.*]] = shl <8 x i16> [[LHS:%.*]], [[MASK]]
68 ; CHECK-AVX512BW-NEXT: ret <8 x i16> [[RES]]
70 %mask = shufflevector <8 x i16> %tmp, <8 x i16> poison, <8 x i32> zeroinitializer
71 br i1 %tst, label %if_true, label %if_false
77 %res = shl <8 x i16> %lhs, %mask
81 define <4 x i32> @test_notsplat(<4 x i32> %lhs, <4 x i32> %tmp, i1 %tst) {
82 ; CHECK-LABEL: @test_notsplat(
83 ; CHECK-NEXT: [[MASK:%.*]] = shufflevector <4 x i32> [[TMP:%.*]], <4 x i32> poison, <4 x i32> <i32 0, i32 1, i32 1, i32 0>
84 ; CHECK-NEXT: br i1 [[TST:%.*]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
86 ; CHECK-NEXT: ret <4 x i32> [[MASK]]
88 ; CHECK-NEXT: [[RES:%.*]] = shl <4 x i32> [[LHS:%.*]], [[MASK]]
89 ; CHECK-NEXT: ret <4 x i32> [[RES]]
91 %mask = shufflevector <4 x i32> %tmp, <4 x i32> poison, <4 x i32> <i32 0, i32 1, i32 1, i32 0>
92 br i1 %tst, label %if_true, label %if_false
98 %res = shl <4 x i32> %lhs, %mask
102 define <4 x i32> @test_32bit(<4 x i32> %lhs, <4 x i32> %tmp, i1 %tst) {
103 ; CHECK-SSE2-LABEL: @test_32bit(
104 ; CHECK-SSE2-NEXT: [[MASK:%.*]] = shufflevector <4 x i32> [[TMP:%.*]], <4 x i32> poison, <4 x i32> <i32 0, i32 undef, i32 0, i32 0>
105 ; CHECK-SSE2-NEXT: br i1 [[TST:%.*]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
106 ; CHECK-SSE2: if_true:
107 ; CHECK-SSE2-NEXT: ret <4 x i32> [[MASK]]
108 ; CHECK-SSE2: if_false:
109 ; CHECK-SSE2-NEXT: [[TMP1:%.*]] = shufflevector <4 x i32> [[TMP]], <4 x i32> poison, <4 x i32> <i32 0, i32 undef, i32 0, i32 0>
110 ; CHECK-SSE2-NEXT: [[RES:%.*]] = ashr <4 x i32> [[LHS:%.*]], [[TMP1]]
111 ; CHECK-SSE2-NEXT: ret <4 x i32> [[RES]]
113 ; CHECK-XOP-LABEL: @test_32bit(
114 ; CHECK-XOP-NEXT: [[MASK:%.*]] = shufflevector <4 x i32> [[TMP:%.*]], <4 x i32> poison, <4 x i32> <i32 0, i32 undef, i32 0, i32 0>
115 ; CHECK-XOP-NEXT: br i1 [[TST:%.*]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
116 ; CHECK-XOP: if_true:
117 ; CHECK-XOP-NEXT: ret <4 x i32> [[MASK]]
118 ; CHECK-XOP: if_false:
119 ; CHECK-XOP-NEXT: [[RES:%.*]] = ashr <4 x i32> [[LHS:%.*]], [[MASK]]
120 ; CHECK-XOP-NEXT: ret <4 x i32> [[RES]]
122 ; CHECK-AVX-LABEL: @test_32bit(
123 ; CHECK-AVX-NEXT: [[MASK:%.*]] = shufflevector <4 x i32> [[TMP:%.*]], <4 x i32> poison, <4 x i32> <i32 0, i32 undef, i32 0, i32 0>
124 ; CHECK-AVX-NEXT: br i1 [[TST:%.*]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
125 ; CHECK-AVX: if_true:
126 ; CHECK-AVX-NEXT: ret <4 x i32> [[MASK]]
127 ; CHECK-AVX: if_false:
128 ; CHECK-AVX-NEXT: [[RES:%.*]] = ashr <4 x i32> [[LHS:%.*]], [[MASK]]
129 ; CHECK-AVX-NEXT: ret <4 x i32> [[RES]]
131 %mask = shufflevector <4 x i32> %tmp, <4 x i32> poison, <4 x i32> <i32 0, i32 undef, i32 0, i32 0>
132 br i1 %tst, label %if_true, label %if_false
138 %res = ashr <4 x i32> %lhs, %mask
142 define <2 x i64> @test_64bit(<2 x i64> %lhs, <2 x i64> %tmp, i1 %tst) {
143 ; CHECK-SSE2-LABEL: @test_64bit(
144 ; CHECK-SSE2-NEXT: [[MASK:%.*]] = shufflevector <2 x i64> [[TMP:%.*]], <2 x i64> poison, <2 x i32> zeroinitializer
145 ; CHECK-SSE2-NEXT: br i1 [[TST:%.*]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
146 ; CHECK-SSE2: if_true:
147 ; CHECK-SSE2-NEXT: ret <2 x i64> [[MASK]]
148 ; CHECK-SSE2: if_false:
149 ; CHECK-SSE2-NEXT: [[TMP1:%.*]] = shufflevector <2 x i64> [[TMP]], <2 x i64> poison, <2 x i32> zeroinitializer
150 ; CHECK-SSE2-NEXT: [[RES:%.*]] = lshr <2 x i64> [[LHS:%.*]], [[TMP1]]
151 ; CHECK-SSE2-NEXT: ret <2 x i64> [[RES]]
153 ; CHECK-XOP-LABEL: @test_64bit(
154 ; CHECK-XOP-NEXT: [[MASK:%.*]] = shufflevector <2 x i64> [[TMP:%.*]], <2 x i64> poison, <2 x i32> zeroinitializer
155 ; CHECK-XOP-NEXT: br i1 [[TST:%.*]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
156 ; CHECK-XOP: if_true:
157 ; CHECK-XOP-NEXT: ret <2 x i64> [[MASK]]
158 ; CHECK-XOP: if_false:
159 ; CHECK-XOP-NEXT: [[RES:%.*]] = lshr <2 x i64> [[LHS:%.*]], [[MASK]]
160 ; CHECK-XOP-NEXT: ret <2 x i64> [[RES]]
162 ; CHECK-AVX-LABEL: @test_64bit(
163 ; CHECK-AVX-NEXT: [[MASK:%.*]] = shufflevector <2 x i64> [[TMP:%.*]], <2 x i64> poison, <2 x i32> zeroinitializer
164 ; CHECK-AVX-NEXT: br i1 [[TST:%.*]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
165 ; CHECK-AVX: if_true:
166 ; CHECK-AVX-NEXT: ret <2 x i64> [[MASK]]
167 ; CHECK-AVX: if_false:
168 ; CHECK-AVX-NEXT: [[RES:%.*]] = lshr <2 x i64> [[LHS:%.*]], [[MASK]]
169 ; CHECK-AVX-NEXT: ret <2 x i64> [[RES]]
171 %mask = shufflevector <2 x i64> %tmp, <2 x i64> poison, <2 x i32> zeroinitializer
172 br i1 %tst, label %if_true, label %if_false
178 %res = lshr <2 x i64> %lhs, %mask
182 define void @funnel_splatvar(i32* nocapture %arr, i32 %rot) {
183 ; CHECK-SSE2-LABEL: @funnel_splatvar(
184 ; CHECK-SSE2-NEXT: entry:
185 ; CHECK-SSE2-NEXT: [[BROADCAST_SPLATINSERT15:%.*]] = insertelement <8 x i32> poison, i32 [[ROT:%.*]], i32 0
186 ; CHECK-SSE2-NEXT: br label [[VECTOR_BODY:%.*]]
187 ; CHECK-SSE2: vector.body:
188 ; CHECK-SSE2-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
189 ; CHECK-SSE2-NEXT: [[T0:%.*]] = getelementptr inbounds i32, i32* [[ARR:%.*]], i64 [[INDEX]]
190 ; CHECK-SSE2-NEXT: [[T1:%.*]] = bitcast i32* [[T0]] to <8 x i32>*
191 ; CHECK-SSE2-NEXT: [[WIDE_LOAD:%.*]] = load <8 x i32>, <8 x i32>* [[T1]], align 4
192 ; CHECK-SSE2-NEXT: [[TMP0:%.*]] = shufflevector <8 x i32> [[BROADCAST_SPLATINSERT15]], <8 x i32> poison, <8 x i32> zeroinitializer
193 ; CHECK-SSE2-NEXT: [[T2:%.*]] = call <8 x i32> @llvm.fshl.v8i32(<8 x i32> [[WIDE_LOAD]], <8 x i32> [[WIDE_LOAD]], <8 x i32> [[TMP0]])
194 ; CHECK-SSE2-NEXT: store <8 x i32> [[T2]], <8 x i32>* [[T1]], align 4
195 ; CHECK-SSE2-NEXT: [[INDEX_NEXT]] = add i64 [[INDEX]], 8
196 ; CHECK-SSE2-NEXT: [[T3:%.*]] = icmp eq i64 [[INDEX_NEXT]], 65536
197 ; CHECK-SSE2-NEXT: br i1 [[T3]], label [[FOR_COND_CLEANUP:%.*]], label [[VECTOR_BODY]]
198 ; CHECK-SSE2: for.cond.cleanup:
199 ; CHECK-SSE2-NEXT: ret void
201 ; CHECK-XOP-LABEL: @funnel_splatvar(
202 ; CHECK-XOP-NEXT: entry:
203 ; CHECK-XOP-NEXT: [[BROADCAST_SPLATINSERT15:%.*]] = insertelement <8 x i32> poison, i32 [[ROT:%.*]], i32 0
204 ; CHECK-XOP-NEXT: [[BROADCAST_SPLAT16:%.*]] = shufflevector <8 x i32> [[BROADCAST_SPLATINSERT15]], <8 x i32> poison, <8 x i32> zeroinitializer
205 ; CHECK-XOP-NEXT: br label [[VECTOR_BODY:%.*]]
206 ; CHECK-XOP: vector.body:
207 ; CHECK-XOP-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
208 ; CHECK-XOP-NEXT: [[T0:%.*]] = getelementptr inbounds i32, i32* [[ARR:%.*]], i64 [[INDEX]]
209 ; CHECK-XOP-NEXT: [[T1:%.*]] = bitcast i32* [[T0]] to <8 x i32>*
210 ; CHECK-XOP-NEXT: [[WIDE_LOAD:%.*]] = load <8 x i32>, <8 x i32>* [[T1]], align 4
211 ; CHECK-XOP-NEXT: [[T2:%.*]] = call <8 x i32> @llvm.fshl.v8i32(<8 x i32> [[WIDE_LOAD]], <8 x i32> [[WIDE_LOAD]], <8 x i32> [[BROADCAST_SPLAT16]])
212 ; CHECK-XOP-NEXT: store <8 x i32> [[T2]], <8 x i32>* [[T1]], align 4
213 ; CHECK-XOP-NEXT: [[INDEX_NEXT]] = add i64 [[INDEX]], 8
214 ; CHECK-XOP-NEXT: [[T3:%.*]] = icmp eq i64 [[INDEX_NEXT]], 65536
215 ; CHECK-XOP-NEXT: br i1 [[T3]], label [[FOR_COND_CLEANUP:%.*]], label [[VECTOR_BODY]]
216 ; CHECK-XOP: for.cond.cleanup:
217 ; CHECK-XOP-NEXT: ret void
219 ; CHECK-AVX-LABEL: @funnel_splatvar(
220 ; CHECK-AVX-NEXT: entry:
221 ; CHECK-AVX-NEXT: [[BROADCAST_SPLATINSERT15:%.*]] = insertelement <8 x i32> poison, i32 [[ROT:%.*]], i32 0
222 ; CHECK-AVX-NEXT: [[BROADCAST_SPLAT16:%.*]] = shufflevector <8 x i32> [[BROADCAST_SPLATINSERT15]], <8 x i32> poison, <8 x i32> zeroinitializer
223 ; CHECK-AVX-NEXT: br label [[VECTOR_BODY:%.*]]
224 ; CHECK-AVX: vector.body:
225 ; CHECK-AVX-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
226 ; CHECK-AVX-NEXT: [[T0:%.*]] = getelementptr inbounds i32, i32* [[ARR:%.*]], i64 [[INDEX]]
227 ; CHECK-AVX-NEXT: [[T1:%.*]] = bitcast i32* [[T0]] to <8 x i32>*
228 ; CHECK-AVX-NEXT: [[WIDE_LOAD:%.*]] = load <8 x i32>, <8 x i32>* [[T1]], align 4
229 ; CHECK-AVX-NEXT: [[T2:%.*]] = call <8 x i32> @llvm.fshl.v8i32(<8 x i32> [[WIDE_LOAD]], <8 x i32> [[WIDE_LOAD]], <8 x i32> [[BROADCAST_SPLAT16]])
230 ; CHECK-AVX-NEXT: store <8 x i32> [[T2]], <8 x i32>* [[T1]], align 4
231 ; CHECK-AVX-NEXT: [[INDEX_NEXT]] = add i64 [[INDEX]], 8
232 ; CHECK-AVX-NEXT: [[T3:%.*]] = icmp eq i64 [[INDEX_NEXT]], 65536
233 ; CHECK-AVX-NEXT: br i1 [[T3]], label [[FOR_COND_CLEANUP:%.*]], label [[VECTOR_BODY]]
234 ; CHECK-AVX: for.cond.cleanup:
235 ; CHECK-AVX-NEXT: ret void
238 %broadcast.splatinsert15 = insertelement <8 x i32> poison, i32 %rot, i32 0
239 %broadcast.splat16 = shufflevector <8 x i32> %broadcast.splatinsert15, <8 x i32> poison, <8 x i32> zeroinitializer
240 br label %vector.body
243 %index = phi i64 [ 0, %entry ], [ %index.next, %vector.body ]
244 %t0 = getelementptr inbounds i32, i32* %arr, i64 %index
245 %t1 = bitcast i32* %t0 to <8 x i32>*
246 %wide.load = load <8 x i32>, <8 x i32>* %t1, align 4
247 %t2 = call <8 x i32> @llvm.fshl.v8i32(<8 x i32> %wide.load, <8 x i32> %wide.load, <8 x i32> %broadcast.splat16)
248 store <8 x i32> %t2, <8 x i32>* %t1, align 4
249 %index.next = add i64 %index, 8
250 %t3 = icmp eq i64 %index.next, 65536
251 br i1 %t3, label %for.cond.cleanup, label %vector.body
257 declare <8 x i32> @llvm.fshl.v8i32(<8 x i32>, <8 x i32>, <8 x i32>)