blob: c3af6f9abe60b85c52524103162c3b2d6688742e [file] [log] [blame]
Thomas Lively64a39a12019-01-10 22:32:11 +00001; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+unimplemented-simd128 | FileCheck %s
Thomas Lively38c902b2018-11-09 01:38:44 +00002
3; Test that vector selects of various varieties lower correctly to bitselects.
4
5target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
6target triple = "wasm32-unknown-unknown"
7
8; ==============================================================================
9; 16 x i8
10; ==============================================================================
11; CHECK-LABEL: vselect_v16i8:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000012; CHECK-NEXT: .functype vselect_v16i8 (v128, v128, v128) -> (v128){{$}}
Thomas Lively38c902b2018-11-09 01:38:44 +000013; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 7{{$}}
14; CHECK-NEXT: i8x16.shl $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
15; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 7{{$}}
16; CHECK-NEXT: i8x16.shr_s $push[[L3:[0-9]+]]=, $pop[[L1]], $pop[[L2]]{{$}}
17; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
18; CHECK-NEXT: return $pop[[R]]{{$}}
19define <16 x i8> @vselect_v16i8(<16 x i1> %c, <16 x i8> %x, <16 x i8> %y) {
20 %res = select <16 x i1> %c, <16 x i8> %x, <16 x i8> %y
21 ret <16 x i8> %res
22}
23
24; CHECK-LABEL: select_v16i8:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000025; CHECK-NEXT: .functype select_v16i8 (i32, v128, v128) -> (v128){{$}}
Thomas Lively38c902b2018-11-09 01:38:44 +000026; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, -1{{$}}
27; CHECK-NEXT: i32.const $push[[L1:[0-9]+]]=, 0{{$}}
28; CHECK-NEXT: i32.select $push[[L2:[0-9]+]]=, $pop[[L0]], $pop[[L1]], $0{{$}}
29; CHECK-NEXT: i8x16.splat $push[[L3:[0-9]+]]=, $pop[[L2]]{{$}}
30; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
31; CHECK-NEXT: return $pop[[R]]{{$}}
Nikita Popove661f942019-02-23 18:59:01 +000032define <16 x i8> @select_v16i8(i1 zeroext %c, <16 x i8> %x, <16 x i8> %y) {
Thomas Lively38c902b2018-11-09 01:38:44 +000033 %res = select i1 %c, <16 x i8> %x, <16 x i8> %y
34 ret <16 x i8> %res
35}
36
37; CHECK-LABEL: select_cmp_v16i8:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000038; CHECK-NEXT: .functype select_cmp_v16i8 (i32, v128, v128) -> (v128){{$}}
Thomas Lively38c902b2018-11-09 01:38:44 +000039; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 31
40; CHECK-NEXT: i32.shr_s $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
41; CHECK-NEXT: i8x16.splat $push[[L2:[0-9]+]]=, $pop[[L1]]{{$}}
42; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L2]]{{$}}
43; CHECK-NEXT: return $pop[[R]]{{$}}
44define <16 x i8> @select_cmp_v16i8(i32 %i, <16 x i8> %x, <16 x i8> %y) {
45 %c = icmp slt i32 %i, 0
46 %res = select i1 %c, <16 x i8> %x, <16 x i8> %y
47 ret <16 x i8> %res
48}
49
50; CHECK-LABEL: select_ne_v16i8:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000051; CHECK-NEXT: .functype select_ne_v16i8 (i32, v128, v128) -> (v128){{$}}
Thomas Lively38c902b2018-11-09 01:38:44 +000052; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, -1{{$}}
53; CHECK-NEXT: i32.const $push[[L1:[0-9]+]]=, 0{{$}}
54; CHECK-NEXT: i32.select $push[[L2:[0-9]+]]=, $pop[[L0]], $pop[[L1]], $0{{$}}
55; CHECK-NEXT: i8x16.splat $push[[L3:[0-9]+]]=, $pop[[L2]]{{$}}
56; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
57; CHECK-NEXT: return $pop[[R]]{{$}}
58define <16 x i8> @select_ne_v16i8(i32 %i, <16 x i8> %x, <16 x i8> %y) {
59 %c = icmp ne i32 %i, 0
60 %res = select i1 %c, <16 x i8> %x, <16 x i8> %y
61 ret <16 x i8> %res
62}
63
64; CHECK-LABEL: select_eq_v16i8:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000065; CHECK-NEXT: .functype select_eq_v16i8 (i32, v128, v128) -> (v128){{$}}
Thomas Lively38c902b2018-11-09 01:38:44 +000066; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 0{{$}}
67; CHECK-NEXT: i32.const $push[[L1:[0-9]+]]=, -1{{$}}
68; CHECK-NEXT: i32.select $push[[L2:[0-9]+]]=, $pop[[L0]], $pop[[L1]], $0{{$}}
69; CHECK-NEXT: i8x16.splat $push[[L3:[0-9]+]]=, $pop[[L2]]{{$}}
70; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
71; CHECK-NEXT: return $pop[[R]]{{$}}
72define <16 x i8> @select_eq_v16i8(i32 %i, <16 x i8> %x, <16 x i8> %y) {
73 %c = icmp eq i32 %i, 0
74 %res = select i1 %c, <16 x i8> %x, <16 x i8> %y
75 ret <16 x i8> %res
76}
77
78; ==============================================================================
79; 8 x i16
80; ==============================================================================
81; CHECK-LABEL: vselect_v8i16:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000082; CHECK-NEXT: .functype vselect_v8i16 (v128, v128, v128) -> (v128){{$}}
Thomas Lively38c902b2018-11-09 01:38:44 +000083; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 15{{$}}
84; CHECK-NEXT: i16x8.shl $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
85; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 15{{$}}
86; CHECK-NEXT: i16x8.shr_s $push[[L3:[0-9]+]]=, $pop[[L1]], $pop[[L2]]{{$}}
87; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
88; CHECK-NEXT: return $pop[[R]]{{$}}
89define <8 x i16> @vselect_v8i16(<8 x i1> %c, <8 x i16> %x, <8 x i16> %y) {
90 %res = select <8 x i1> %c, <8 x i16> %x, <8 x i16> %y
91 ret <8 x i16> %res
92}
93
94; CHECK-LABEL: select_v8i16:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +000095; CHECK-NEXT: .functype select_v8i16 (i32, v128, v128) -> (v128){{$}}
Thomas Lively38c902b2018-11-09 01:38:44 +000096; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, -1{{$}}
97; CHECK-NEXT: i32.const $push[[L1:[0-9]+]]=, 0{{$}}
98; CHECK-NEXT: i32.select $push[[L2:[0-9]+]]=, $pop[[L0]], $pop[[L1]], $0{{$}}
99; CHECK-NEXT: i16x8.splat $push[[L3:[0-9]+]]=, $pop[[L2]]{{$}}
100; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
101; CHECK-NEXT: return $pop[[R]]{{$}}
Nikita Popove661f942019-02-23 18:59:01 +0000102define <8 x i16> @select_v8i16(i1 zeroext %c, <8 x i16> %x, <8 x i16> %y) {
Thomas Lively38c902b2018-11-09 01:38:44 +0000103 %res = select i1 %c, <8 x i16> %x, <8 x i16> %y
104 ret <8 x i16> %res
105}
106
107; CHECK-LABEL: select_cmp_v8i16:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000108; CHECK-NEXT: .functype select_cmp_v8i16 (i32, v128, v128) -> (v128){{$}}
Thomas Lively38c902b2018-11-09 01:38:44 +0000109; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 31{{$}}
110; CHECK-NEXT: i32.shr_s $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
111; CHECK-NEXT: i16x8.splat $push[[L2:[0-9]+]]=, $pop[[L1]]{{$}}
112; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L2]]{{$}}
113; CHECK-NEXT: return $pop[[R]]{{$}}
114define <8 x i16> @select_cmp_v8i16(i32 %i, <8 x i16> %x, <8 x i16> %y) {
115 %c = icmp slt i32 %i, 0
116 %res = select i1 %c, <8 x i16> %x, <8 x i16> %y
117 ret <8 x i16> %res
118}
119
120; CHECK-LABEL: select_ne_v8i16:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000121; CHECK-NEXT: .functype select_ne_v8i16 (i32, v128, v128) -> (v128){{$}}
Thomas Lively38c902b2018-11-09 01:38:44 +0000122; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, -1{{$}}
123; CHECK-NEXT: i32.const $push[[L1:[0-9]+]]=, 0{{$}}
124; CHECK-NEXT: i32.select $push[[L2:[0-9]+]]=, $pop[[L0]], $pop[[L1]], $0{{$}}
125; CHECK-NEXT: i16x8.splat $push[[L3:[0-9]+]]=, $pop[[L2]]{{$}}
126; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
127; CHECK-NEXT: return $pop[[R]]{{$}}
128define <8 x i16> @select_ne_v8i16(i32 %i, <8 x i16> %x, <8 x i16> %y) {
129 %c = icmp ne i32 %i, 0
130 %res = select i1 %c, <8 x i16> %x, <8 x i16> %y
131 ret <8 x i16> %res
132}
133
134; CHECK-LABEL: select_eq_v8i16:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000135; CHECK-NEXT: .functype select_eq_v8i16 (i32, v128, v128) -> (v128){{$}}
Thomas Lively38c902b2018-11-09 01:38:44 +0000136; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 0{{$}}
137; CHECK-NEXT: i32.const $push[[L1:[0-9]+]]=, -1{{$}}
138; CHECK-NEXT: i32.select $push[[L2:[0-9]+]]=, $pop[[L0]], $pop[[L1]], $0{{$}}
139; CHECK-NEXT: i16x8.splat $push[[L3:[0-9]+]]=, $pop[[L2]]{{$}}
140; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
141; CHECK-NEXT: return $pop[[R]]{{$}}
142define <8 x i16> @select_eq_v8i16(i32 %i, <8 x i16> %x, <8 x i16> %y) {
143 %c = icmp eq i32 %i, 0
144 %res = select i1 %c, <8 x i16> %x, <8 x i16> %y
145 ret <8 x i16> %res
146}
147
148; ==============================================================================
149; 4 x i32
150; ==============================================================================
151; CHECK-LABEL: vselect_v4i32:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000152; CHECK-NEXT: .functype vselect_v4i32 (v128, v128, v128) -> (v128){{$}}
Thomas Lively38c902b2018-11-09 01:38:44 +0000153; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 31{{$}}
154; CHECK-NEXT: i32x4.shl $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
155; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 31{{$}}
156; CHECK-NEXT: i32x4.shr_s $push[[L3:[0-9]+]]=, $pop[[L1]], $pop[[L2]]{{$}}
157; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
158; CHECK-NEXT: return $pop[[R]]{{$}}
159define <4 x i32> @vselect_v4i32(<4 x i1> %c, <4 x i32> %x, <4 x i32> %y) {
160 %res = select <4 x i1> %c, <4 x i32> %x, <4 x i32> %y
161 ret <4 x i32> %res
162}
163
164
165; CHECK-LABEL: select_v4i32:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000166; CHECK-NEXT: .functype select_v4i32 (i32, v128, v128) -> (v128){{$}}
Thomas Lively38c902b2018-11-09 01:38:44 +0000167; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, -1{{$}}
168; CHECK-NEXT: i32.const $push[[L1:[0-9]+]]=, 0{{$}}
169; CHECK-NEXT: i32.select $push[[L2:[0-9]+]]=, $pop[[L0]], $pop[[L1]], $0{{$}}
170; CHECK-NEXT: i32x4.splat $push[[L3:[0-9]+]]=, $pop[[L2]]{{$}}
171; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
172; CHECK-NEXT: return $pop[[R]]{{$}}
Nikita Popove661f942019-02-23 18:59:01 +0000173define <4 x i32> @select_v4i32(i1 zeroext %c, <4 x i32> %x, <4 x i32> %y) {
Thomas Lively38c902b2018-11-09 01:38:44 +0000174 %res = select i1 %c, <4 x i32> %x, <4 x i32> %y
175 ret <4 x i32> %res
176}
177
178; CHECK-LABEL: select_cmp_v4i32:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000179; CHECK-NEXT: .functype select_cmp_v4i32 (i32, v128, v128) -> (v128){{$}}
Thomas Lively38c902b2018-11-09 01:38:44 +0000180; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 31{{$}}
181; CHECK-NEXT: i32.shr_s $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
182; CHECK-NEXT: i32x4.splat $push[[L2:[0-9]+]]=, $pop[[L1]]{{$}}
183; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L2]]{{$}}
184; CHECK-NEXT: return $pop[[R]]{{$}}
185define <4 x i32> @select_cmp_v4i32(i32 %i, <4 x i32> %x, <4 x i32> %y) {
186 %c = icmp slt i32 %i, 0
187 %res = select i1 %c, <4 x i32> %x, <4 x i32> %y
188 ret <4 x i32> %res
189}
190
191; CHECK-LABEL: select_ne_v4i32:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000192; CHECK-NEXT: .functype select_ne_v4i32 (i32, v128, v128) -> (v128){{$}}
Thomas Lively38c902b2018-11-09 01:38:44 +0000193; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, -1{{$}}
194; CHECK-NEXT: i32.const $push[[L1:[0-9]+]]=, 0{{$}}
195; CHECK-NEXT: i32.select $push[[L2:[0-9]+]]=, $pop[[L0]], $pop[[L1]], $0{{$}}
196; CHECK-NEXT: i32x4.splat $push[[L3:[0-9]+]]=, $pop[[L2]]{{$}}
197; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
198; CHECK-NEXT: return $pop[[R]]{{$}}
199define <4 x i32> @select_ne_v4i32(i32 %i, <4 x i32> %x, <4 x i32> %y) {
200 %c = icmp ne i32 %i, 0
201 %res = select i1 %c, <4 x i32> %x, <4 x i32> %y
202 ret <4 x i32> %res
203}
204
205; CHECK-LABEL: select_eq_v4i32:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000206; CHECK-NEXT: .functype select_eq_v4i32 (i32, v128, v128) -> (v128){{$}}
Thomas Lively38c902b2018-11-09 01:38:44 +0000207; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 0{{$}}
208; CHECK-NEXT: i32.const $push[[L1:[0-9]+]]=, -1{{$}}
209; CHECK-NEXT: i32.select $push[[L2:[0-9]+]]=, $pop[[L0]], $pop[[L1]], $0{{$}}
210; CHECK-NEXT: i32x4.splat $push[[L3:[0-9]+]]=, $pop[[L2]]{{$}}
211; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
212; CHECK-NEXT: return $pop[[R]]{{$}}
213define <4 x i32> @select_eq_v4i32(i32 %i, <4 x i32> %x, <4 x i32> %y) {
214 %c = icmp eq i32 %i, 0
215 %res = select i1 %c, <4 x i32> %x, <4 x i32> %y
216 ret <4 x i32> %res
217}
218
219; ==============================================================================
220; 2 x i64
221; ==============================================================================
222; CHECK-LABEL: vselect_v2i64:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000223; CHECK-NEXT: .functype vselect_v2i64 (v128, v128, v128) -> (v128){{$}}
Thomas Lively38c902b2018-11-09 01:38:44 +0000224; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 63{{$}}
225; CHECK-NEXT: i64x2.shl $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
226; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 63{{$}}
227; CHECK-NEXT: i64x2.shr_s $push[[L3:[0-9]+]]=, $pop[[L1]], $pop[[L2]]{{$}}
228; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
229; CHECK-NEXT: return $pop[[R]]{{$}}
230define <2 x i64> @vselect_v2i64(<2 x i1> %c, <2 x i64> %x, <2 x i64> %y) {
231 %res = select <2 x i1> %c, <2 x i64> %x, <2 x i64> %y
232 ret <2 x i64> %res
233}
234
235; CHECK-LABEL: select_v2i64:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000236; CHECK-NEXT: .functype select_v2i64 (i32, v128, v128) -> (v128){{$}}
Thomas Lively38c902b2018-11-09 01:38:44 +0000237; CHECK-NEXT: i64.const $push[[L0:[0-9]+]]=, -1{{$}}
238; CHECK-NEXT: i64.const $push[[L1:[0-9]+]]=, 0{{$}}
239; CHECK-NEXT: i64.select $push[[L2:[0-9]+]]=, $pop[[L0]], $pop[[L1]], $0{{$}}
240; CHECK-NEXT: i64x2.splat $push[[L3:[0-9]+]]=, $pop[[L2]]{{$}}
241; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
242; CHECK-NEXT: return $pop[[R]]{{$}}
Nikita Popove661f942019-02-23 18:59:01 +0000243define <2 x i64> @select_v2i64(i1 zeroext %c, <2 x i64> %x, <2 x i64> %y) {
Thomas Lively38c902b2018-11-09 01:38:44 +0000244 %res = select i1 %c, <2 x i64> %x, <2 x i64> %y
245 ret <2 x i64> %res
246}
247
248; CHECK-LABEL: select_cmp_v2i64:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000249; CHECK-NEXT: .functype select_cmp_v2i64 (i32, v128, v128) -> (v128){{$}}
Thomas Lively38c902b2018-11-09 01:38:44 +0000250; CHECK-NEXT: i64.const $push[[L0:[0-9]+]]=, -1{{$}}
251; CHECK-NEXT: i64.const $push[[L1:[0-9]+]]=, 0{{$}}
252; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 0{{$}}
253; CHECK-NEXT: i32.lt_s $push[[L3:[0-9]+]]=, $0, $pop[[L2]]{{$}}
254; CHECK-NEXT: i64.select $push[[L4:[0-9]+]]=, $pop[[L0]], $pop[[L1]], $pop[[L3]]{{$}}
255; CHECK-NEXT: i64x2.splat $push[[L5:[0-9]+]]=, $pop[[L4]]{{$}}
256; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L5]]{{$}}
257; CHECK-NEXT: return $pop[[R]]{{$}}
258define <2 x i64> @select_cmp_v2i64(i32 %i, <2 x i64> %x, <2 x i64> %y) {
259 %c = icmp slt i32 %i, 0
260 %res = select i1 %c, <2 x i64> %x, <2 x i64> %y
261 ret <2 x i64> %res
262}
263
264; CHECK-LABEL: select_ne_v2i64:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000265; CHECK-NEXT: .functype select_ne_v2i64 (i32, v128, v128) -> (v128){{$}}
Thomas Lively38c902b2018-11-09 01:38:44 +0000266; CHECK-NEXT: i64.const $push[[L0:[0-9]+]]=, -1{{$}}
267; CHECK-NEXT: i64.const $push[[L1:[0-9]+]]=, 0{{$}}
268; CHECK-NEXT: i64.select $push[[L2:[0-9]+]]=, $pop[[L0]], $pop[[L1]], $0{{$}}
269; CHECK-NEXT: i64x2.splat $push[[L3:[0-9]+]]=, $pop[[L2]]{{$}}
270; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
271; CHECK-NEXT: return $pop[[R]]{{$}}
272define <2 x i64> @select_ne_v2i64(i32 %i, <2 x i64> %x, <2 x i64> %y) {
273 %c = icmp ne i32 %i, 0
274 %res = select i1 %c, <2 x i64> %x, <2 x i64> %y
275 ret <2 x i64> %res
276}
277
278; CHECK-LABEL: select_eq_v2i64:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000279; CHECK-NEXT: .functype select_eq_v2i64 (i32, v128, v128) -> (v128){{$}}
Thomas Lively38c902b2018-11-09 01:38:44 +0000280; CHECK-NEXT: i64.const $push[[L0:[0-9]+]]=, 0{{$}}
281; CHECK-NEXT: i64.const $push[[L1:[0-9]+]]=, -1{{$}}
282; CHECK-NEXT: i64.select $push[[L2:[0-9]+]]=, $pop[[L0]], $pop[[L1]], $0{{$}}
283; CHECK-NEXT: i64x2.splat $push[[L3:[0-9]+]]=, $pop[[L2]]{{$}}
284; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
285; CHECK-NEXT: return $pop[[R]]{{$}}
286define <2 x i64> @select_eq_v2i64(i32 %i, <2 x i64> %x, <2 x i64> %y) {
287 %c = icmp eq i32 %i, 0
288 %res = select i1 %c, <2 x i64> %x, <2 x i64> %y
289 ret <2 x i64> %res
290}
291
292; ==============================================================================
293; 4 x float
294; ==============================================================================
295; CHECK-LABEL: vselect_v4f32:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000296; CHECK-NEXT: .functype vselect_v4f32 (v128, v128, v128) -> (v128){{$}}
Thomas Lively38c902b2018-11-09 01:38:44 +0000297; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 31{{$}}
298; CHECK-NEXT: i32x4.shl $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
299; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 31{{$}}
300; CHECK-NEXT: i32x4.shr_s $push[[L3:[0-9]+]]=, $pop[[L1]], $pop[[L2]]{{$}}
301; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
302; CHECK-NEXT: return $pop[[R]]{{$}}
303define <4 x float> @vselect_v4f32(<4 x i1> %c, <4 x float> %x, <4 x float> %y) {
304 %res = select <4 x i1> %c, <4 x float> %x, <4 x float> %y
305 ret <4 x float> %res
306}
307
308; CHECK-LABEL: select_v4f32:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000309; CHECK-NEXT: .functype select_v4f32 (i32, v128, v128) -> (v128){{$}}
Thomas Lively38c902b2018-11-09 01:38:44 +0000310; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, -1{{$}}
311; CHECK-NEXT: i32.const $push[[L1:[0-9]+]]=, 0{{$}}
312; CHECK-NEXT: i32.select $push[[L2:[0-9]+]]=, $pop[[L0]], $pop[[L1]], $0{{$}}
313; CHECK-NEXT: i32x4.splat $push[[L3:[0-9]+]]=, $pop[[L2]]{{$}}
314; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
315; CHECK-NEXT: return $pop[[R]]{{$}}
Nikita Popove661f942019-02-23 18:59:01 +0000316define <4 x float> @select_v4f32(i1 zeroext %c, <4 x float> %x, <4 x float> %y) {
Thomas Lively38c902b2018-11-09 01:38:44 +0000317 %res = select i1 %c, <4 x float> %x, <4 x float> %y
318 ret <4 x float> %res
319}
320
321; CHECK-LABEL: select_cmp_v4f32:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000322; CHECK-NEXT: .functype select_cmp_v4f32 (i32, v128, v128) -> (v128){{$}}
Thomas Lively38c902b2018-11-09 01:38:44 +0000323; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 31{{$}}
324; CHECK-NEXT: i32.shr_s $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
325; CHECK-NEXT: i32x4.splat $push[[L2:[0-9]+]]=, $pop[[L1]]{{$}}
326; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L2]]{{$}}
327; CHECK-NEXT: return $pop[[R]]{{$}}
328define <4 x float> @select_cmp_v4f32(i32 %i, <4 x float> %x, <4 x float> %y) {
329 %c = icmp slt i32 %i, 0
330 %res = select i1 %c, <4 x float> %x, <4 x float> %y
331 ret <4 x float> %res
332}
333
334; CHECK-LABEL: select_ne_v4f32:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000335; CHECK-NEXT: .functype select_ne_v4f32 (i32, v128, v128) -> (v128){{$}}
Thomas Lively38c902b2018-11-09 01:38:44 +0000336; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, -1{{$}}
337; CHECK-NEXT: i32.const $push[[L1:[0-9]+]]=, 0{{$}}
338; CHECK-NEXT: i32.select $push[[L2:[0-9]+]]=, $pop[[L0]], $pop[[L1]], $0{{$}}
339; CHECK-NEXT: i32x4.splat $push[[L3:[0-9]+]]=, $pop[[L2]]{{$}}
340; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
341; CHECK-NEXT: return $pop[[R]]{{$}}
342define <4 x float> @select_ne_v4f32(i32 %i, <4 x float> %x, <4 x float> %y) {
343 %c = icmp ne i32 %i, 0
344 %res = select i1 %c, <4 x float> %x, <4 x float> %y
345 ret <4 x float> %res
346}
347
348; CHECK-LABEL: select_eq_v4f32:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000349; CHECK-NEXT: .functype select_eq_v4f32 (i32, v128, v128) -> (v128){{$}}
Thomas Lively38c902b2018-11-09 01:38:44 +0000350; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 0{{$}}
351; CHECK-NEXT: i32.const $push[[L1:[0-9]+]]=, -1{{$}}
352; CHECK-NEXT: i32.select $push[[L2:[0-9]+]]=, $pop[[L0]], $pop[[L1]], $0{{$}}
353; CHECK-NEXT: i32x4.splat $push[[L3:[0-9]+]]=, $pop[[L2]]{{$}}
354; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
355; CHECK-NEXT: return $pop[[R]]{{$}}
356define <4 x float> @select_eq_v4f32(i32 %i, <4 x float> %x, <4 x float> %y) {
357 %c = icmp eq i32 %i, 0
358 %res = select i1 %c, <4 x float> %x, <4 x float> %y
359 ret <4 x float> %res
360}
361
362; ==============================================================================
363; 2 x double
364; ==============================================================================
365; CHECK-LABEL: vselect_v2f64:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000366; CHECK-NEXT: .functype vselect_v2f64 (v128, v128, v128) -> (v128){{$}}
Thomas Lively38c902b2018-11-09 01:38:44 +0000367; CHECK-NEXT: i32.const $push[[L0:[0-9]+]]=, 63{{$}}
368; CHECK-NEXT: i64x2.shl $push[[L1:[0-9]+]]=, $0, $pop[[L0]]{{$}}
369; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 63{{$}}
370; CHECK-NEXT: i64x2.shr_s $push[[L3:[0-9]+]]=, $pop[[L1]], $pop[[L2]]{{$}}
371; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
372; CHECK-NEXT: return $pop[[R]]{{$}}
373define <2 x double> @vselect_v2f64(<2 x i1> %c, <2 x double> %x, <2 x double> %y) {
374 %res = select <2 x i1> %c, <2 x double> %x, <2 x double> %y
375 ret <2 x double> %res
376}
377
378; CHECK-LABEL: select_v2f64:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000379; CHECK-NEXT: .functype select_v2f64 (i32, v128, v128) -> (v128){{$}}
Thomas Lively38c902b2018-11-09 01:38:44 +0000380; CHECK-NEXT: i64.const $push[[L0:[0-9]+]]=, -1{{$}}
381; CHECK-NEXT: i64.const $push[[L1:[0-9]+]]=, 0{{$}}
382; CHECK-NEXT: i64.select $push[[L2:[0-9]+]]=, $pop[[L0]], $pop[[L1]], $0{{$}}
383; CHECK-NEXT: i64x2.splat $push[[L3:[0-9]+]]=, $pop[[L2]]{{$}}
384; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
385; CHECK-NEXT: return $pop[[R]]{{$}}
Nikita Popove661f942019-02-23 18:59:01 +0000386define <2 x double> @select_v2f64(i1 zeroext %c, <2 x double> %x, <2 x double> %y) {
Thomas Lively38c902b2018-11-09 01:38:44 +0000387 %res = select i1 %c, <2 x double> %x, <2 x double> %y
388 ret <2 x double> %res
389}
390
391; CHECK-LABEL: select_cmp_v2f64:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000392; CHECK-NEXT: .functype select_cmp_v2f64 (i32, v128, v128) -> (v128){{$}}
Thomas Lively38c902b2018-11-09 01:38:44 +0000393; CHECK-NEXT: i64.const $push[[L0:[0-9]+]]=, -1{{$}}
394; CHECK-NEXT: i64.const $push[[L1:[0-9]+]]=, 0{{$}}
395; CHECK-NEXT: i32.const $push[[L2:[0-9]+]]=, 0{{$}}
396; CHECK-NEXT: i32.lt_s $push[[L3:[0-9]+]]=, $0, $pop[[L2]]{{$}}
397; CHECK-NEXT: i64.select $push[[L4:[0-9]+]]=, $pop[[L0]], $pop[[L1]], $pop[[L3]]{{$}}
398; CHECK-NEXT: i64x2.splat $push[[L5:[0-9]+]]=, $pop[[L4]]{{$}}
399; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L5]]{{$}}
400; CHECK-NEXT: return $pop[[R]]{{$}}
401define <2 x double> @select_cmp_v2f64(i32 %i, <2 x double> %x, <2 x double> %y) {
402 %c = icmp slt i32 %i, 0
403 %res = select i1 %c, <2 x double> %x, <2 x double> %y
404 ret <2 x double> %res
405}
406
407; CHECK-LABEL: select_ne_v2f64:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000408; CHECK-NEXT: .functype select_ne_v2f64 (i32, v128, v128) -> (v128){{$}}
Thomas Lively38c902b2018-11-09 01:38:44 +0000409; CHECK-NEXT: i64.const $push[[L0:[0-9]+]]=, -1{{$}}
410; CHECK-NEXT: i64.const $push[[L1:[0-9]+]]=, 0{{$}}
411; CHECK-NEXT: i64.select $push[[L2:[0-9]+]]=, $pop[[L0]], $pop[[L1]], $0{{$}}
412; CHECK-NEXT: i64x2.splat $push[[L3:[0-9]+]]=, $pop[[L2]]{{$}}
413; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
414; CHECK-NEXT: return $pop[[R]]{{$}}
415define <2 x double> @select_ne_v2f64(i32 %i, <2 x double> %x, <2 x double> %y) {
416 %c = icmp ne i32 %i, 0
417 %res = select i1 %c, <2 x double> %x, <2 x double> %y
418 ret <2 x double> %res
419}
420
421; CHECK-LABEL: select_eq_v2f64:
Wouter van Oortmerssen49482f82018-11-19 17:10:36 +0000422; CHECK-NEXT: .functype select_eq_v2f64 (i32, v128, v128) -> (v128){{$}}
Thomas Lively38c902b2018-11-09 01:38:44 +0000423; CHECK-NEXT: i64.const $push[[L0:[0-9]+]]=, 0{{$}}
424; CHECK-NEXT: i64.const $push[[L1:[0-9]+]]=, -1{{$}}
425; CHECK-NEXT: i64.select $push[[L2:[0-9]+]]=, $pop[[L0]], $pop[[L1]], $0{{$}}
426; CHECK-NEXT: i64x2.splat $push[[L3:[0-9]+]]=, $pop[[L2]]{{$}}
427; CHECK-NEXT: v128.bitselect $push[[R:[0-9]+]]=, $1, $2, $pop[[L3]]{{$}}
428; CHECK-NEXT: return $pop[[R]]{{$}}
429define <2 x double> @select_eq_v2f64(i32 %i, <2 x double> %x, <2 x double> %y) {
430 %c = icmp eq i32 %i, 0
431 %res = select i1 %c, <2 x double> %x, <2 x double> %y
432 ret <2 x double> %res
433}