simd-widening.ll
6.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc < %s -mattr=+simd128 | FileCheck %s
;; Test that SIMD widening operations can be successfully selected
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
target triple = "wasm32-unknown-unknown"
define <8 x i16> @widen_low_i8x16_s(<16 x i8> %v) {
; CHECK-LABEL: widen_low_i8x16_s:
; CHECK: .functype widen_low_i8x16_s (v128) -> (v128)
; CHECK-NEXT: # %bb.0:
; CHECK-NEXT: local.get 0
; CHECK-NEXT: i16x8.widen_low_i8x16_s
; CHECK-NEXT: # fallthrough-return
%low = shufflevector <16 x i8> %v, <16 x i8> undef,
<8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
%widened = sext <8 x i8> %low to <8 x i16>
ret <8 x i16> %widened
}
define <8 x i16> @widen_low_i8x16_u(<16 x i8> %v) {
; CHECK-LABEL: widen_low_i8x16_u:
; CHECK: .functype widen_low_i8x16_u (v128) -> (v128)
; CHECK-NEXT: # %bb.0:
; CHECK-NEXT: local.get 0
; CHECK-NEXT: i16x8.widen_low_i8x16_u
; CHECK-NEXT: # fallthrough-return
%low = shufflevector <16 x i8> %v, <16 x i8> undef,
<8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
%widened = zext <8 x i8> %low to <8 x i16>
ret <8 x i16> %widened
}
define <8 x i16> @widen_high_i8x16_s(<16 x i8> %v) {
; CHECK-LABEL: widen_high_i8x16_s:
; CHECK: .functype widen_high_i8x16_s (v128) -> (v128)
; CHECK-NEXT: # %bb.0:
; CHECK-NEXT: local.get 0
; CHECK-NEXT: i16x8.widen_high_i8x16_s
; CHECK-NEXT: # fallthrough-return
%low = shufflevector <16 x i8> %v, <16 x i8> undef,
<8 x i32> <i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>
%widened = sext <8 x i8> %low to <8 x i16>
ret <8 x i16> %widened
}
define <8 x i16> @widen_high_i8x16_u(<16 x i8> %v) {
; CHECK-LABEL: widen_high_i8x16_u:
; CHECK: .functype widen_high_i8x16_u (v128) -> (v128)
; CHECK-NEXT: # %bb.0:
; CHECK-NEXT: local.get 0
; CHECK-NEXT: i16x8.widen_high_i8x16_u
; CHECK-NEXT: # fallthrough-return
%low = shufflevector <16 x i8> %v, <16 x i8> undef,
<8 x i32> <i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>
%widened = zext <8 x i8> %low to <8 x i16>
ret <8 x i16> %widened
}
define <4 x i32> @widen_low_i16x8_s(<8 x i16> %v) {
; CHECK-LABEL: widen_low_i16x8_s:
; CHECK: .functype widen_low_i16x8_s (v128) -> (v128)
; CHECK-NEXT: # %bb.0:
; CHECK-NEXT: local.get 0
; CHECK-NEXT: i32x4.widen_low_i16x8_s
; CHECK-NEXT: # fallthrough-return
%low = shufflevector <8 x i16> %v, <8 x i16> undef,
<4 x i32> <i32 0, i32 1, i32 2, i32 3>
%widened = sext <4 x i16> %low to <4 x i32>
ret <4 x i32> %widened
}
define <4 x i32> @widen_low_i16x8_u(<8 x i16> %v) {
; CHECK-LABEL: widen_low_i16x8_u:
; CHECK: .functype widen_low_i16x8_u (v128) -> (v128)
; CHECK-NEXT: # %bb.0:
; CHECK-NEXT: local.get 0
; CHECK-NEXT: i32x4.widen_low_i16x8_u
; CHECK-NEXT: # fallthrough-return
%low = shufflevector <8 x i16> %v, <8 x i16> undef,
<4 x i32> <i32 0, i32 1, i32 2, i32 3>
%widened = zext <4 x i16> %low to <4 x i32>
ret <4 x i32> %widened
}
define <4 x i32> @widen_high_i16x8_s(<8 x i16> %v) {
; CHECK-LABEL: widen_high_i16x8_s:
; CHECK: .functype widen_high_i16x8_s (v128) -> (v128)
; CHECK-NEXT: # %bb.0:
; CHECK-NEXT: local.get 0
; CHECK-NEXT: i32x4.widen_high_i16x8_s
; CHECK-NEXT: # fallthrough-return
%low = shufflevector <8 x i16> %v, <8 x i16> undef,
<4 x i32> <i32 4, i32 5, i32 6, i32 7>
%widened = sext <4 x i16> %low to <4 x i32>
ret <4 x i32> %widened
}
define <4 x i32> @widen_high_i16x8_u(<8 x i16> %v) {
; CHECK-LABEL: widen_high_i16x8_u:
; CHECK: .functype widen_high_i16x8_u (v128) -> (v128)
; CHECK-NEXT: # %bb.0:
; CHECK-NEXT: local.get 0
; CHECK-NEXT: i32x4.widen_high_i16x8_u
; CHECK-NEXT: # fallthrough-return
%low = shufflevector <8 x i16> %v, <8 x i16> undef,
<4 x i32> <i32 4, i32 5, i32 6, i32 7>
%widened = zext <4 x i16> %low to <4 x i32>
ret <4 x i32> %widened
}
;; Also test that similar patterns with offsets not corresponding to
;; the low or high half are correctly expanded.
define <8 x i16> @widen_lowish_i8x16_s(<16 x i8> %v) {
; CHECK-LABEL: widen_lowish_i8x16_s:
; CHECK: .functype widen_lowish_i8x16_s (v128) -> (v128)
; CHECK-NEXT: # %bb.0:
; CHECK-NEXT: local.get 0
; CHECK-NEXT: i8x16.extract_lane_u 1
; CHECK-NEXT: i16x8.splat
; CHECK-NEXT: local.get 0
; CHECK-NEXT: i8x16.extract_lane_u 2
; CHECK-NEXT: i16x8.replace_lane 1
; CHECK-NEXT: local.get 0
; CHECK-NEXT: i8x16.extract_lane_u 3
; CHECK-NEXT: i16x8.replace_lane 2
; CHECK-NEXT: local.get 0
; CHECK-NEXT: i8x16.extract_lane_u 4
; CHECK-NEXT: i16x8.replace_lane 3
; CHECK-NEXT: local.get 0
; CHECK-NEXT: i8x16.extract_lane_u 5
; CHECK-NEXT: i16x8.replace_lane 4
; CHECK-NEXT: local.get 0
; CHECK-NEXT: i8x16.extract_lane_u 6
; CHECK-NEXT: i16x8.replace_lane 5
; CHECK-NEXT: local.get 0
; CHECK-NEXT: i8x16.extract_lane_u 7
; CHECK-NEXT: i16x8.replace_lane 6
; CHECK-NEXT: local.get 0
; CHECK-NEXT: i8x16.extract_lane_u 8
; CHECK-NEXT: i16x8.replace_lane 7
; CHECK-NEXT: i32.const 8
; CHECK-NEXT: i16x8.shl
; CHECK-NEXT: i32.const 8
; CHECK-NEXT: i16x8.shr_s
; CHECK-NEXT: # fallthrough-return
%lowish = shufflevector <16 x i8> %v, <16 x i8> undef,
<8 x i32> <i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8>
%widened = sext <8 x i8> %lowish to <8 x i16>
ret <8 x i16> %widened
}
define <4 x i32> @widen_lowish_i16x8_s(<8 x i16> %v) {
; CHECK-LABEL: widen_lowish_i16x8_s:
; CHECK: .functype widen_lowish_i16x8_s (v128) -> (v128)
; CHECK-NEXT: # %bb.0:
; CHECK-NEXT: local.get 0
; CHECK-NEXT: i16x8.extract_lane_u 1
; CHECK-NEXT: i32x4.splat
; CHECK-NEXT: local.get 0
; CHECK-NEXT: i16x8.extract_lane_u 2
; CHECK-NEXT: i32x4.replace_lane 1
; CHECK-NEXT: local.get 0
; CHECK-NEXT: i16x8.extract_lane_u 3
; CHECK-NEXT: i32x4.replace_lane 2
; CHECK-NEXT: local.get 0
; CHECK-NEXT: i16x8.extract_lane_u 4
; CHECK-NEXT: i32x4.replace_lane 3
; CHECK-NEXT: i32.const 16
; CHECK-NEXT: i32x4.shl
; CHECK-NEXT: i32.const 16
; CHECK-NEXT: i32x4.shr_s
; CHECK-NEXT: # fallthrough-return
%lowish = shufflevector <8 x i16> %v, <8 x i16> undef,
<4 x i32> <i32 1, i32 2, i32 3, i32 4>
%widened = sext <4 x i16> %lowish to <4 x i32>
ret <4 x i32> %widened
}