File: shift-amount-mod.ll

package info (click to toggle)
llvm-toolchain-17 1%3A17.0.6-22
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,799,624 kB
  • sloc: cpp: 6,428,607; ansic: 1,383,196; asm: 793,408; python: 223,504; objc: 75,364; f90: 60,502; lisp: 33,869; pascal: 15,282; sh: 9,684; perl: 7,453; ml: 4,937; awk: 3,523; makefile: 2,889; javascript: 2,149; xml: 888; fortran: 619; cs: 573
file content (280 lines) | stat: -rw-r--r-- 7,414 bytes parent folder | download | duplicates (6)
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
; 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=riscv64 -verify-machineinstrs < %s \
; RUN:   | FileCheck %s -check-prefix=RV64I

define i32 @shl_by_complemented_32(i32 %x) {
; RV32I-LABEL: shl_by_complemented_32:
; RV32I:       # %bb.0:
; RV32I-NEXT:    not a1, a0
; RV32I-NEXT:    sll a0, a0, a1
; RV32I-NEXT:    ret
;
; RV64I-LABEL: shl_by_complemented_32:
; RV64I:       # %bb.0:
; RV64I-NEXT:    not a1, a0
; RV64I-NEXT:    sllw a0, a0, a1
; RV64I-NEXT:    ret
  %a = sub i32 31, %x
  %b = shl i32 %x, %a
  ret i32 %b
}

define i64 @shl_by_complemented_64(i64 %x) {
; RV32I-LABEL: shl_by_complemented_64:
; RV32I:       # %bb.0:
; RV32I-NEXT:    not a4, a0
; RV32I-NEXT:    li a2, 31
; RV32I-NEXT:    sub a2, a2, a0
; RV32I-NEXT:    sll a3, a0, a4
; RV32I-NEXT:    bltz a2, .LBB1_2
; RV32I-NEXT:  # %bb.1:
; RV32I-NEXT:    mv a1, a3
; RV32I-NEXT:    j .LBB1_3
; RV32I-NEXT:  .LBB1_2:
; RV32I-NEXT:    sll a1, a1, a4
; RV32I-NEXT:    li a4, 63
; RV32I-NEXT:    sub a4, a4, a0
; RV32I-NEXT:    not a4, a4
; RV32I-NEXT:    srli a0, a0, 1
; RV32I-NEXT:    srl a0, a0, a4
; RV32I-NEXT:    or a1, a1, a0
; RV32I-NEXT:  .LBB1_3:
; RV32I-NEXT:    srai a0, a2, 31
; RV32I-NEXT:    and a0, a0, a3
; RV32I-NEXT:    ret
;
; RV64I-LABEL: shl_by_complemented_64:
; RV64I:       # %bb.0:
; RV64I-NEXT:    not a1, a0
; RV64I-NEXT:    sll a0, a0, a1
; RV64I-NEXT:    ret
  %a = sub i64 63, %x
  %b = shl i64 %x, %a
  ret i64 %b
}

define i32 @lshr_by_complemented_32(i32 %x) {
; RV32I-LABEL: lshr_by_complemented_32:
; RV32I:       # %bb.0:
; RV32I-NEXT:    not a1, a0
; RV32I-NEXT:    srl a0, a0, a1
; RV32I-NEXT:    ret
;
; RV64I-LABEL: lshr_by_complemented_32:
; RV64I:       # %bb.0:
; RV64I-NEXT:    not a1, a0
; RV64I-NEXT:    srlw a0, a0, a1
; RV64I-NEXT:    ret
  %a = sub i32 31, %x
  %b = lshr i32 %x, %a
  ret i32 %b
}

