blob: 414c5b313568fc9d827db1448040960b5ad3bc0f [file] [log] [blame]
Heejin Ahnc15a8782018-08-14 19:10:50 +00001; RUN: llc < %s -disable-wasm-fallthrough-return-opt -disable-wasm-explicit-locals -wasm-enable-unimplemented-simd -mattr=+simd128,+sign-ext --show-mc-encoding | FileCheck %s --check-prefixes CHECK,SIMD128
2; RUN: llc < %s -disable-wasm-fallthrough-return-opt -disable-wasm-explicit-locals -mattr=+simd128,+sign-ext --show-mc-encoding | FileCheck %s --check-prefixes CHECK,SIMD128-VM
3; RUN: llc < %s -disable-wasm-fallthrough-return-opt -disable-wasm-explicit-locals -mattr=-simd128,+sign-ext --show-mc-encoding | FileCheck %s --check-prefixes CHECK,NO-SIMD128
Heejin Ahna0fd9c32018-08-14 18:53:27 +00004
5; Test that basic SIMD128 vector manipulation operations assemble as expected.
6
7target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
8target triple = "wasm32-unknown-unknown"
9
10; ==============================================================================
11; 16 x i8
12; ==============================================================================
Derek Schuff4ec8bca2018-08-15 00:30:27 +000013; CHECK-LABEL: splat_v16i8:
14; NO-SIMD128-NOT: i8x16
15; SIMD128: .param i32{{$}}
16; SIMD128: .result v128{{$}}
17; SIMD128: i8x16.splat $push0=, $0 # encoding: [0xfd,0x03]{{$}}
18; SIMD128: return $pop0 # encoding: [0x0f]{{$}}
19define <16 x i8> @splat_v16i8(i8 %x) {
20 %v = insertelement <16 x i8> undef, i8 %x, i32 0
21 %res = shufflevector <16 x i8> %v, <16 x i8> undef,
22 <16 x i32> <i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0,
23 i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0>
24 ret <16 x i8> %res
25}
26
Heejin Ahnc15a8782018-08-14 19:10:50 +000027; CHECK-LABEL: extract_v16i8_s:
Heejin Ahna0fd9c32018-08-14 18:53:27 +000028; NO-SIMD128-NOT: i8x16
29; SIMD128: .param v128{{$}}
30; SIMD128: .result i32{{$}}
Heejin Ahnc15a8782018-08-14 19:10:50 +000031; SIMD128: i8x16.extract_lane_s $push0=, $0, 13 # encoding: [0xfd,0x09,0x0d]{{$}}
32; SIMD128: return $pop0 #
Heejin Ahna0fd9c32018-08-14 18:53:27 +000033define i32 @extract_v16i8_s(<16 x i8> %v) {
34 %elem = extractelement <16 x i8> %v, i8 13
35 %a = sext i8 %elem to i32
36 ret i32 %a
37}
38
Heejin Ahnc15a8782018-08-14 19:10:50 +000039; CHECK-LABEL: extract_v16i8_u:
Heejin Ahna0fd9c32018-08-14 18:53:27 +000040; NO-SIMD128-NOT: i8x16
41; SIMD128: .param v128{{$}}
42; SIMD128: .result i32{{$}}
Heejin Ahnc15a8782018-08-14 19:10:50 +000043; SIMD128: i8x16.extract_lane_u $push0=, $0, 13 # encoding: [0xfd,0x0a,0x0d]{{$}}
44; SIMD128: return $pop0 #
Heejin Ahna0fd9c32018-08-14 18:53:27 +000045define i32 @extract_v16i8_u(<16 x i8> %v) {
46 %elem = extractelement <16 x i8> %v, i8 13
47 %a = zext i8 %elem to i32
48 ret i32 %a
49}
50
Heejin Ahnc15a8782018-08-14 19:10:50 +000051; CHECK-LABEL: extract_v16i8:
Heejin Ahna0fd9c32018-08-14 18:53:27 +000052; NO-SIMD128-NOT: i8x16
53; SIMD128: .param v128{{$}}
54; SIMD128: .result i32{{$}}
Heejin Ahnc15a8782018-08-14 19:10:50 +000055; SIMD128: i8x16.extract_lane_u $push0=, $0, 13 # encoding: [0xfd,0x0a,0x0d]{{$}}
56; SIMD128: return $pop0 #
Heejin Ahna0fd9c32018-08-14 18:53:27 +000057define i8 @extract_v16i8(<16 x i8> %v) {
58 %elem = extractelement <16 x i8> %v, i8 13
59 ret i8 %elem
60}
61
Derek Schuff82812fb2018-08-15 16:18:51 +000062; CHECK-LABEL: replace_v16i8:
63; NO-SIMD128-NOT: i8x16
64; SIMD128: .param v128, i32{{$}}
65; SIMD128: .result v128{{$}}
66; SIMD128: i8x16.replace_lane $push0=, $0, 11, $1 # encoding: [0xfd,0x11,0x0b]{{$}}
67; SIMD128: return $pop0 # encoding: [0x0f]{{$}}
68define <16 x i8> @replace_v16i8(<16 x i8> %v, i8 %x) {
69 %res = insertelement <16 x i8> %v, i8 %x, i32 11
70 ret <16 x i8> %res
71}
72
Heejin Ahna0fd9c32018-08-14 18:53:27 +000073; ==============================================================================
74; 8 x i16
75; ==============================================================================
Derek Schuff4ec8bca2018-08-15 00:30:27 +000076; CHECK-LABEL: splat_v8i16:
77; NO-SIMD128-NOT: i16x8
78; SIMD128: .param i32{{$}}
79; SIMD128: .result v128{{$}}
80; SIMD128: i16x8.splat $push0=, $0 # encoding: [0xfd,0x04]{{$}}
81; SIMD128: return $pop0 # encoding: [0x0f]{{$}}
82define <8 x i16> @splat_v8i16(i16 %x) {
83 %v = insertelement <8 x i16> undef, i16 %x, i32 0
84 %res = shufflevector <8 x i16> %v, <8 x i16> undef,
85 <8 x i32> <i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0>
86 ret <8 x i16> %res
87}
88
Heejin Ahnc15a8782018-08-14 19:10:50 +000089; CHECK-LABEL: extract_v8i16_s:
Heejin Ahna0fd9c32018-08-14 18:53:27 +000090; NO-SIMD128-NOT: i16x8
91; SIMD128: .param v128{{$}}
92; SIMD128: .result i32{{$}}
Heejin Ahnc15a8782018-08-14 19:10:50 +000093; SIMD128: i16x8.extract_lane_s $push0=, $0, 5 # encoding: [0xfd,0x0b,0x05]{{$}}
94; SIMD128: return $pop0 #
Heejin Ahna0fd9c32018-08-14 18:53:27 +000095define i32 @extract_v8i16_s(<8 x i16> %v) {
96 %elem = extractelement <8 x i16> %v, i16 5
97 %a = sext i16 %elem to i32
98 ret i32 %a
99}
100
Heejin Ahnc15a8782018-08-14 19:10:50 +0000101; CHECK-LABEL: extract_v8i16_u:
Heejin Ahna0fd9c32018-08-14 18:53:27 +0000102; NO-SIMD128-NOT: i16x8
103; SIMD128: .param v128{{$}}
104; SIMD128: .result i32{{$}}
Heejin Ahnc15a8782018-08-14 19:10:50 +0000105; SIMD128: i16x8.extract_lane_u $push0=, $0, 5 # encoding: [0xfd,0x0c,0x05]{{$}}
106; SIMD128: return $pop0 #
Heejin Ahna0fd9c32018-08-14 18:53:27 +0000107define i32 @extract_v8i16_u(<8 x i16> %v) {
108 %elem = extractelement <8 x i16> %v, i16 5
109 %a = zext i16 %elem to i32
110 ret i32 %a
111}
112
Heejin Ahnc15a8782018-08-14 19:10:50 +0000113; CHECK-LABEL: extract_v8i16:
Heejin Ahna0fd9c32018-08-14 18:53:27 +0000114; NO-SIMD128-NOT: i16x8
115; SIMD128: .param v128{{$}}
116; SIMD128: .result i32{{$}}
Heejin Ahnc15a8782018-08-14 19:10:50 +0000117; SIMD128: i16x8.extract_lane_u $push0=, $0, 5 # encoding: [0xfd,0x0c,0x05]{{$}}
118; SIMD128: return $pop0 #
Heejin Ahna0fd9c32018-08-14 18:53:27 +0000119define i16 @extract_v8i16(<8 x i16> %v) {
120 %elem = extractelement <8 x i16> %v, i16 5
121 ret i16 %elem
122}
123
Derek Schuff82812fb2018-08-15 16:18:51 +0000124; CHECK-LABEL: replace_v8i16:
125; NO-SIMD128-NOT: i16x8
126; SIMD128: .param v128, i32{{$}}
127; SIMD128: .result v128{{$}}
128; SIMD128: i16x8.replace_lane $push0=, $0, 7, $1 # encoding: [0xfd,0x12,0x07]{{$}}
129; SIMD128: return $pop0 # encoding: [0x0f]{{$}}
130define <8 x i16> @replace_v8i16(<8 x i16> %v, i16 %x) {
131 %res = insertelement <8 x i16> %v, i16 %x, i32 7
132 ret <8 x i16> %res
133}
134
Heejin Ahna0fd9c32018-08-14 18:53:27 +0000135; ==============================================================================
136; 4 x i32
137; ==============================================================================
Derek Schuff4ec8bca2018-08-15 00:30:27 +0000138; CHECK-LABEL: splat_v4i32:
139; NO-SIMD128-NOT: i32x4
140; SIMD128: .param i32{{$}}
141; SIMD128: .result v128{{$}}
142; SIMD128: i32x4.splat $push0=, $0 # encoding: [0xfd,0x05]{{$}}
143; SIMD128: return $pop0 # encoding: [0x0f]{{$}}
144define <4 x i32> @splat_v4i32(i32 %x) {
145 %v = insertelement <4 x i32> undef, i32 %x, i32 0
146 %res = shufflevector <4 x i32> %v, <4 x i32> undef,
147 <4 x i32> <i32 0, i32 0, i32 0, i32 0>
148 ret <4 x i32> %res
149}
150
Heejin Ahnc15a8782018-08-14 19:10:50 +0000151; CHECK-LABEL: extract_v4i32:
Heejin Ahna0fd9c32018-08-14 18:53:27 +0000152; NO-SIMD128-NOT: i32x4
153; SIMD128: .param v128{{$}}
154; SIMD128: .result i32{{$}}
Heejin Ahnc15a8782018-08-14 19:10:50 +0000155; SIMD128: i32x4.extract_lane $push0=, $0, 3 # encoding: [0xfd,0x0d,0x03]{{$}}
156; SIMD128: return $pop0 #
Heejin Ahna0fd9c32018-08-14 18:53:27 +0000157define i32 @extract_v4i32(<4 x i32> %v) {
158 %elem = extractelement <4 x i32> %v, i32 3
159 ret i32 %elem
160}
161
Derek Schuff82812fb2018-08-15 16:18:51 +0000162; CHECK-LABEL: replace_v4i32:
163; NO-SIMD128-NOT: i32x4
164; SIMD128: .param v128, i32{{$}}
165; SIMD128: .result v128{{$}}
166; SIMD128: i32x4.replace_lane $push0=, $0, 2, $1 # encoding: [0xfd,0x13,0x02]{{$}}
167; SIMD128: return $pop0 # encoding: [0x0f]{{$}}
168define <4 x i32> @replace_v4i32(<4 x i32> %v, i32 %x) {
169 %res = insertelement <4 x i32> %v, i32 %x, i32 2
170 ret <4 x i32> %res
171}
172
Heejin Ahna0fd9c32018-08-14 18:53:27 +0000173; ==============================================================================
174; 2 x i64
175; ==============================================================================
Derek Schuff4ec8bca2018-08-15 00:30:27 +0000176; CHECK-LABEL: splat_v2i64:
177; NO-SIMD128-NOT: i64x2
178; SIMD128-VM-NOT: i64x2
179; SIMD128: .param i64{{$}}
180; SIMD128: .result v128{{$}}
181; SIMD128: i64x2.splat $push0=, $0 # encoding: [0xfd,0x06]{{$}}
182; SIMD128: return $pop0 # encoding: [0x0f]{{$}}
183define <2 x i64> @splat_v2i64(i64 %x) {
184 %t1 = insertelement <2 x i64> zeroinitializer, i64 %x, i32 0
185 %res = insertelement <2 x i64> %t1, i64 %x, i32 1
186 ret <2 x i64> %res
187}
188
Heejin Ahnc15a8782018-08-14 19:10:50 +0000189; CHECK-LABEL: extract_v2i64:
Heejin Ahna0fd9c32018-08-14 18:53:27 +0000190; NO-SIMD128-NOT: i64x2
191; SIMD128-VM-NOT: i64x2
192; SIMD128: .param v128{{$}}
193; SIMD128: .result i64{{$}}
Heejin Ahnc15a8782018-08-14 19:10:50 +0000194; SIMD128: i64x2.extract_lane $push0=, $0, 1 # encoding: [0xfd,0x0e,0x01]{{$}}
195; SIMD128: return $pop0 #
Heejin Ahna0fd9c32018-08-14 18:53:27 +0000196define i64 @extract_v2i64(<2 x i64> %v) {
197 %elem = extractelement <2 x i64> %v, i64 1
198 ret i64 %elem
199}
200
Derek Schuff82812fb2018-08-15 16:18:51 +0000201; CHECK-LABEL: replace_v2i64:
202; NO-SIMD128-NOT: i64x2
203; SIMD128-VM-NOT: i64x2
204; SIMD128: .param v128, i64{{$}}
205; SIMD128: .result v128{{$}}
206; SIMD128: i64x2.replace_lane $push0=, $0, 0, $1 # encoding: [0xfd,0x14,0x00]{{$}}
207; SIMD128: return $pop0 # encoding: [0x0f]{{$}}
208define <2 x i64> @replace_v2i64(<2 x i64> %v, i64 %x) {
209 %res = insertelement <2 x i64> %v, i64 %x, i32 0
210 ret <2 x i64> %res
211}
212
Heejin Ahna0fd9c32018-08-14 18:53:27 +0000213; ==============================================================================
214; 4 x f32
215; ==============================================================================
Derek Schuff4ec8bca2018-08-15 00:30:27 +0000216; CHECK-LABEL: splat_v4f32:
217; NO-SIMD128-NOT: f32x4
218; SIMD128: .param f32{{$}}
219; SIMD128: .result v128{{$}}
220; SIMD128: f32x4.splat $push0=, $0 # encoding: [0xfd,0x07]{{$}}
221; SIMD128: return $pop0 # encoding: [0x0f]{{$}}
222define <4 x float> @splat_v4f32(float %x) {
223 %v = insertelement <4 x float> undef, float %x, i32 0
224 %res = shufflevector <4 x float> %v, <4 x float> undef,
225 <4 x i32> <i32 0, i32 0, i32 0, i32 0>
226 ret <4 x float> %res
227}
228
Heejin Ahnc15a8782018-08-14 19:10:50 +0000229; CHECK-LABEL: extract_v4f32:
Heejin Ahna0fd9c32018-08-14 18:53:27 +0000230; NO-SIMD128-NOT: f32x4
231; SIMD128: .param v128{{$}}
232; SIMD128: .result f32{{$}}
Heejin Ahnc15a8782018-08-14 19:10:50 +0000233; SIMD128: f32x4.extract_lane $push0=, $0, 3 # encoding: [0xfd,0x0f,0x03]{{$}}
234; SIMD128: return $pop0 #
Heejin Ahna0fd9c32018-08-14 18:53:27 +0000235define float @extract_v4f32(<4 x float> %v) {
236 %elem = extractelement <4 x float> %v, i32 3
237 ret float %elem
238}
239
Derek Schuff82812fb2018-08-15 16:18:51 +0000240; CHECK-LABEL: replace_v4f32:
241; NO-SIMD128-NOT: f32x4
242; SIMD128: .param v128, f32{{$}}
243; SIMD128: .result v128{{$}}
244; SIMD128: f32x4.replace_lane $push0=, $0, 2, $1 # encoding: [0xfd,0x15,0x02]{{$}}
245; SIMD128: return $pop0 # encoding: [0x0f]{{$}}
246define <4 x float> @replace_v4f32(<4 x float> %v, float %x) {
247 %res = insertelement <4 x float> %v, float %x, i32 2
248 ret <4 x float> %res
249}
250
Heejin Ahna0fd9c32018-08-14 18:53:27 +0000251; ==============================================================================
252; 2 x f64
253; ==============================================================================
Derek Schuff4ec8bca2018-08-15 00:30:27 +0000254; CHECK-LABEL: splat_v2f64:
255; NO-SIMD128-NOT: f64x2
256; SIMD128-VM-NOT: f64x2
257; SIMD128: .param f64{{$}}
258; SIMD128: .result v128{{$}}
259; SIMD128: f64x2.splat $push0=, $0 # encoding: [0xfd,0x08]{{$}}
260; SIMD128: return $pop0 # encoding: [0x0f]{{$}}
261define <2 x double> @splat_v2f64(double %x) {
262 %t1 = insertelement <2 x double> zeroinitializer, double %x, i3 0
263 %res = insertelement <2 x double> %t1, double %x, i32 1
264 ret <2 x double> %res
265}
266
Heejin Ahnc15a8782018-08-14 19:10:50 +0000267; CHECK-LABEL: extract_v2f64:
Heejin Ahna0fd9c32018-08-14 18:53:27 +0000268; NO-SIMD128-NOT: f64x2
269; SIMD128-VM-NOT: f64x2
270; SIMD128: .param v128{{$}}
271; SIMD128: .result f64{{$}}
Heejin Ahnc15a8782018-08-14 19:10:50 +0000272; SIMD128: f64x2.extract_lane $push0=, $0, 1 # encoding: [0xfd,0x10,0x01]{{$}}
273; SIMD128: return $pop0 #
Heejin Ahna0fd9c32018-08-14 18:53:27 +0000274define double @extract_v2f64(<2 x double> %v) {
275 %elem = extractelement <2 x double> %v, i32 1
276 ret double %elem
277}
Derek Schuff82812fb2018-08-15 16:18:51 +0000278
279; CHECK-LABEL: replace_v2f64:
280; NO-SIMD128-NOT: f64x2
281; SIMD128-VM-NOT: f64x2
282; SIMD128: .param v128, f64{{$}}
283; SIMD128: .result v128{{$}}
284; SIMD128: f64x2.replace_lane $push0=, $0, 0, $1 # encoding: [0xfd,0x16,0x00]{{$}}
285; SIMD128: return $pop0 # encoding: [0x0f]{{$}}
286define <2 x double> @replace_v2f64(<2 x double> %v, double %x) {
287 %res = insertelement <2 x double> %v, double %x, i32 0
288 ret <2 x double> %res
289}