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 define i16 @slt(i16 %a, i16 %b) nounwind {
215 ; RV32I-NEXT: slli a1, a1, 16
216 ; RV32I-NEXT: srai a1, a1, 16
217 ; RV32I-NEXT: slli a0, a0, 16
218 ; RV32I-NEXT: srai a0, a0, 16
219 ; RV32I-NEXT: slt a0, a0, a1
224 ; RV64I-NEXT: slli a1, a1, 48
225 ; RV64I-NEXT: srai a1, a1, 48
226 ; RV64I-NEXT: slli a0, a0, 48
227 ; RV64I-NEXT: srai a0, a0, 48
228 ; RV64I-NEXT: slt a0, a0, a1
230 %1 = icmp slt i16 %a, %b
231 %2 = zext i1 %1 to i16
235 define i16 @sltu(i16 %a, i16 %b) nounwind {
238 ; RV32I-NEXT: lui a2, 16
239 ; RV32I-NEXT: addi a2, a2, -1
240 ; RV32I-NEXT: and a1, a1, a2
241 ; RV32I-NEXT: and a0, a0, a2
242 ; RV32I-NEXT: sltu a0, a0, a1
247 ; RV64I-NEXT: lui a2, 16
248 ; RV64I-NEXT: addiw a2, a2, -1
249 ; RV64I-NEXT: and a1, a1, a2
250 ; RV64I-NEXT: and a0, a0, a2
251 ; RV64I-NEXT: sltu a0, a0, a1
253 %1 = icmp ult i16 %a, %b
254 %2 = zext i1 %1 to i16
258 define i16 @xor(i16 %a, i16 %b) nounwind {
261 ; RV32I-NEXT: xor a0, a0, a1
266 ; RV64I-NEXT: xor a0, a0, a1
272 define i16 @srl(i16 %a, i16 %b) nounwind {
275 ; RV32I-NEXT: slli a0, a0, 16
276 ; RV32I-NEXT: srli a0, a0, 16
277 ; RV32I-NEXT: srl a0, a0, a1
282 ; RV64I-NEXT: slli a0, a0, 48
283 ; RV64I-NEXT: srli a0, a0, 48
284 ; RV64I-NEXT: srl a0, a0, a1
290 define i16 @sra(i16 %a, i16 %b) nounwind {
293 ; RV32I-NEXT: slli a0, a0, 16
294 ; RV32I-NEXT: srai a0, a0, 16
295 ; RV32I-NEXT: sra a0, a0, a1
300 ; RV64I-NEXT: slli a0, a0, 48
301 ; RV64I-NEXT: srai a0, a0, 48
302 ; RV64I-NEXT: sra a0, a0, a1
308 define i16 @or(i16 %a, i16 %b) nounwind {
311 ; RV32I-NEXT: or a0, a0, a1
316 ; RV64I-NEXT: or a0, a0, a1
322 define i16 @and(i16 %a, i16 %b) nounwind {
325 ; RV32I-NEXT: and a0, a0, a1
330 ; RV64I-NEXT: and a0, a0, a1