define i64 @lshr_by_complemented_64(i64 %x) {
; RV32I-LABEL: lshr_by_complemented_64:
; RV32I:       # %bb.0:
; RV32I-NEXT:    not a4, a0
; RV32I-NEXT:    li a2, 31
; RV32I-NEXT:    sub a2, a2, a0
; RV32I-NEXT:    srl a3, a1, a4
; RV32I-NEXT:    bltz a2, .LBB3_2
; RV32I-NEXT:  # %bb.1:
; RV32I-NEXT:    mv a0, a3
; RV32I-NEXT:    j .LBB3_3
; RV32I-NEXT:  .LBB3_2:
; RV32I-NEXT:    srl a4, a0, a4
; RV32I-NEXT:    li a5, 63
; RV32I-NEXT:    sub a5, a5, a0
; RV32I-NEXT:    not a0, a5
; RV32I-NEXT:    slli a1, a1, 1
; RV32I-NEXT:    sll a0, a1, a0
; RV32I-NEXT:    or a0, a4, a0
; RV32I-NEXT:  .LBB3_3:
; RV32I-NEXT:    srai a1, a2, 31
; RV32I-NEXT:    and a1, a1, a3
; RV32I-NEXT:    ret
;
; RV64I-LABEL: lshr_by_complemented_64:
; RV64I:       # %bb.0:
; RV64I-NEXT:    not a1, a0
; RV64I-NEXT:    srl a0, a0, a1
; RV64I-NEXT:    ret
  %a = sub i64 63, %x
  %b = lshr i64 %x, %a
  ret i64 %b
}

define i32 @ashr_by_complemented_32(i32 %x) {
; RV32I-LABEL: ashr_by_complemented_32:
; RV32I:       # %bb.0:
; RV32I-NEXT:    not a1, a0
; RV32I-NEXT:    sra a0, a0, a1
; RV32I-NEXT:    ret
;
; RV64I-LABEL: ashr_by_complemented_32:
; RV64I:       # %bb.0:
; RV64I-NEXT:    not a1, a0
; RV64I-NEXT:    sraw a0, a0, a1
; RV64I-NEXT:    ret
  %a = sub i32 31, %x
  %b = ashr i32 %x, %a
  ret i32 %b
}

define i64 @ashr_by_complemented_64(i64 %x) {
; RV32I-LABEL: ashr_by_complemented_64:
; RV32I:       # %bb.0:
; RV32I-NEXT:    mv a2, a0
; RV32I-NEXT:    li a0, 31
; RV32I-NEXT:    sub a4, a0, a2
; RV32I-NEXT:    not a3, a2
; RV32I-NEXT:    sra a0, a1, a3
; RV32I-NEXT:    bltz a4, .LBB5_2
; RV32I-NEXT:  # %bb.1:
; RV32I-NEXT:    srai a1, a1, 31
; RV32I-NEXT:    ret
; RV32I-NEXT:  .LBB5_2:
; RV32I-NEXT:    srl a3, a2, a3
; RV32I-NEXT:    li a4, 63
; RV32I-NEXT:    sub a4, a4, a2
; RV32I-NEXT:    not a2, a4
; RV32I-NEXT:    slli a1, a1, 1
; RV32I-NEXT:    sll a1, a1, a2
; RV32I-NEXT:    or a3, a3, a1
; RV32I-NEXT:    mv a1, a0
; RV32I-NEXT:    mv a0, a3
; RV32I-NEXT:    ret
;
; RV64I-LABEL: ashr_by_complemented_64:
; RV64I:       # %bb.0:
; RV64I-NEXT:    not a1, a0
; RV64I-NEXT:    sra a0, a0, a1
; RV64I-NEXT:    ret
  %a = sub i64 63, %x
  %b = ashr i64 %x, %a
  ret i64 %b
}

define i32 @shl_by_masked_complemented_32(i32 %x) {
; RV32I-LABEL: shl_by_masked_complemented_32:
; RV32I:       # %bb.0:
; RV32I-NEXT:    not a1, a0
; RV32I-NEXT:    sll a0, a0, a1
; RV32I-NEXT:    ret
;
; RV64I-LABEL: shl_by_masked_complemented_32:
; RV64I:       # %bb.0:
; RV64I-NEXT:    not a1, a0
; RV64I-NEXT:    sllw a0, a0, a1
; RV64I-NEXT:    ret
  %a = sub i32 31, %x
  %b = and i32 %a, 31
  %c = shl i32 %x, %b
  ret i32 %c
}

