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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
| ; RUN: llc -march=hexagon < %s | FileCheck %s
; This test checks for the generation of 64b mul instruction
; (dpmpyss_s0 and dpmpyuu_s0).
; Checks for unsigned multiplication.
; 16 x 16 = 64
; CHECK-LABEL: f0:
; CHECK: r1:0 = mpyu(
define i64 @f0(i16 zeroext %a0, i16 zeroext %a1) local_unnamed_addr #0 {
b0:
%v0 = zext i16 %a0 to i64
%v1 = zext i16 %a1 to i64
%v2 = mul nuw nsw i64 %v1, %v0
ret i64 %v2
}
; 32 x 32 = 64
; CHECK-LABEL: f1:
; CHECK: r1:0 = mpyu(
define i64 @f1(i32 %a0, i32 %a1) local_unnamed_addr #0 {
b0:
%v0 = zext i32 %a0 to i64
%v1 = zext i32 %a1 to i64
%v2 = mul nuw nsw i64 %v1, %v0
ret i64 %v2
}
; Given int w[2], short h[4], signed char c[8], the below tests check for the
; generation of dpmpyuu_s0.
; w[0] * h[0]
; CHECK-LABEL: f2:
; CHECK: = sxth
; CHECK: r1:0 = mpyu(
define i64 @f2(i64 %a0, i64 %a1) local_unnamed_addr #0 {
b0:
%v0 = and i64 %a0, 4294967295
%v1 = trunc i64 %a1 to i32
%v2 = shl i32 %v1, 16
%v3 = ashr exact i32 %v2, 16
%v4 = zext i32 %v3 to i64
%v5 = mul nuw i64 %v0, %v4
ret i64 %v5
}
; w[0] * h[1]
; CHECK-LABEL: f3:
; CHECK: = asrh
; CHECK: r1:0 = mpyu(
define i64 @f3(i64 %a0, i64 %a1) local_unnamed_addr #0 {
b0:
%v0 = and i64 %a0, 4294967295
%v1 = trunc i64 %a1 to i32
%v2 = ashr i32 %v1, 16
%v3 = zext i32 %v2 to i64
%v4 = mul nuw i64 %v0, %v3
ret i64 %v4
}
; w[0] * h[2]
; CHECK-LABEL: f4:
; CHECK: = extract(
; CHECK: r1:0 = mpyu(
define i64 @f4(i64 %a0, i64 %a1) local_unnamed_addr #0 {
b0:
%v0 = and i64 %a0, 4294967295
%v1 = lshr i64 %a1, 32
%v2 = shl nuw nsw i64 %v1, 16
%v3 = trunc i64 %v2 to i32
%v4 = ashr exact i32 %v3, 16
%v5 = zext i32 %v4 to i64
%v6 = mul nuw i64 %v0, %v5
ret i64 %v6
}
; w[0] * h[3]
; CHECK-LABEL: f5:
; CHECK: = extractu(
; CHECK: r1:0 = mpyu(
define i64 @f5(i64 %a0, i64 %a1) local_unnamed_addr #0 {
b0:
%v0 = and i64 %a0, 4294967295
%v1 = lshr i64 %a1, 48
%v2 = shl nuw nsw i64 %v1, 16
%v3 = trunc i64 %v2 to i32
%v4 = ashr exact i32 %v3, 16
%v5 = zext i32 %v4 to i64
%v6 = mul nuw i64 %v0, %v5
ret i64 %v6
}
; w[1] * h[0]
; CHECK-LABEL: f6:
; CHECK: = sxth(
; CHECK: r1:0 = mpyu(
define i64 @f6(i64 %a0, i64 %a1) local_unnamed_addr #0 {
b0:
%v0 = lshr i64 %a0, 32
%v1 = trunc i64 %a1 to i32
%v2 = shl i32 %v1, 16
%v3 = ashr exact i32 %v2, 16
%v4 = zext i32 %v3 to i64
%v5 = mul nuw i64 %v0, %v4
ret i64 %v5
}
; w[0] * c[0]
; CHECK-LABEL: f7:
; CHECK: = and({{.*}}#255)
; CHECK: r1:0 = mpyu(
define i64 @f7(i64 %a0, i64 %a1) local_unnamed_addr #0 {
b0:
%v0 = and i64 %a0, 4294967295
%v1 = and i64 %a1, 255
%v2 = mul nuw nsw i64 %v1, %v0
ret i64 %v2
}
; w[0] * c[2]
; CHECK-LABEL: f8:
; CHECK: = extractu(
; CHECK: r1:0 = mpyu(
define i64 @f8(i64 %a0, i64 %a1) local_unnamed_addr #0 {
b0:
%v0 = and i64 %a0, 4294967295
%v1 = lshr i64 %a1, 16
%v2 = and i64 %v1, 255
%v3 = mul nuw nsw i64 %v2, %v0
ret i64 %v3
}
; w[0] * c[7]
; CHECK-LABEL: f9:
; CHECK: = lsr(
; CHECK: r1:0 = mpyu(
define i64 @f9(i64 %a0, i64 %a1) local_unnamed_addr #0 {
b0:
%v0 = and i64 %a0, 4294967295
%v1 = lshr i64 %a1, 56
%v2 = mul nuw nsw i64 %v1, %v0
ret i64 %v2
}
; Checks for signed multiplication.
; 16 x 16 = 64
; CHECK-LABEL: f10:
; CHECK: r1:0 = mpy(
define i64 @f10(i16 signext %a0, i16 signext %a1) local_unnamed_addr #0 {
b0:
%v0 = sext i16 %a0 to i64
%v1 = sext i16 %a1 to i64
%v2 = mul nsw i64 %v1, %v0
ret i64 %v2
}
; 32 x 32 = 64
; CHECK-LABEL: f11:
; CHECK: r1:0 = mpy(
define i64 @f11(i32 %a0, i32 %a1) local_unnamed_addr #0 {
b0:
%v0 = sext i32 %a0 to i64
%v1 = sext i32 %a1 to i64
%v2 = mul nsw i64 %v1, %v0
ret i64 %v2
}
; Given unsigned int w[2], unsigned short h[4], unsigned char c[8], the below
; tests check for the generation of dpmpyss_s0.
; w[0] * h[0]
; CHECK-LABEL: f12:
; CHECK: = sxth
; CHECK: r1:0 = mpy(
define i64 @f12(i64 %a0, i64 %a1) local_unnamed_addr #0 {
b0:
%v0 = shl i64 %a0, 32
%v1 = ashr exact i64 %v0, 32
%v2 = shl i64 %a1, 48
%v3 = ashr exact i64 %v2, 48
%v4 = mul nsw i64 %v3, %v1
ret i64 %v4
}
; w[0] * h[1]
; CHECK-LABEL: f13:
; CHECK: = asrh
; CHECK: r1:0 = mpy(
define i64 @f13(i64 %a0, i64 %a1) local_unnamed_addr #0 {
b0:
%v0 = shl i64 %a0, 32
%v1 = ashr exact i64 %v0, 32
%v2 = trunc i64 %a1 to i32
%v3 = ashr i32 %v2, 16
%v4 = sext i32 %v3 to i64
%v5 = mul nsw i64 %v1, %v4
ret i64 %v5
}
; w[0] * h[2]
; CHECK-LABEL: f14:
; CHECK: = extract(
; CHECK: r1:0 = mpy(
define i64 @f14(i64 %a0, i64 %a1) local_unnamed_addr #0 {
b0:
%v0 = shl i64 %a0, 32
%v1 = ashr exact i64 %v0, 32
%v2 = lshr i64 %a1, 32
%v3 = shl nuw nsw i64 %v2, 16
%v4 = trunc i64 %v3 to i32
%v5 = ashr exact i32 %v4, 16
%v6 = sext i32 %v5 to i64
%v7 = mul nsw i64 %v1, %v6
ret i64 %v7
}
; w[0] * h[3]
; CHECK-LABEL: f15:
; CHECK: = sxth(
; CHECK: r1:0 = mpy(
define i64 @f15(i64 %a0, i64 %a1) local_unnamed_addr #0 {
b0:
%v0 = ashr i64 %a0, 32
%v1 = shl i64 %a1, 48
%v2 = ashr exact i64 %v1, 48
%v3 = mul nsw i64 %v2, %v0
ret i64 %v3
}
; w[1] * h[0]
; CHECK-LABEL: f16:
; CHECK: = asrh(
; CHECK: r1:0 = mpy(
define i64 @f16(i64 %a0, i64 %a1) local_unnamed_addr #0 {
b0:
%v0 = ashr i64 %a0, 32
%v1 = trunc i64 %a1 to i32
%v2 = ashr i32 %v1, 16
%v3 = sext i32 %v2 to i64
%v4 = mul nsw i64 %v0, %v3
ret i64 %v4
}
; w[0] * c[0]
; CHECK-LABEL: f17:
; CHECK: = sxtb(
; CHECK: r1:0 = mpy(
define i64 @f17(i64 %a0, i64 %a1) local_unnamed_addr #0 {
b0:
%v0 = shl i64 %a0, 32
%v1 = ashr exact i64 %v0, 32
%v2 = shl i64 %a1, 56
%v3 = ashr exact i64 %v2, 56
%v4 = mul nsw i64 %v3, %v1
ret i64 %v4
}
; w[0] * c[2]
; CHECK-LABEL: f18:
; CHECK: = extract(
; CHECK: r1:0 = mpy(
define i64 @f18(i64 %a0, i64 %a1) local_unnamed_addr #0 {
b0:
%v0 = shl i64 %a0, 32
%v1 = ashr exact i64 %v0, 32
%v2 = lshr i64 %a1, 16
%v3 = shl i64 %v2, 24
%v4 = trunc i64 %v3 to i32
%v5 = ashr exact i32 %v4, 24
%v6 = sext i32 %v5 to i64
%v7 = mul nsw i64 %v1, %v6
ret i64 %v7
}
; w[0] * c[7]
; CHECK-LABEL: f19:
; CHECK: = sxtb(
; CHECK: r1:0 = mpy(
define i64 @f19(i64 %a0, i64 %a1) local_unnamed_addr #0 {
b0:
%v0 = shl i64 %a0, 32
%v1 = ashr exact i64 %v0, 32
%v2 = lshr i64 %a1, 56
%v3 = shl nuw nsw i64 %v2, 24
%v4 = trunc i64 %v3 to i32
%v5 = ashr exact i32 %v4, 24
%v6 = sext i32 %v5 to i64
%v7 = mul nsw i64 %v1, %v6
ret i64 %v7
}
attributes #0 = { norecurse nounwind readnone "target-cpu"="hexagonv60" "target-features"="-hvx" }
|