blob: 50d8b689aee095daa73d2a33cda05f90daa13ae4 [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
62; ==============================================================================
63; 8 x i16
64; ==============================================================================
Derek Schuff4ec8bca2018-08-15 00:30:27 +000065; CHECK-LABEL: splat_v8i16:
66; NO-SIMD128-NOT: i16x8
67; SIMD128: .param i32{{$}}
68; SIMD128: .result v128{{$}}
69; SIMD128: i16x8.splat $push0=, $0 # encoding: [0xfd,0x04]{{$}}
70; SIMD128: return $pop0 # encoding: [0x0f]{{$}}
71define <8 x i16> @splat_v8i16(i16 %x) {
72 %v = insertelement <8 x i16> undef, i16 %x, i32 0
73 %res = shufflevector <8 x i16> %v, <8 x i16> undef,
74 <8 x i32> <i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0>
75 ret <8 x i16> %res
76}
77
Heejin Ahnc15a8782018-08-14 19:10:50 +000078; CHECK-LABEL: extract_v8i16_s:
Heejin Ahna0fd9c32018-08-14 18:53:27 +000079; NO-SIMD128-NOT: i16x8
80; SIMD128: .param v128{{$}}
81; SIMD128: .result i32{{$}}
Heejin Ahnc15a8782018-08-14 19:10:50 +000082; SIMD128: i16x8.extract_lane_s $push0=, $0, 5 # encoding: [0xfd,0x0b,0x05]{{$}}
83; SIMD128: return $pop0 #
Heejin Ahna0fd9c32018-08-14 18:53:27 +000084define i32 @extract_v8i16_s(<8 x i16> %v) {
85 %elem = extractelement <8 x i16> %v, i16 5
86 %a = sext i16 %elem to i32
87 ret i32 %a
88}
89
Heejin Ahnc15a8782018-08-14 19:10:50 +000090; CHECK-LABEL: extract_v8i16_u:
Heejin Ahna0fd9c32018-08-14 18:53:27 +000091; NO-SIMD128-NOT: i16x8
92; SIMD128: .param v128{{$}}
93; SIMD128: .result i32{{$}}
Heejin Ahnc15a8782018-08-14 19:10:50 +000094; SIMD128: i16x8.extract_lane_u $push0=, $0, 5 # encoding: [0xfd,0x0c,0x05]{{$}}
95; SIMD128: return $pop0 #
Heejin Ahna0fd9c32018-08-14 18:53:27 +000096define i32 @extract_v8i16_u(<8 x i16> %v) {
97 %elem = extractelement <8 x i16> %v, i16 5
98 %a = zext i16 %elem to i32
99 ret i32 %a
100}
101
Heejin Ahnc15a8782018-08-14 19:10:50 +0000102; CHECK-LABEL: extract_v8i16:
Heejin Ahna0fd9c32018-08-14 18:53:27 +0000103; NO-SIMD128-NOT: i16x8
104; SIMD128: .param v128{{$}}
105; SIMD128: .result i32{{$}}
Heejin Ahnc15a8782018-08-14 19:10:50 +0000106; SIMD128: i16x8.extract_lane_u $push0=, $0, 5 # encoding: [0xfd,0x0c,0x05]{{$}}
107; SIMD128: return $pop0 #
Heejin Ahna0fd9c32018-08-14 18:53:27 +0000108define i16 @extract_v8i16(<8 x i16> %v) {
109 %elem = extractelement <8 x i16> %v, i16 5
110 ret i16 %elem
111}
112
113; ==============================================================================
114; 4 x i32
115; ==============================================================================
Derek Schuff4ec8bca2018-08-15 00:30:27 +0000116; CHECK-LABEL: splat_v4i32:
117; NO-SIMD128-NOT: i32x4
118; SIMD128: .param i32{{$}}
119; SIMD128: .result v128{{$}}
120; SIMD128: i32x4.splat $push0=, $0 # encoding: [0xfd,0x05]{{$}}
121; SIMD128: return $pop0 # encoding: [0x0f]{{$}}
122define <4 x i32> @splat_v4i32(i32 %x) {
123 %v = insertelement <4 x i32> undef, i32 %x, i32 0
124 %res = shufflevector <4 x i32> %v, <4 x i32> undef,
125 <4 x i32> <i32 0, i32 0, i32 0, i32 0>
126 ret <4 x i32> %res
127}
128
Heejin Ahnc15a8782018-08-14 19:10:50 +0000129; CHECK-LABEL: extract_v4i32:
Heejin Ahna0fd9c32018-08-14 18:53:27 +0000130; NO-SIMD128-NOT: i32x4
131; SIMD128: .param v128{{$}}
132; SIMD128: .result i32{{$}}
Heejin Ahnc15a8782018-08-14 19:10:50 +0000133; SIMD128: i32x4.extract_lane $push0=, $0, 3 # encoding: [0xfd,0x0d,0x03]{{$}}
134; SIMD128: return $pop0 #
Heejin Ahna0fd9c32018-08-14 18:53:27 +0000135define i32 @extract_v4i32(<4 x i32> %v) {
136 %elem = extractelement <4 x i32> %v, i32 3
137 ret i32 %elem
138}
139
140; ==============================================================================
141; 2 x i64
142; ==============================================================================
Derek Schuff4ec8bca2018-08-15 00:30:27 +0000143; CHECK-LABEL: splat_v2i64:
144; NO-SIMD128-NOT: i64x2
145; SIMD128-VM-NOT: i64x2
146; SIMD128: .param i64{{$}}
147; SIMD128: .result v128{{$}}
148; SIMD128: i64x2.splat $push0=, $0 # encoding: [0xfd,0x06]{{$}}
149; SIMD128: return $pop0 # encoding: [0x0f]{{$}}
150define <2 x i64> @splat_v2i64(i64 %x) {
151 %t1 = insertelement <2 x i64> zeroinitializer, i64 %x, i32 0
152 %res = insertelement <2 x i64> %t1, i64 %x, i32 1
153 ret <2 x i64> %res
154}
155
Heejin Ahnc15a8782018-08-14 19:10:50 +0000156; CHECK-LABEL: extract_v2i64:
Heejin Ahna0fd9c32018-08-14 18:53:27 +0000157; NO-SIMD128-NOT: i64x2
158; SIMD128-VM-NOT: i64x2
159; SIMD128: .param v128{{$}}
160; SIMD128: .result i64{{$}}
Heejin Ahnc15a8782018-08-14 19:10:50 +0000161; SIMD128: i64x2.extract_lane $push0=, $0, 1 # encoding: [0xfd,0x0e,0x01]{{$}}
162; SIMD128: return $pop0 #
Heejin Ahna0fd9c32018-08-14 18:53:27 +0000163define i64 @extract_v2i64(<2 x i64> %v) {
164 %elem = extractelement <2 x i64> %v, i64 1
165 ret i64 %elem
166}
167
168; ==============================================================================
169; 4 x f32
170; ==============================================================================
Derek Schuff4ec8bca2018-08-15 00:30:27 +0000171; CHECK-LABEL: splat_v4f32:
172; NO-SIMD128-NOT: f32x4
173; SIMD128: .param f32{{$}}
174; SIMD128: .result v128{{$}}
175; SIMD128: f32x4.splat $push0=, $0 # encoding: [0xfd,0x07]{{$}}
176; SIMD128: return $pop0 # encoding: [0x0f]{{$}}
177define <4 x float> @splat_v4f32(float %x) {
178 %v = insertelement <4 x float> undef, float %x, i32 0
179 %res = shufflevector <4 x float> %v, <4 x float> undef,
180 <4 x i32> <i32 0, i32 0, i32 0, i32 0>
181 ret <4 x float> %res
182}
183
Heejin Ahnc15a8782018-08-14 19:10:50 +0000184; CHECK-LABEL: extract_v4f32:
Heejin Ahna0fd9c32018-08-14 18:53:27 +0000185; NO-SIMD128-NOT: f32x4
186; SIMD128: .param v128{{$}}
187; SIMD128: .result f32{{$}}
Heejin Ahnc15a8782018-08-14 19:10:50 +0000188; SIMD128: f32x4.extract_lane $push0=, $0, 3 # encoding: [0xfd,0x0f,0x03]{{$}}
189; SIMD128: return $pop0 #
Heejin Ahna0fd9c32018-08-14 18:53:27 +0000190define float @extract_v4f32(<4 x float> %v) {
191 %elem = extractelement <4 x float> %v, i32 3
192 ret float %elem
193}
194
195; ==============================================================================
196; 2 x f64
197; ==============================================================================
Derek Schuff4ec8bca2018-08-15 00:30:27 +0000198; CHECK-LABEL: splat_v2f64:
199; NO-SIMD128-NOT: f64x2
200; SIMD128-VM-NOT: f64x2
201; SIMD128: .param f64{{$}}
202; SIMD128: .result v128{{$}}
203; SIMD128: f64x2.splat $push0=, $0 # encoding: [0xfd,0x08]{{$}}
204; SIMD128: return $pop0 # encoding: [0x0f]{{$}}
205define <2 x double> @splat_v2f64(double %x) {
206 %t1 = insertelement <2 x double> zeroinitializer, double %x, i3 0
207 %res = insertelement <2 x double> %t1, double %x, i32 1
208 ret <2 x double> %res
209}
210
Heejin Ahnc15a8782018-08-14 19:10:50 +0000211; CHECK-LABEL: extract_v2f64:
Heejin Ahna0fd9c32018-08-14 18:53:27 +0000212; NO-SIMD128-NOT: f64x2
213; SIMD128-VM-NOT: f64x2
214; SIMD128: .param v128{{$}}
215; SIMD128: .result f64{{$}}
Heejin Ahnc15a8782018-08-14 19:10:50 +0000216; SIMD128: f64x2.extract_lane $push0=, $0, 1 # encoding: [0xfd,0x10,0x01]{{$}}
217; SIMD128: return $pop0 #
Heejin Ahna0fd9c32018-08-14 18:53:27 +0000218define double @extract_v2f64(<2 x double> %v) {
219 %elem = extractelement <2 x double> %v, i32 1
220 ret double %elem
221}