define i64 @shl_by_masked_complemented_64(i64 %x) {
; RV32I-LABEL: shl_by_masked_complemented_64:
; RV32I:       # %bb.0:
; RV32I-NEXT:    li a2, 63
; RV32I-NEXT:    sub a2, a2, a0
; RV32I-NEXT:    andi a4, a2, 63
; RV32I-NEXT:    addi a2, a4, -32
; RV32I-NEXT:    not a3, a0
; RV32I-NEXT:    bltz a2, .LBB7_2
; RV32I-NEXT:  # %bb.1:
; RV32I-NEXT:    sll a1, a0, a4
; RV32I-NEXT:    j .LBB7_3
; RV32I-NEXT:  .LBB7_2:
; RV32I-NEXT:    sll a1, a1, a3
; RV32I-NEXT:    not a4, a4
; RV32I-NEXT:    srli a5, a0, 1
; RV32I-NEXT:    srl a4, a5, a4
; RV32I-NEXT:    or a1, a1, a4
; RV32I-NEXT:  .LBB7_3:
; RV32I-NEXT:    sll a0, a0, a3
; RV32I-NEXT:    srai a2, a2, 31
; RV32I-NEXT:    and a0, a2, a0
; RV32I-NEXT:    ret
;
; RV64I-LABEL: shl_by_masked_complemented_64:
; RV64I:       # %bb.0:
; RV64I-NEXT:    not a1, a0
; RV64I-NEXT:    sll a0, a0, a1
; RV64I-NEXT:    ret
  %a = sub i64 63, %x
  %b = and i64 %a, 63
  %c = shl i64 %x, %b
  ret i64 %c
}

define i64 @lshr_by_masked_complemented_64(i64 %x) {
; RV32I-LABEL: lshr_by_masked_complemented_64:
; RV32I:       # %bb.0:
; RV32I-NEXT:    li a2, 63
; RV32I-NEXT:    sub a2, a2, a0
; RV32I-NEXT:    andi a4, a2, 63
; RV32I-NEXT:    addi a2, a4, -32
; RV32I-NEXT:    not a3, a0
; RV32I-NEXT:    bltz a2, .LBB8_2
; RV32I-NEXT:  # %bb.1:
; RV32I-NEXT:    srl a0, a1, a4
; RV32I-NEXT:    j .LBB8_3
; RV32I-NEXT:  .LBB8_2:
; RV32I-NEXT:    srl a0, a0, a3
; RV32I-NEXT:    not a4, a4
; RV32I-NEXT:    slli a5, a1, 1
; RV32I-NEXT:    sll a4, a5, a4
; RV32I-NEXT:    or a0, a0, a4
; RV32I-NEXT:  .LBB8_3:
; RV32I-NEXT:    srl a1, a1, a3
; RV32I-NEXT:    srai a2, a2, 31
; RV32I-NEXT:    and a1, a2, a1
; RV32I-NEXT:    ret
;
; RV64I-LABEL: lshr_by_masked_complemented_64:
; RV64I:       # %bb.0:
; RV64I-NEXT:    not a1, a0
; RV64I-NEXT:    srl a0, a0, a1
; RV64I-NEXT:    ret
  %a = sub i64 63, %x
  %b = and i64 %a, 63
  %c = lshr i64 %x, %b
  ret i64 %c
}

define i64 @ashr_by_masked_complemented_64(i64 %x) {
; RV32I-LABEL: ashr_by_masked_complemented_64:
; RV32I:       # %bb.0:
; RV32I-NEXT:    li a2, 63
; RV32I-NEXT:    sub a2, a2, a0
; RV32I-NEXT:    andi a3, a2, 63
; RV32I-NEXT:    addi a4, a3, -32
; RV32I-NEXT:    mv a2, a1
; RV32I-NEXT:    bltz a4, .LBB9_2
; RV32I-NEXT:  # %bb.1:
; RV32I-NEXT:    srai a1, a2, 31
; RV32I-NEXT:    sra a0, a2, a3
; RV32I-NEXT:    ret
; RV32I-NEXT:  .LBB9_2:
; RV32I-NEXT:    not a4, a0
; RV32I-NEXT:    sra a1, a2, a4
; RV32I-NEXT:    srl a0, a0, a4
; RV32I-NEXT:    not a3, a3
; RV32I-NEXT:    slli a2, a2, 1
; RV32I-NEXT:    sll a2, a2, a3
; RV32I-NEXT:    or a0, a0, a2
; RV32I-NEXT:    ret
;
; RV64I-LABEL: ashr_by_masked_complemented_64:
; RV64I:       # %bb.0:
; RV64I-NEXT:    not a1, a0
; RV64I-NEXT:    sra a0, a0, a1
; RV64I-NEXT:    ret
  %a = sub i64 63, %x
  %b = and i64 %a, 63
  %c = ashr i64 %x, %b
  ret i64 %c
}