1 ; 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
5 ; Test that basic SIMD128 vector manipulation operations assemble as expected.
7 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
8 target triple = "wasm32-unknown-unknown"
10 ; ==============================================================================
12 ; ==============================================================================
13 ; 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]{{$}}
19 define <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>
27 ; CHECK-LABEL: extract_v16i8_s:
28 ; NO-SIMD128-NOT: i8x16
29 ; SIMD128: .param v128{{$}}
30 ; SIMD128: .result i32{{$}}
31 ; SIMD128: i8x16.extract_lane_s $push0=, $0, 13 # encoding: [0xfd,0x09,0x0d]{{$}}
32 ; SIMD128: return $pop0 #
33 define i32 @extract_v16i8_s(<16 x i8> %v) {
34 %elem = extractelement <16 x i8> %v, i8 13
35 %a = sext i8 %elem to i32
39 ; CHECK-LABEL: extract_v16i8_u:
40 ; NO-SIMD128-NOT: i8x16
41 ; SIMD128: .param v128{{$}}
42 ; SIMD128: .result i32{{$}}
43 ; SIMD128: i8x16.extract_lane_u $push0=, $0, 13 # encoding: [0xfd,0x0a,0x0d]{{$}}
44 ; SIMD128: return $pop0 #
45 define i32 @extract_v16i8_u(<16 x i8> %v) {
46 %elem = extractelement <16 x i8> %v, i8 13
47 %a = zext i8 %elem to i32
51 ; CHECK-LABEL: extract_v16i8:
52 ; NO-SIMD128-NOT: i8x16
53 ; SIMD128: .param v128{{$}}
54 ; SIMD128: .result i32{{$}}
55 ; SIMD128: i8x16.extract_lane_u $push0=, $0, 13 # encoding: [0xfd,0x0a,0x0d]{{$}}
56 ; SIMD128: return $pop0 #
57 define i8 @extract_v16i8(<16 x i8> %v) {
58 %elem = extractelement <16 x i8> %v, i8 13
62 ; 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]{{$}}
68 define <16 x i8> @replace_v16i8(<16 x i8> %v, i8 %x) {
69 %res = insertelement <16 x i8> %v, i8 %x, i32 11
73 ; ==============================================================================
75 ; ==============================================================================
76 ; 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]{{$}}
82 define <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>
89 ; CHECK-LABEL: extract_v8i16_s:
90 ; NO-SIMD128-NOT: i16x8
91 ; SIMD128: .param v128{{$}}
92 ; SIMD128: .result i32{{$}}
93 ; SIMD128: i16x8.extract_lane_s $push0=, $0, 5 # encoding: [0xfd,0x0b,0x05]{{$}}
94 ; SIMD128: return $pop0 #
95 define i32 @extract_v8i16_s(<8 x i16> %v) {
96 %elem = extractelement <8 x i16> %v, i16 5
97 %a = sext i16 %elem to i32
101 ; CHECK-LABEL: extract_v8i16_u:
102 ; NO-SIMD128-NOT: i16x8
103 ; SIMD128: .param v128{{$}}
104 ; SIMD128: .result i32{{$}}
105 ; SIMD128: i16x8.extract_lane_u $push0=, $0, 5 # encoding: [0xfd,0x0c,0x05]{{$}}
106 ; SIMD128: return $pop0 #
107 define i32 @extract_v8i16_u(<8 x i16> %v) {
108 %elem = extractelement <8 x i16> %v, i16 5
109 %a = zext i16 %elem to i32
113 ; CHECK-LABEL: extract_v8i16:
114 ; NO-SIMD128-NOT: i16x8
115 ; SIMD128: .param v128{{$}}
116 ; SIMD128: .result i32{{$}}
117 ; SIMD128: i16x8.extract_lane_u $push0=, $0, 5 # encoding: [0xfd,0x0c,0x05]{{$}}
118 ; SIMD128: return $pop0 #
119 define i16 @extract_v8i16(<8 x i16> %v) {
120 %elem = extractelement <8 x i16> %v, i16 5
124 ; 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]{{$}}
130 define <8 x i16> @replace_v8i16(<8 x i16> %v, i16 %x) {
131 %res = insertelement <8 x i16> %v, i16 %x, i32 7
135 ; ==============================================================================
137 ; ==============================================================================
138 ; 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]{{$}}
144 define <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>
151 ; CHECK-LABEL: extract_v4i32:
152 ; NO-SIMD128-NOT: i32x4
153 ; SIMD128: .param v128{{$}}
154 ; SIMD128: .result i32{{$}}
155 ; SIMD128: i32x4.extract_lane $push0=, $0, 3 # encoding: [0xfd,0x0d,0x03]{{$}}
156 ; SIMD128: return $pop0 #
157 define i32 @extract_v4i32(<4 x i32> %v) {
158 %elem = extractelement <4 x i32> %v, i32 3
162 ; 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]{{$}}
168 define <4 x i32> @replace_v4i32(<4 x i32> %v, i32 %x) {
169 %res = insertelement <4 x i32> %v, i32 %x, i32 2
173 ; ==============================================================================
175 ; ==============================================================================
176 ; 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]{{$}}
183 define <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
189 ; CHECK-LABEL: extract_v2i64:
190 ; NO-SIMD128-NOT: i64x2
191 ; SIMD128-VM-NOT: i64x2
192 ; SIMD128: .param v128{{$}}
193 ; SIMD128: .result i64{{$}}
194 ; SIMD128: i64x2.extract_lane $push0=, $0, 1 # encoding: [0xfd,0x0e,0x01]{{$}}
195 ; SIMD128: return $pop0 #
196 define i64 @extract_v2i64(<2 x i64> %v) {
197 %elem = extractelement <2 x i64> %v, i64 1
201 ; 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]{{$}}
208 define <2 x i64> @replace_v2i64(<2 x i64> %v, i64 %x) {
209 %res = insertelement <2 x i64> %v, i64 %x, i32 0
213 ; ==============================================================================
215 ; ==============================================================================
216 ; 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]{{$}}
222 define <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>
229 ; CHECK-LABEL: extract_v4f32:
230 ; NO-SIMD128-NOT: f32x4
231 ; SIMD128: .param v128{{$}}
232 ; SIMD128: .result f32{{$}}
233 ; SIMD128: f32x4.extract_lane $push0=, $0, 3 # encoding: [0xfd,0x0f,0x03]{{$}}
234 ; SIMD128: return $pop0 #
235 define float @extract_v4f32(<4 x float> %v) {
236 %elem = extractelement <4 x float> %v, i32 3
240 ; 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]{{$}}
246 define <4 x float> @replace_v4f32(<4 x float> %v, float %x) {
247 %res = insertelement <4 x float> %v, float %x, i32 2
251 ; ==============================================================================
253 ; ==============================================================================
254 ; 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]{{$}}
261 define <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
267 ; CHECK-LABEL: extract_v2f64:
268 ; NO-SIMD128-NOT: f64x2
269 ; SIMD128-VM-NOT: f64x2
270 ; SIMD128: .param v128{{$}}
271 ; SIMD128: .result f64{{$}}
272 ; SIMD128: f64x2.extract_lane $push0=, $0, 1 # encoding: [0xfd,0x10,0x01]{{$}}
273 ; SIMD128: return $pop0 #
274 define double @extract_v2f64(<2 x double> %v) {
275 %elem = extractelement <2 x double> %v, i32 1
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]{{$}}
286 define <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