1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv32 -verify-machineinstrs < %s \
3 ; RUN: | FileCheck -check-prefix=RV32I %s
4 ; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s \
5 ; RUN: | FileCheck -check-prefix=RV64I %s
7 @gi = external global i32
9 define i32 @constraint_r(i32 %a) nounwind {
10 ; RV32I-LABEL: constraint_r:
12 ; RV32I-NEXT: lui a1, %hi(gi)
13 ; RV32I-NEXT: lw a1, %lo(gi)(a1)
15 ; RV32I-NEXT: add a0, a0, a1
19 ; RV64I-LABEL: constraint_r:
21 ; RV64I-NEXT: lui a1, %hi(gi)
22 ; RV64I-NEXT: lwu a1, %lo(gi)(a1)
24 ; RV64I-NEXT: add a0, a0, a1
27 %1 = load i32, i32* @gi
28 %2 = tail call i32 asm "add $0, $1, $2", "=r,r,r"(i32 %a, i32 %1)
32 define i32 @constraint_i(i32 %a) nounwind {
33 ; RV32I-LABEL: constraint_i:
36 ; RV32I-NEXT: addi a0, a0, 113
40 ; RV64I-LABEL: constraint_i:
43 ; RV64I-NEXT: addi a0, a0, 113
46 %1 = load i32, i32* @gi
47 %2 = tail call i32 asm "addi $0, $1, $2", "=r,r,i"(i32 %a, i32 113)
51 define void @constraint_m(i32* %a) nounwind {
52 ; RV32I-LABEL: constraint_m:
58 ; RV64I-LABEL: constraint_m:
63 call void asm sideeffect "", "=*m"(i32* %a)
67 define i32 @constraint_m2(i32* %a) nounwind {
68 ; RV32I-LABEL: constraint_m2:
71 ; RV32I-NEXT: lw a0, 0(a0)
75 ; RV64I-LABEL: constraint_m2:
78 ; RV64I-NEXT: lw a0, 0(a0)
81 %1 = tail call i32 asm "lw $0, $1", "=r,*m"(i32* %a) nounwind
85 define void @constraint_I() nounwind {
86 ; RV32I-LABEL: constraint_I:
89 ; RV32I-NEXT: addi a0, a0, 2047
92 ; RV32I-NEXT: addi a0, a0, -2048
96 ; RV64I-LABEL: constraint_I:
99 ; RV64I-NEXT: addi a0, a0, 2047
100 ; RV64I-NEXT: #NO_APP
102 ; RV64I-NEXT: addi a0, a0, -2048
103 ; RV64I-NEXT: #NO_APP
105 tail call void asm sideeffect "addi a0, a0, $0", "I"(i32 2047)
106 tail call void asm sideeffect "addi a0, a0, $0", "I"(i32 -2048)
110 define void @constraint_J() nounwind {
111 ; RV32I-LABEL: constraint_J:
114 ; RV32I-NEXT: addi a0, a0, 0
115 ; RV32I-NEXT: #NO_APP
118 ; RV64I-LABEL: constraint_J:
121 ; RV64I-NEXT: addi a0, a0, 0
122 ; RV64I-NEXT: #NO_APP
124 tail call void asm sideeffect "addi a0, a0, $0", "J"(i32 0)
128 define void @constraint_K() nounwind {
129 ; RV32I-LABEL: constraint_K:
132 ; RV32I-NEXT: csrwi mstatus, 31
133 ; RV32I-NEXT: #NO_APP
135 ; RV32I-NEXT: csrwi mstatus, 0
136 ; RV32I-NEXT: #NO_APP
139 ; RV64I-LABEL: constraint_K:
142 ; RV64I-NEXT: csrwi mstatus, 31
143 ; RV64I-NEXT: #NO_APP
145 ; RV64I-NEXT: csrwi mstatus, 0
146 ; RV64I-NEXT: #NO_APP
148 tail call void asm sideeffect "csrwi mstatus, $0", "K"(i32 31)
149 tail call void asm sideeffect "csrwi mstatus, $0", "K"(i32 0)
153 define void @constraint_A(i8* %a) nounwind {
154 ; RV32I-LABEL: constraint_A:
157 ; RV32I-NEXT: sb s0, 0(a0)
158 ; RV32I-NEXT: #NO_APP
160 ; RV32I-NEXT: lb s1, 0(a0)
161 ; RV32I-NEXT: #NO_APP
164 ; RV64I-LABEL: constraint_A:
167 ; RV64I-NEXT: sb s0, 0(a0)
168 ; RV64I-NEXT: #NO_APP
170 ; RV64I-NEXT: lb s1, 0(a0)
171 ; RV64I-NEXT: #NO_APP
173 tail call void asm sideeffect "sb s0, $0", "*A"(i8* %a)
174 tail call void asm sideeffect "lb s1, $0", "*A"(i8* %a)
178 define i32 @modifier_z_zero(i32 %a) nounwind {
179 ; RV32I-LABEL: modifier_z_zero:
182 ; RV32I-NEXT: add a0, a0, zero
183 ; RV32I-NEXT: #NO_APP
186 ; RV64I-LABEL: modifier_z_zero:
189 ; RV64I-NEXT: add a0, a0, zero
190 ; RV64I-NEXT: #NO_APP
192 %1 = tail call i32 asm "add $0, $1, ${2:z}", "=r,r,r"(i32 %a, i32 0)
196 define i32 @modifier_z_nonzero(i32 %a) nounwind {
197 ; RV32I-LABEL: modifier_z_nonzero:
199 ; RV32I-NEXT: addi a1, zero, 1
201 ; RV32I-NEXT: add a0, a0, a1
202 ; RV32I-NEXT: #NO_APP
205 ; RV64I-LABEL: modifier_z_nonzero:
207 ; RV64I-NEXT: addi a1, zero, 1
209 ; RV64I-NEXT: add a0, a0, a1
210 ; RV64I-NEXT: #NO_APP
212 %1 = tail call i32 asm "add $0, $1, ${2:z}", "=r,r,r"(i32 %a, i32 1)
216 define i32 @modifier_i_imm(i32 %a) nounwind {
217 ; RV32I-LABEL: modifier_i_imm:
220 ; RV32I-NEXT: addi a0, a0, 1
221 ; RV32I-NEXT: #NO_APP
224 ; RV64I-LABEL: modifier_i_imm:
227 ; RV64I-NEXT: addi a0, a0, 1
228 ; RV64I-NEXT: #NO_APP
230 %1 = tail call i32 asm "add${2:i} $0, $1, $2", "=r,r,ri"(i32 %a, i32 1)
234 define i32 @modifier_i_reg(i32 %a, i32 %b) nounwind {
235 ; RV32I-LABEL: modifier_i_reg:
238 ; RV32I-NEXT: add a0, a0, a1
239 ; RV32I-NEXT: #NO_APP
242 ; RV64I-LABEL: modifier_i_reg:
245 ; RV64I-NEXT: add a0, a0, a1
246 ; RV64I-NEXT: #NO_APP
248 %1 = tail call i32 asm "add${2:i} $0, $1, $2", "=r,r,ri"(i32 %a, i32 %b)
252 ; TODO: expend tests for more complex constraints, out of range immediates etc