rv32Zbs.ll
9.85 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
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc -mtriple=riscv32 -verify-machineinstrs < %s \
; RUN: | FileCheck %s -check-prefix=RV32I
; RUN: llc -mtriple=riscv32 -mattr=+experimental-b -verify-machineinstrs < %s \
; RUN: | FileCheck %s -check-prefix=RV32IB
; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbs -verify-machineinstrs < %s \
; RUN: | FileCheck %s -check-prefix=RV32IBS
define i32 @sbclr_i32(i32 %a, i32 %b) nounwind {
; RV32I-LABEL: sbclr_i32:
; RV32I: # %bb.0:
; RV32I-NEXT: addi a2, zero, 1
; RV32I-NEXT: sll a1, a2, a1
; RV32I-NEXT: not a1, a1
; RV32I-NEXT: and a0, a1, a0
; RV32I-NEXT: ret
;
; RV32IB-LABEL: sbclr_i32:
; RV32IB: # %bb.0:
; RV32IB-NEXT: sbclr a0, a0, a1
; RV32IB-NEXT: ret
;
; RV32IBS-LABEL: sbclr_i32:
; RV32IBS: # %bb.0:
; RV32IBS-NEXT: sbclr a0, a0, a1
; RV32IBS-NEXT: ret
%and = and i32 %b, 31
%shl = shl nuw i32 1, %and
%neg = xor i32 %shl, -1
%and1 = and i32 %neg, %a
ret i32 %and1
}
define i64 @sbclr_i64(i64 %a, i64 %b) nounwind {
; RV32I-LABEL: sbclr_i64:
; RV32I: # %bb.0:
; RV32I-NEXT: andi a3, a2, 63
; RV32I-NEXT: addi a4, a3, -32
; RV32I-NEXT: addi a3, zero, 1
; RV32I-NEXT: bltz a4, .LBB1_2
; RV32I-NEXT: # %bb.1:
; RV32I-NEXT: mv a2, zero
; RV32I-NEXT: sll a4, a3, a4
; RV32I-NEXT: j .LBB1_3
; RV32I-NEXT: .LBB1_2:
; RV32I-NEXT: mv a4, zero
; RV32I-NEXT: sll a2, a3, a2
; RV32I-NEXT: .LBB1_3:
; RV32I-NEXT: not a3, a4
; RV32I-NEXT: not a2, a2
; RV32I-NEXT: and a0, a2, a0
; RV32I-NEXT: and a1, a3, a1
; RV32I-NEXT: ret
;
; RV32IB-LABEL: sbclr_i64:
; RV32IB: # %bb.0:
; RV32IB-NEXT: andi a3, a2, 63
; RV32IB-NEXT: addi a4, a3, -32
; RV32IB-NEXT: addi a3, zero, 1
; RV32IB-NEXT: bltz a4, .LBB1_2
; RV32IB-NEXT: # %bb.1:
; RV32IB-NEXT: mv a2, zero
; RV32IB-NEXT: sll a4, a3, a4
; RV32IB-NEXT: j .LBB1_3
; RV32IB-NEXT: .LBB1_2:
; RV32IB-NEXT: mv a4, zero
; RV32IB-NEXT: sll a2, a3, a2
; RV32IB-NEXT: .LBB1_3:
; RV32IB-NEXT: andn a0, a0, a2
; RV32IB-NEXT: andn a1, a1, a4
; RV32IB-NEXT: ret
;
; RV32IBS-LABEL: sbclr_i64:
; RV32IBS: # %bb.0:
; RV32IBS-NEXT: andi a3, a2, 63
; RV32IBS-NEXT: addi a4, a3, -32
; RV32IBS-NEXT: addi a3, zero, 1
; RV32IBS-NEXT: bltz a4, .LBB1_2
; RV32IBS-NEXT: # %bb.1:
; RV32IBS-NEXT: mv a2, zero
; RV32IBS-NEXT: sll a4, a3, a4
; RV32IBS-NEXT: j .LBB1_3
; RV32IBS-NEXT: .LBB1_2:
; RV32IBS-NEXT: mv a4, zero
; RV32IBS-NEXT: sll a2, a3, a2
; RV32IBS-NEXT: .LBB1_3:
; RV32IBS-NEXT: not a3, a4
; RV32IBS-NEXT: not a2, a2
; RV32IBS-NEXT: and a0, a2, a0
; RV32IBS-NEXT: and a1, a3, a1
; RV32IBS-NEXT: ret
%and = and i64 %b, 63
%shl = shl nuw i64 1, %and
%neg = xor i64 %shl, -1
%and1 = and i64 %neg, %a
ret i64 %and1
}
define i32 @sbset_i32(i32 %a, i32 %b) nounwind {
; RV32I-LABEL: sbset_i32:
; RV32I: # %bb.0:
; RV32I-NEXT: addi a2, zero, 1
; RV32I-NEXT: sll a1, a2, a1
; RV32I-NEXT: or a0, a1, a0
; RV32I-NEXT: ret
;
; RV32IB-LABEL: sbset_i32:
; RV32IB: # %bb.0:
; RV32IB-NEXT: sbset a0, a0, a1
; RV32IB-NEXT: ret
;
; RV32IBS-LABEL: sbset_i32:
; RV32IBS: # %bb.0:
; RV32IBS-NEXT: sbset a0, a0, a1
; RV32IBS-NEXT: ret
%and = and i32 %b, 31
%shl = shl nuw i32 1, %and
%or = or i32 %shl, %a
ret i32 %or
}
; As we are not matching directly i64 code patterns on RV32 some i64 patterns
; don't have yet any matching bit manipulation instructions on RV32.
; This test is presented here in case future expansions of the experimental-b
; extension introduce instructions suitable for this pattern.
define i64 @sbset_i64(i64 %a, i64 %b) nounwind {
; RV32I-LABEL: sbset_i64:
; RV32I: # %bb.0:
; RV32I-NEXT: addi a3, zero, 1
; RV32I-NEXT: sll a2, a3, a2
; RV32I-NEXT: srai a3, a2, 31
; RV32I-NEXT: or a0, a2, a0
; RV32I-NEXT: or a1, a3, a1
; RV32I-NEXT: ret
;
; RV32IB-LABEL: sbset_i64:
; RV32IB: # %bb.0:
; RV32IB-NEXT: addi a3, zero, 1
; RV32IB-NEXT: sll a2, a3, a2
; RV32IB-NEXT: srai a3, a2, 31
; RV32IB-NEXT: or a0, a2, a0
; RV32IB-NEXT: or a1, a3, a1
; RV32IB-NEXT: ret
;
; RV32IBS-LABEL: sbset_i64:
; RV32IBS: # %bb.0:
; RV32IBS-NEXT: addi a3, zero, 1
; RV32IBS-NEXT: sll a2, a3, a2
; RV32IBS-NEXT: srai a3, a2, 31
; RV32IBS-NEXT: or a0, a2, a0
; RV32IBS-NEXT: or a1, a3, a1
; RV32IBS-NEXT: ret
%1 = trunc i64 %b to i32
%conv = and i32 %1, 63
%shl = shl nuw i32 1, %conv
%conv1 = sext i32 %shl to i64
%or = or i64 %conv1, %a
ret i64 %or
}
define i32 @sbinv_i32(i32 %a, i32 %b) nounwind {
; RV32I-LABEL: sbinv_i32:
; RV32I: # %bb.0:
; RV32I-NEXT: addi a2, zero, 1
; RV32I-NEXT: sll a1, a2, a1
; RV32I-NEXT: xor a0, a1, a0
; RV32I-NEXT: ret
;
; RV32IB-LABEL: sbinv_i32:
; RV32IB: # %bb.0:
; RV32IB-NEXT: sbinv a0, a0, a1
; RV32IB-NEXT: ret
;
; RV32IBS-LABEL: sbinv_i32:
; RV32IBS: # %bb.0:
; RV32IBS-NEXT: sbinv a0, a0, a1
; RV32IBS-NEXT: ret
%and = and i32 %b, 31
%shl = shl nuw i32 1, %and
%xor = xor i32 %shl, %a
ret i32 %xor
}
; As we are not matching directly i64 code patterns on RV32 some i64 patterns
; don't have yet any matching bit manipulation instructions on RV32.
; This test is presented here in case future expansions of the experimental-b
; extension introduce instructions suitable for this pattern.
define i64 @sbinv_i64(i64 %a, i64 %b) nounwind {
; RV32I-LABEL: sbinv_i64:
; RV32I: # %bb.0:
; RV32I-NEXT: addi a3, zero, 1
; RV32I-NEXT: sll a2, a3, a2
; RV32I-NEXT: srai a3, a2, 31
; RV32I-NEXT: xor a0, a2, a0
; RV32I-NEXT: xor a1, a3, a1
; RV32I-NEXT: ret
;
; RV32IB-LABEL: sbinv_i64:
; RV32IB: # %bb.0:
; RV32IB-NEXT: addi a3, zero, 1
; RV32IB-NEXT: sll a2, a3, a2
; RV32IB-NEXT: srai a3, a2, 31
; RV32IB-NEXT: xor a0, a2, a0
; RV32IB-NEXT: xor a1, a3, a1
; RV32IB-NEXT: ret
;
; RV32IBS-LABEL: sbinv_i64:
; RV32IBS: # %bb.0:
; RV32IBS-NEXT: addi a3, zero, 1
; RV32IBS-NEXT: sll a2, a3, a2
; RV32IBS-NEXT: srai a3, a2, 31
; RV32IBS-NEXT: xor a0, a2, a0
; RV32IBS-NEXT: xor a1, a3, a1
; RV32IBS-NEXT: ret
%1 = trunc i64 %b to i32
%conv = and i32 %1, 63
%shl = shl nuw i32 1, %conv
%conv1 = sext i32 %shl to i64
%xor = xor i64 %conv1, %a
ret i64 %xor
}
define i32 @sbext_i32(i32 %a, i32 %b) nounwind {
; RV32I-LABEL: sbext_i32:
; RV32I: # %bb.0:
; RV32I-NEXT: srl a0, a0, a1
; RV32I-NEXT: andi a0, a0, 1
; RV32I-NEXT: ret
;
; RV32IB-LABEL: sbext_i32:
; RV32IB: # %bb.0:
; RV32IB-NEXT: sbext a0, a0, a1
; RV32IB-NEXT: ret
;
; RV32IBS-LABEL: sbext_i32:
; RV32IBS: # %bb.0:
; RV32IBS-NEXT: sbext a0, a0, a1
; RV32IBS-NEXT: ret
%and = and i32 %b, 31
%shr = lshr i32 %a, %and
%and1 = and i32 %shr, 1
ret i32 %and1
}
; As we are not matching directly i64 code patterns on RV32 some i64 patterns
; don't have yet any matching bit manipulation instructions on RV32.
; This test is presented here in case future expansions of the experimental-b
; extension introduce instructions suitable for this pattern.
define i64 @sbext_i64(i64 %a, i64 %b) nounwind {
; RV32I-LABEL: sbext_i64:
; RV32I: # %bb.0:
; RV32I-NEXT: andi a3, a2, 63
; RV32I-NEXT: addi a4, a3, -32
; RV32I-NEXT: bltz a4, .LBB7_2
; RV32I-NEXT: # %bb.1:
; RV32I-NEXT: srl a0, a1, a4
; RV32I-NEXT: j .LBB7_3
; RV32I-NEXT: .LBB7_2:
; RV32I-NEXT: srl a0, a0, a2
; RV32I-NEXT: addi a2, zero, 31
; RV32I-NEXT: sub a2, a2, a3
; RV32I-NEXT: slli a1, a1, 1
; RV32I-NEXT: sll a1, a1, a2
; RV32I-NEXT: or a0, a0, a1
; RV32I-NEXT: .LBB7_3:
; RV32I-NEXT: andi a0, a0, 1
; RV32I-NEXT: mv a1, zero
; RV32I-NEXT: ret
;
; RV32IB-LABEL: sbext_i64:
; RV32IB: # %bb.0:
; RV32IB-NEXT: andi a3, a2, 63
; RV32IB-NEXT: addi a4, a3, -32
; RV32IB-NEXT: bltz a4, .LBB7_2
; RV32IB-NEXT: # %bb.1:
; RV32IB-NEXT: srl a0, a1, a4
; RV32IB-NEXT: j .LBB7_3
; RV32IB-NEXT: .LBB7_2:
; RV32IB-NEXT: srl a0, a0, a2
; RV32IB-NEXT: addi a2, zero, 31
; RV32IB-NEXT: sub a2, a2, a3
; RV32IB-NEXT: slli a1, a1, 1
; RV32IB-NEXT: sll a1, a1, a2
; RV32IB-NEXT: or a0, a0, a1
; RV32IB-NEXT: .LBB7_3:
; RV32IB-NEXT: andi a0, a0, 1
; RV32IB-NEXT: mv a1, zero
; RV32IB-NEXT: ret
;
; RV32IBS-LABEL: sbext_i64:
; RV32IBS: # %bb.0:
; RV32IBS-NEXT: andi a3, a2, 63
; RV32IBS-NEXT: addi a4, a3, -32
; RV32IBS-NEXT: bltz a4, .LBB7_2
; RV32IBS-NEXT: # %bb.1:
; RV32IBS-NEXT: srl a0, a1, a4
; RV32IBS-NEXT: j .LBB7_3
; RV32IBS-NEXT: .LBB7_2:
; RV32IBS-NEXT: srl a0, a0, a2
; RV32IBS-NEXT: addi a2, zero, 31
; RV32IBS-NEXT: sub a2, a2, a3
; RV32IBS-NEXT: slli a1, a1, 1
; RV32IBS-NEXT: sll a1, a1, a2
; RV32IBS-NEXT: or a0, a0, a1
; RV32IBS-NEXT: .LBB7_3:
; RV32IBS-NEXT: andi a0, a0, 1
; RV32IBS-NEXT: mv a1, zero
; RV32IBS-NEXT: ret
%conv = and i64 %b, 63
%shr = lshr i64 %a, %conv
%and1 = and i64 %shr, 1
ret i64 %and1
}
define i32 @sbexti_i32(i32 %a) nounwind {
; RV32I-LABEL: sbexti_i32:
; RV32I: # %bb.0:
; RV32I-NEXT: srli a0, a0, 5
; RV32I-NEXT: andi a0, a0, 1
; RV32I-NEXT: ret
;
; RV32IB-LABEL: sbexti_i32:
; RV32IB: # %bb.0:
; RV32IB-NEXT: sbexti a0, a0, 5
; RV32IB-NEXT: ret
;
; RV32IBS-LABEL: sbexti_i32:
; RV32IBS: # %bb.0:
; RV32IBS-NEXT: sbexti a0, a0, 5
; RV32IBS-NEXT: ret
%shr = lshr i32 %a, 5
%and = and i32 %shr, 1
ret i32 %and
}
define i64 @sbexti_i64(i64 %a) nounwind {
; RV32I-LABEL: sbexti_i64:
; RV32I: # %bb.0:
; RV32I-NEXT: srli a0, a0, 5
; RV32I-NEXT: andi a0, a0, 1
; RV32I-NEXT: mv a1, zero
; RV32I-NEXT: ret
;
; RV32IB-LABEL: sbexti_i64:
; RV32IB: # %bb.0:
; RV32IB-NEXT: sbexti a0, a0, 5
; RV32IB-NEXT: mv a1, zero
; RV32IB-NEXT: ret
;
; RV32IBS-LABEL: sbexti_i64:
; RV32IBS: # %bb.0:
; RV32IBS-NEXT: sbexti a0, a0, 5
; RV32IBS-NEXT: mv a1, zero
; RV32IBS-NEXT: ret
%shr = lshr i64 %a, 5
%and = and i64 %shr, 1
ret i64 %and
}