1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -verify-machineinstrs -mattr=+simd128 | FileCheck %s
4 ; Test that a vector trunc correctly optimizes and lowers to narrow instructions
6 target triple = "wasm32-unknown-unknown"
8 define <16 x i8> @trunc16i64_16i8(<16 x i64> %a) {
9 ; CHECK-LABEL: trunc16i64_16i8:
10 ; CHECK: .functype trunc16i64_16i8 (v128, v128, v128, v128, v128, v128, v128, v128) -> (v128)
11 ; CHECK-NEXT: .local v128
12 ; CHECK-NEXT: # %bb.0: # %entry
13 ; CHECK-NEXT: local.get 0
14 ; CHECK-NEXT: v128.const 255, 255
15 ; CHECK-NEXT: local.tee 8
16 ; CHECK-NEXT: v128.and
17 ; CHECK-NEXT: local.get 1
18 ; CHECK-NEXT: local.get 8
19 ; CHECK-NEXT: v128.and
20 ; CHECK-NEXT: i16x8.narrow_i32x4_u
21 ; CHECK-NEXT: local.get 2
22 ; CHECK-NEXT: local.get 8
23 ; CHECK-NEXT: v128.and
24 ; CHECK-NEXT: local.get 3
25 ; CHECK-NEXT: local.get 8
26 ; CHECK-NEXT: v128.and
27 ; CHECK-NEXT: i16x8.narrow_i32x4_u
28 ; CHECK-NEXT: i16x8.narrow_i32x4_u
29 ; CHECK-NEXT: local.get 4
30 ; CHECK-NEXT: local.get 8
31 ; CHECK-NEXT: v128.and
32 ; CHECK-NEXT: local.get 5
33 ; CHECK-NEXT: local.get 8
34 ; CHECK-NEXT: v128.and
35 ; CHECK-NEXT: i16x8.narrow_i32x4_u
36 ; CHECK-NEXT: local.get 6
37 ; CHECK-NEXT: local.get 8
38 ; CHECK-NEXT: v128.and
39 ; CHECK-NEXT: local.get 7
40 ; CHECK-NEXT: local.get 8
41 ; CHECK-NEXT: v128.and
42 ; CHECK-NEXT: i16x8.narrow_i32x4_u
43 ; CHECK-NEXT: i16x8.narrow_i32x4_u
44 ; CHECK-NEXT: i8x16.narrow_i16x8_u
45 ; CHECK-NEXT: # fallthrough-return
47 %0 = trunc <16 x i64> %a to <16 x i8>
51 define <16 x i8> @trunc16i32_16i8(<16 x i32> %a) {
52 ; CHECK-LABEL: trunc16i32_16i8:
53 ; CHECK: .functype trunc16i32_16i8 (v128, v128, v128, v128) -> (v128)
54 ; CHECK-NEXT: .local v128
55 ; CHECK-NEXT: # %bb.0: # %entry
56 ; CHECK-NEXT: local.get 0
57 ; CHECK-NEXT: v128.const 255, 255, 255, 255
58 ; CHECK-NEXT: local.tee 4
59 ; CHECK-NEXT: v128.and
60 ; CHECK-NEXT: local.get 1
61 ; CHECK-NEXT: local.get 4
62 ; CHECK-NEXT: v128.and
63 ; CHECK-NEXT: i16x8.narrow_i32x4_u
64 ; CHECK-NEXT: local.get 2
65 ; CHECK-NEXT: local.get 4
66 ; CHECK-NEXT: v128.and
67 ; CHECK-NEXT: local.get 3
68 ; CHECK-NEXT: local.get 4
69 ; CHECK-NEXT: v128.and
70 ; CHECK-NEXT: i16x8.narrow_i32x4_u
71 ; CHECK-NEXT: i8x16.narrow_i16x8_u
72 ; CHECK-NEXT: # fallthrough-return
74 %0 = trunc <16 x i32> %a to <16 x i8>
78 define <16 x i8> @trunc16i16_16i8(<16 x i16> %a) {
79 ; CHECK-LABEL: trunc16i16_16i8:
80 ; CHECK: .functype trunc16i16_16i8 (v128, v128) -> (v128)
81 ; CHECK-NEXT: .local v128
82 ; CHECK-NEXT: # %bb.0: # %entry
83 ; CHECK-NEXT: local.get 0
84 ; CHECK-NEXT: v128.const 255, 255, 255, 255, 255, 255, 255, 255
85 ; CHECK-NEXT: local.tee 2
86 ; CHECK-NEXT: v128.and
87 ; CHECK-NEXT: local.get 1
88 ; CHECK-NEXT: local.get 2
89 ; CHECK-NEXT: v128.and
90 ; CHECK-NEXT: i8x16.narrow_i16x8_u
91 ; CHECK-NEXT: # fallthrough-return
93 %0 = trunc <16 x i16> %a to <16 x i8>
97 define <8 x i16> @trunc8i64_8i16(<8 x i64> %a) {
98 ; CHECK-LABEL: trunc8i64_8i16:
99 ; CHECK: .functype trunc8i64_8i16 (v128, v128, v128, v128) -> (v128)
100 ; CHECK-NEXT: .local v128
101 ; CHECK-NEXT: # %bb.0: # %entry
102 ; CHECK-NEXT: local.get 0
103 ; CHECK-NEXT: v128.const 65535, 65535
104 ; CHECK-NEXT: local.tee 4
105 ; CHECK-NEXT: v128.and
106 ; CHECK-NEXT: local.get 1
107 ; CHECK-NEXT: local.get 4
108 ; CHECK-NEXT: v128.and
109 ; CHECK-NEXT: i16x8.narrow_i32x4_u
110 ; CHECK-NEXT: local.get 2
111 ; CHECK-NEXT: local.get 4
112 ; CHECK-NEXT: v128.and
113 ; CHECK-NEXT: local.get 3
114 ; CHECK-NEXT: local.get 4
115 ; CHECK-NEXT: v128.and
116 ; CHECK-NEXT: i16x8.narrow_i32x4_u
117 ; CHECK-NEXT: i16x8.narrow_i32x4_u
118 ; CHECK-NEXT: # fallthrough-return
120 %0 = trunc <8 x i64> %a to <8 x i16>
124 define <8 x i16> @trunc8i32_8i16(<8 x i32> %a) {
125 ; CHECK-LABEL: trunc8i32_8i16:
126 ; CHECK: .functype trunc8i32_8i16 (v128, v128) -> (v128)
127 ; CHECK-NEXT: .local v128
128 ; CHECK-NEXT: # %bb.0: # %entry
129 ; CHECK-NEXT: local.get 0
130 ; CHECK-NEXT: v128.const 65535, 65535, 65535, 65535
131 ; CHECK-NEXT: local.tee 2
132 ; CHECK-NEXT: v128.and
133 ; CHECK-NEXT: local.get 1
134 ; CHECK-NEXT: local.get 2
135 ; CHECK-NEXT: v128.and
136 ; CHECK-NEXT: i16x8.narrow_i32x4_u
137 ; CHECK-NEXT: # fallthrough-return
139 %0 = trunc <8 x i32> %a to <8 x i16>