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 i32 @modifier_z_zero(i32 %a) nounwind {
154 ; RV32I-LABEL: modifier_z_zero:
157 ; RV32I-NEXT: add a0, a0, zero
158 ; RV32I-NEXT: #NO_APP
160 %1 = tail call i32 asm "add $0, $1, ${2:z}", "=r,r,r"(i32 %a, i32 0)
164 define i32 @modifier_z_nonzero(i32 %a) nounwind {
165 ; RV32I-LABEL: modifier_z_nonzero:
167 ; RV32I-NEXT: addi a1, zero, 1
169 ; RV32I-NEXT: add a0, a0, a1
170 ; RV32I-NEXT: #NO_APP
172 %1 = tail call i32 asm "add $0, $1, ${2:z}", "=r,r,r"(i32 %a, i32 1)
176 define i32 @modifier_i_imm(i32 %a) nounwind {
177 ; RV32I-LABEL: modifier_i_imm:
180 ; RV32I-NEXT: addi a0, a0, 1
181 ; RV32I-NEXT: #NO_APP
183 %1 = tail call i32 asm "add${2:i} $0, $1, $2", "=r,r,ri"(i32 %a, i32 1)
187 define i32 @modifier_i_reg(i32 %a, i32 %b) nounwind {
188 ; RV32I-LABEL: modifier_i_reg:
191 ; RV32I-NEXT: add a0, a0, a1
192 ; RV32I-NEXT: #NO_APP
194 %1 = tail call i32 asm "add${2:i} $0, $1, $2", "=r,r,ri"(i32 %a, i32 %b)
198 ; TODO: expend tests for more complex constraints, out of range immediates etc