1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv32 -verify-machineinstrs < %s \
3 ; RUN: | FileCheck %s -check-prefix=RV32I
4 ; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s \
5 ; RUN: | FileCheck %s -check-prefix=RV64I
7 ; These tests are identical to those in alu32.ll but operate on i16. They check
8 ; that legalisation of these non-native types doesn't introduce unnecessary
11 define i16 @addi(i16 %a) nounwind {
14 ; RV32I-NEXT: addi a0, a0, 1
19 ; RV64I-NEXT: addi a0, a0, 1
25 define i16 @slti(i16 %a) nounwind {
28 ; RV32I-NEXT: slli a0, a0, 16
29 ; RV32I-NEXT: srai a0, a0, 16
30 ; RV32I-NEXT: slti a0, a0, 2
35 ; RV64I-NEXT: slli a0, a0, 48
36 ; RV64I-NEXT: srai a0, a0, 48
37 ; RV64I-NEXT: slti a0, a0, 2
39 %1 = icmp slt i16 %a, 2
40 %2 = zext i1 %1 to i16
44 define i16 @sltiu(i16 %a) nounwind {
47 ; RV32I-NEXT: slli a0, a0, 16
48 ; RV32I-NEXT: srli a0, a0, 16
49 ; RV32I-NEXT: sltiu a0, a0, 3
54 ; RV64I-NEXT: slli a0, a0, 48
55 ; RV64I-NEXT: srli a0, a0, 48
56 ; RV64I-NEXT: sltiu a0, a0, 3
58 %1 = icmp ult i16 %a, 3
59 %2 = zext i1 %1 to i16
63 ; Make sure we avoid an AND, if the input of an unsigned compare is known
64 ; to be sign extended. This can occur due to InstCombine canonicalizing
65 ; x s>= 0 && x s< 10 to x u< 10.
66 define i16 @sltiu_signext(i16 signext %a) nounwind {
67 ; RV32I-LABEL: sltiu_signext:
69 ; RV32I-NEXT: sltiu a0, a0, 10
72 ; RV64I-LABEL: sltiu_signext:
74 ; RV64I-NEXT: sltiu a0, a0, 10
76 %1 = icmp ult i16 %a, 10
77 %2 = zext i1 %1 to i16
81 define i16 @xori(i16 %a) nounwind {
84 ; RV32I-NEXT: xori a0, a0, 4
89 ; RV64I-NEXT: xori a0, a0, 4
95 define i16 @ori(i16 %a) nounwind {
98 ; RV32I-NEXT: ori a0, a0, 5
103 ; RV64I-NEXT: ori a0, a0, 5
109 define i16 @andi(i16 %a) nounwind {
112 ; RV32I-NEXT: andi a0, a0, 6
117 ; RV64I-NEXT: andi a0, a0, 6
123 define i16 @slli(i16 %a) nounwind {
126 ; RV32I-NEXT: slli a0, a0, 7
131 ; RV64I-NEXT: slli a0, a0, 7
137 define i16 @srli(i16 %a) nounwind {
140 ; RV32I-NEXT: slli a0, a0, 16
141 ; RV32I-NEXT: srli a0, a0, 22
146 ; RV64I-NEXT: slli a0, a0, 48
147 ; RV64I-NEXT: srli a0, a0, 54
153 define i16 @srai(i16 %a) nounwind {
156 ; RV32I-NEXT: slli a0, a0, 16
157 ; RV32I-NEXT: srai a0, a0, 25
162 ; RV64I-NEXT: slli a0, a0, 48
163 ; RV64I-NEXT: srai a0, a0, 57
170 define i16 @add(i16 %a, i16 %b) nounwind {
173 ; RV32I-NEXT: add a0, a0, a1
178 ; RV64I-NEXT: add a0, a0, a1
184 define i16 @sub(i16 %a, i16 %b) nounwind {
187 ; RV32I-NEXT: sub a0, a0, a1
192 ; RV64I-NEXT: sub a0, a0, a1
198 define i16 @sll(i16 %a, i16 %b) nounwind {
201 ; RV32I-NEXT: sll a0, a0, a1
206 ; RV64I-NEXT: sll a0, a0, a1
212 ; Test the pattern we get from C integer promotion.
213 define void @sll_ext(i16 %a, i32 signext %b, ptr %p) nounwind {
214 ; RV32I-LABEL: sll_ext:
216 ; RV32I-NEXT: sll a0, a0, a1
217 ; RV32I-NEXT: sh a0, 0(a2)
220 ; RV64I-LABEL: sll_ext:
222 ; RV64I-NEXT: sllw a0, a0, a1
223 ; RV64I-NEXT: sh a0, 0(a2)
225 %1 = zext i16 %a to i32
227 %3 = trunc i32 %2 to i16
232 ; Test the pattern we get from C integer promotion. This time with poison
234 define void @sll_ext_drop_poison(i16 %a, i32 signext %b, ptr %p) nounwind {
235 ; RV32I-LABEL: sll_ext_drop_poison:
237 ; RV32I-NEXT: sll a0, a0, a1
238 ; RV32I-NEXT: sh a0, 0(a2)
241 ; RV64I-LABEL: sll_ext_drop_poison:
243 ; RV64I-NEXT: sllw a0, a0, a1
244 ; RV64I-NEXT: sh a0, 0(a2)
246 %1 = zext i16 %a to i32
247 %2 = shl nuw nsw i32 %1, %b
248 %3 = trunc i32 %2 to i16
253 define i16 @slt(i16 %a, i16 %b) nounwind {
256 ; RV32I-NEXT: slli a1, a1, 16
257 ; RV32I-NEXT: srai a1, a1, 16
258 ; RV32I-NEXT: slli a0, a0, 16
259 ; RV32I-NEXT: srai a0, a0, 16
260 ; RV32I-NEXT: slt a0, a0, a1
265 ; RV64I-NEXT: slli a1, a1, 48
266 ; RV64I-NEXT: srai a1, a1, 48
267 ; RV64I-NEXT: slli a0, a0, 48
268 ; RV64I-NEXT: srai a0, a0, 48
269 ; RV64I-NEXT: slt a0, a0, a1
271 %1 = icmp slt i16 %a, %b
272 %2 = zext i1 %1 to i16
276 define i16 @sltu(i16 %a, i16 %b) nounwind {
279 ; RV32I-NEXT: lui a2, 16
280 ; RV32I-NEXT: addi a2, a2, -1
281 ; RV32I-NEXT: and a1, a1, a2
282 ; RV32I-NEXT: and a0, a0, a2
283 ; RV32I-NEXT: sltu a0, a0, a1
288 ; RV64I-NEXT: lui a2, 16
289 ; RV64I-NEXT: addiw a2, a2, -1
290 ; RV64I-NEXT: and a1, a1, a2
291 ; RV64I-NEXT: and a0, a0, a2
292 ; RV64I-NEXT: sltu a0, a0, a1
294 %1 = icmp ult i16 %a, %b
295 %2 = zext i1 %1 to i16
299 define i16 @xor(i16 %a, i16 %b) nounwind {
302 ; RV32I-NEXT: xor a0, a0, a1
307 ; RV64I-NEXT: xor a0, a0, a1
313 define i16 @srl(i16 %a, i16 %b) nounwind {
316 ; RV32I-NEXT: slli a0, a0, 16
317 ; RV32I-NEXT: srli a0, a0, 16
318 ; RV32I-NEXT: srl a0, a0, a1
323 ; RV64I-NEXT: slli a0, a0, 48
324 ; RV64I-NEXT: srli a0, a0, 48
325 ; RV64I-NEXT: srl a0, a0, a1
331 define i16 @sra(i16 %a, i16 %b) nounwind {
334 ; RV32I-NEXT: slli a0, a0, 16
335 ; RV32I-NEXT: srai a0, a0, 16
336 ; RV32I-NEXT: sra a0, a0, a1
341 ; RV64I-NEXT: slli a0, a0, 48
342 ; RV64I-NEXT: srai a0, a0, 48
343 ; RV64I-NEXT: sra a0, a0, a1
349 define i16 @or(i16 %a, i16 %b) nounwind {
352 ; RV32I-NEXT: or a0, a0, a1
357 ; RV64I-NEXT: or a0, a0, a1
363 define i16 @and(i16 %a, i16 %b) nounwind {
366 ; RV32I-NEXT: and a0, a0, a1
371 ; RV64I-NEXT: and a0, a0, a1