xref: /llvm-project/llvm/test/CodeGen/CSKY/inline-asm.ll (revision 423ac3d9ee82ff48da91b35ec80497089bc55b9e)
1a190fcdfSZi Xuan Wu; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2a190fcdfSZi Xuan Wu; RUN: llc -mtriple=csky -verify-machineinstrs -csky-no-aliases -no-integrated-as < %s \
3a190fcdfSZi Xuan Wu; RUN:   | FileCheck -check-prefix=CSKY %s
4a190fcdfSZi Xuan Wu
5a190fcdfSZi Xuan Wu@gi = external global i32
6a190fcdfSZi Xuan Wu@mi = external global i64
7a190fcdfSZi Xuan Wu
8a190fcdfSZi Xuan Wudefine i32 @constraint_r(i32 %a) nounwind {
9a190fcdfSZi Xuan Wu; CSKY-LABEL: constraint_r:
10a190fcdfSZi Xuan Wu; CSKY:       # %bb.0:
11a190fcdfSZi Xuan Wu; CSKY-NEXT:    subi16 sp, sp, 4
12a190fcdfSZi Xuan Wu; CSKY-NEXT:    lrw32 a1, [.LCPI0_0]
13a190fcdfSZi Xuan Wu; CSKY-NEXT:    ld16.w a1, (a1, 0)
14a190fcdfSZi Xuan Wu; CSKY-NEXT:    #APP
15a190fcdfSZi Xuan Wu; CSKY-NEXT:    add a0, a0, a1
16a190fcdfSZi Xuan Wu; CSKY-NEXT:    #NO_APP
17a190fcdfSZi Xuan Wu; CSKY-NEXT:    addi16 sp, sp, 4
18a190fcdfSZi Xuan Wu; CSKY-NEXT:    rts16
19a190fcdfSZi Xuan Wu; CSKY-NEXT:    .p2align 1
20a190fcdfSZi Xuan Wu; CSKY-NEXT:  # %bb.1:
21a190fcdfSZi Xuan Wu; CSKY-NEXT:    .p2align 2
22a190fcdfSZi Xuan Wu; CSKY-NEXT:  .LCPI0_0:
23a190fcdfSZi Xuan Wu; CSKY-NEXT:    .long gi
24*423ac3d9SFangrui Song  %1 = load i32, ptr @gi
25a190fcdfSZi Xuan Wu  %2 = tail call i32 asm "add $0, $1, $2", "=r,r,r"(i32 %a, i32 %1)
26a190fcdfSZi Xuan Wu  ret i32 %2
27a190fcdfSZi Xuan Wu}
28a190fcdfSZi Xuan Wu
29a190fcdfSZi Xuan Wudefine i64 @constraint_r_i64(i32 %a) nounwind {
30a190fcdfSZi Xuan Wu; CSKY-LABEL: constraint_r_i64:
31a190fcdfSZi Xuan Wu; CSKY:       # %bb.0:
32a190fcdfSZi Xuan Wu; CSKY-NEXT:    subi16 sp, sp, 4
33a190fcdfSZi Xuan Wu; CSKY-NEXT:    lrw32 a3, [.LCPI1_0]
34a190fcdfSZi Xuan Wu; CSKY-NEXT:    ld16.w a1, (a3, 0)
35a190fcdfSZi Xuan Wu; CSKY-NEXT:    ld16.w a2, (a3, 4)
36a190fcdfSZi Xuan Wu; CSKY-NEXT:    #APP
37a190fcdfSZi Xuan Wu; CSKY-NEXT:    mula.s32 a1, a0, a0
38a190fcdfSZi Xuan Wu; CSKY-NEXT:    #NO_APP
39a190fcdfSZi Xuan Wu; CSKY-NEXT:    mov16 a0, a1
40a190fcdfSZi Xuan Wu; CSKY-NEXT:    mov16 a1, a2
41a190fcdfSZi Xuan Wu; CSKY-NEXT:    addi16 sp, sp, 4
42a190fcdfSZi Xuan Wu; CSKY-NEXT:    rts16
43a190fcdfSZi Xuan Wu; CSKY-NEXT:    .p2align 1
44a190fcdfSZi Xuan Wu; CSKY-NEXT:  # %bb.1:
45a190fcdfSZi Xuan Wu; CSKY-NEXT:    .p2align 2
46a190fcdfSZi Xuan Wu; CSKY-NEXT:  .LCPI1_0:
47a190fcdfSZi Xuan Wu; CSKY-NEXT:    .long mi
48*423ac3d9SFangrui Song  %1 = load i64, ptr @mi
49a190fcdfSZi Xuan Wu  %2 = call i64 asm "mula.s32 $0, $1, $2", "=r,r,r,0"(i32 %a, i32 %a, i64 %1)
50a190fcdfSZi Xuan Wu  ret i64 %2
51a190fcdfSZi Xuan Wu}
52a190fcdfSZi Xuan Wu
53a190fcdfSZi Xuan Wudefine i32 @constraint_a(i32 %a) nounwind {
54a190fcdfSZi Xuan Wu; CSKY-LABEL: constraint_a:
55a190fcdfSZi Xuan Wu; CSKY:       # %bb.0:
56a190fcdfSZi Xuan Wu; CSKY-NEXT:    subi16 sp, sp, 4
57a190fcdfSZi Xuan Wu; CSKY-NEXT:    lrw32 a1, [.LCPI2_0]
58a190fcdfSZi Xuan Wu; CSKY-NEXT:    ld16.w a1, (a1, 0)
59a190fcdfSZi Xuan Wu; CSKY-NEXT:    #APP
60a190fcdfSZi Xuan Wu; CSKY-NEXT:    add a0, a0, a1
61a190fcdfSZi Xuan Wu; CSKY-NEXT:    #NO_APP
62a190fcdfSZi Xuan Wu; CSKY-NEXT:    addi16 sp, sp, 4
63a190fcdfSZi Xuan Wu; CSKY-NEXT:    rts16
64a190fcdfSZi Xuan Wu; CSKY-NEXT:    .p2align 1
65a190fcdfSZi Xuan Wu; CSKY-NEXT:  # %bb.1:
66a190fcdfSZi Xuan Wu; CSKY-NEXT:    .p2align 2
67a190fcdfSZi Xuan Wu; CSKY-NEXT:  .LCPI2_0:
68a190fcdfSZi Xuan Wu; CSKY-NEXT:    .long gi
69*423ac3d9SFangrui Song  %1 = load i32, ptr @gi
70a190fcdfSZi Xuan Wu  %2 = tail call i32 asm "add $0, $1, $2", "=a,a,a"(i32 %a, i32 %1)
71a190fcdfSZi Xuan Wu  ret i32 %2
72a190fcdfSZi Xuan Wu}
73a190fcdfSZi Xuan Wu
74a190fcdfSZi Xuan Wudefine i32 @constraint_b(i32 %a) nounwind {
75a190fcdfSZi Xuan Wu; CSKY-LABEL: constraint_b:
76a190fcdfSZi Xuan Wu; CSKY:       # %bb.0:
77a190fcdfSZi Xuan Wu; CSKY-NEXT:    subi16 sp, sp, 4
78a190fcdfSZi Xuan Wu; CSKY-NEXT:    lrw32 a1, [.LCPI3_0]
79a190fcdfSZi Xuan Wu; CSKY-NEXT:    ld16.w a1, (a1, 0)
80a190fcdfSZi Xuan Wu; CSKY-NEXT:    #APP
81a190fcdfSZi Xuan Wu; CSKY-NEXT:    add a0, a0, a1
82a190fcdfSZi Xuan Wu; CSKY-NEXT:    #NO_APP
83a190fcdfSZi Xuan Wu; CSKY-NEXT:    addi16 sp, sp, 4
84a190fcdfSZi Xuan Wu; CSKY-NEXT:    rts16
85a190fcdfSZi Xuan Wu; CSKY-NEXT:    .p2align 1
86a190fcdfSZi Xuan Wu; CSKY-NEXT:  # %bb.1:
87a190fcdfSZi Xuan Wu; CSKY-NEXT:    .p2align 2
88a190fcdfSZi Xuan Wu; CSKY-NEXT:  .LCPI3_0:
89a190fcdfSZi Xuan Wu; CSKY-NEXT:    .long gi
90*423ac3d9SFangrui Song  %1 = load i32, ptr @gi
91a190fcdfSZi Xuan Wu  %2 = tail call i32 asm "add $0, $1, $2", "=b,b,b"(i32 %a, i32 %1)
92a190fcdfSZi Xuan Wu  ret i32 %2
93a190fcdfSZi Xuan Wu}
94a190fcdfSZi Xuan Wu
95a190fcdfSZi Xuan Wudefine i32 @constraint_z(i32 %a) nounwind {
96a190fcdfSZi Xuan Wu; CSKY-LABEL: constraint_z:
97a190fcdfSZi Xuan Wu; CSKY:       # %bb.0:
98a190fcdfSZi Xuan Wu; CSKY-NEXT:    subi16 sp, sp, 4
99a190fcdfSZi Xuan Wu; CSKY-NEXT:    mov16 sp, a0
100a190fcdfSZi Xuan Wu; CSKY-NEXT:    lrw32 a0, [.LCPI4_0]
101a190fcdfSZi Xuan Wu; CSKY-NEXT:    ld16.w a0, (a0, 0)
102a190fcdfSZi Xuan Wu; CSKY-NEXT:    #APP
103a190fcdfSZi Xuan Wu; CSKY-NEXT:    add a0, sp, a0
104a190fcdfSZi Xuan Wu; CSKY-NEXT:    #NO_APP
105a190fcdfSZi Xuan Wu; CSKY-NEXT:    addi16 sp, sp, 4
106a190fcdfSZi Xuan Wu; CSKY-NEXT:    rts16
107a190fcdfSZi Xuan Wu; CSKY-NEXT:    .p2align 1
108a190fcdfSZi Xuan Wu; CSKY-NEXT:  # %bb.1:
109a190fcdfSZi Xuan Wu; CSKY-NEXT:    .p2align 2
110a190fcdfSZi Xuan Wu; CSKY-NEXT:  .LCPI4_0:
111a190fcdfSZi Xuan Wu; CSKY-NEXT:    .long gi
112*423ac3d9SFangrui Song  %1 = load i32, ptr @gi
113a190fcdfSZi Xuan Wu  %2 = tail call i32 asm "add $0, $1, $2", "=r,z,r"(i32 %a, i32 %1)
114a190fcdfSZi Xuan Wu  ret i32 %2
115a190fcdfSZi Xuan Wu}
116a190fcdfSZi Xuan Wu
117a190fcdfSZi Xuan Wudefine i32 @constraint_c(i32 %a, i32 %b) nounwind {
118a190fcdfSZi Xuan Wu; CSKY-LABEL: constraint_c:
119a190fcdfSZi Xuan Wu; CSKY:       # %bb.0:
120a190fcdfSZi Xuan Wu; CSKY-NEXT:    subi16 sp, sp, 4
121a190fcdfSZi Xuan Wu; CSKY-NEXT:    lrw32 a1, [.LCPI5_0]
122a190fcdfSZi Xuan Wu; CSKY-NEXT:    ld16.w a1, (a1, 0)
123a190fcdfSZi Xuan Wu; CSKY-NEXT:    #APP
124a190fcdfSZi Xuan Wu; CSKY-NEXT:    addc a0, a0, a1
125a190fcdfSZi Xuan Wu; CSKY-NEXT:    #NO_APP
126a190fcdfSZi Xuan Wu; CSKY-NEXT:    addi16 sp, sp, 4
127a190fcdfSZi Xuan Wu; CSKY-NEXT:    rts16
128a190fcdfSZi Xuan Wu; CSKY-NEXT:    .p2align 1
129a190fcdfSZi Xuan Wu; CSKY-NEXT:  # %bb.1:
130a190fcdfSZi Xuan Wu; CSKY-NEXT:    .p2align 2
131a190fcdfSZi Xuan Wu; CSKY-NEXT:  .LCPI5_0:
132a190fcdfSZi Xuan Wu; CSKY-NEXT:    .long gi
133*423ac3d9SFangrui Song  %1 = load i32, ptr @gi
134a190fcdfSZi Xuan Wu  %2 = tail call i32 asm "addc $0, $1, $2", "=r,r,r,~{c}"(i32 %a, i32 %1)
135a190fcdfSZi Xuan Wu  ret i32 %2
136a190fcdfSZi Xuan Wu}
137a190fcdfSZi Xuan Wu
138a190fcdfSZi Xuan Wudefine i32 @constraint_i(i32 %a) nounwind {
139a190fcdfSZi Xuan Wu; CSKY-LABEL: constraint_i:
140a190fcdfSZi Xuan Wu; CSKY:       # %bb.0:
141a190fcdfSZi Xuan Wu; CSKY-NEXT:    subi16 sp, sp, 4
142a190fcdfSZi Xuan Wu; CSKY-NEXT:    #APP
143a190fcdfSZi Xuan Wu; CSKY-NEXT:    addi a0, a0, 113
144a190fcdfSZi Xuan Wu; CSKY-NEXT:    #NO_APP
145a190fcdfSZi Xuan Wu; CSKY-NEXT:    addi16 sp, sp, 4
146a190fcdfSZi Xuan Wu; CSKY-NEXT:    rts16
147a190fcdfSZi Xuan Wu
148*423ac3d9SFangrui Song  %1 = load i32, ptr @gi
149a190fcdfSZi Xuan Wu  %2 = tail call i32 asm "addi $0, $1, $2", "=r,r,i"(i32 %a, i32 113)
150a190fcdfSZi Xuan Wu  ret i32 %2
151a190fcdfSZi Xuan Wu}
152a190fcdfSZi Xuan Wu
153*423ac3d9SFangrui Songdefine void @constraint_m(ptr %a) nounwind {
154a190fcdfSZi Xuan Wu; CSKY-LABEL: constraint_m:
155a190fcdfSZi Xuan Wu; CSKY:       # %bb.0:
156a190fcdfSZi Xuan Wu; CSKY-NEXT:    subi16 sp, sp, 4
157a190fcdfSZi Xuan Wu; CSKY-NEXT:    #APP
158a190fcdfSZi Xuan Wu; CSKY-NEXT:    #NO_APP
159a190fcdfSZi Xuan Wu; CSKY-NEXT:    addi16 sp, sp, 4
160a190fcdfSZi Xuan Wu; CSKY-NEXT:    rts16
161a190fcdfSZi Xuan Wu
162*423ac3d9SFangrui Song  call void asm sideeffect "", "=*m"(ptr elementtype(i32) %a)
163a190fcdfSZi Xuan Wu  ret void
164a190fcdfSZi Xuan Wu}
165a190fcdfSZi Xuan Wu
166*423ac3d9SFangrui Songdefine i32 @constraint_m2(ptr %a) nounwind {
167a190fcdfSZi Xuan Wu; CSKY-LABEL: constraint_m2:
168a190fcdfSZi Xuan Wu; CSKY:       # %bb.0:
169a190fcdfSZi Xuan Wu; CSKY-NEXT:    subi16 sp, sp, 4
170a190fcdfSZi Xuan Wu; CSKY-NEXT:    #APP
171a190fcdfSZi Xuan Wu; CSKY-NEXT:    ld.w a0, (a0, 0)
172a190fcdfSZi Xuan Wu; CSKY-NEXT:    #NO_APP
173a190fcdfSZi Xuan Wu; CSKY-NEXT:    addi16 sp, sp, 4
174a190fcdfSZi Xuan Wu; CSKY-NEXT:    rts16
175a190fcdfSZi Xuan Wu
176*423ac3d9SFangrui Song  %1 = tail call i32 asm "ld.w $0, $1", "=r,*m"(ptr elementtype(i32) %a)
177a190fcdfSZi Xuan Wu  ret i32 %1
178a190fcdfSZi Xuan Wu}
179a190fcdfSZi Xuan Wu
180a190fcdfSZi Xuan Wudefine i32 @modifier_i_imm(i32 %a) nounwind {
181a190fcdfSZi Xuan Wu; CSKY-LABEL: modifier_i_imm:
182a190fcdfSZi Xuan Wu; CSKY:       # %bb.0:
183a190fcdfSZi Xuan Wu; CSKY-NEXT:    subi16 sp, sp, 4
184a190fcdfSZi Xuan Wu; CSKY-NEXT:    #APP
185a190fcdfSZi Xuan Wu; CSKY-NEXT:    addi a0, a0, 1
186a190fcdfSZi Xuan Wu; CSKY-NEXT:    #NO_APP
187a190fcdfSZi Xuan Wu; CSKY-NEXT:    addi16 sp, sp, 4
188a190fcdfSZi Xuan Wu; CSKY-NEXT:    rts16
189a190fcdfSZi Xuan Wu  %1 = tail call i32 asm "addi $0, $1, $2", "=r,r,ri"(i32 %a, i32 1)
190a190fcdfSZi Xuan Wu  ret i32 %1
191a190fcdfSZi Xuan Wu}
192a190fcdfSZi Xuan Wu
193a190fcdfSZi Xuan Wudefine void @operand_global() nounwind {
194a190fcdfSZi Xuan Wu; CSKY-LABEL: operand_global:
195a190fcdfSZi Xuan Wu; CSKY:       # %bb.0:
196a190fcdfSZi Xuan Wu; CSKY-NEXT:    subi16 sp, sp, 4
197a190fcdfSZi Xuan Wu; CSKY-NEXT:    #APP
198a190fcdfSZi Xuan Wu; CSKY-NEXT:    .4byte gi
199a190fcdfSZi Xuan Wu; CSKY-NEXT:    #NO_APP
200a190fcdfSZi Xuan Wu; CSKY-NEXT:    addi16 sp, sp, 4
201a190fcdfSZi Xuan Wu; CSKY-NEXT:    rts16
202a190fcdfSZi Xuan Wu
203*423ac3d9SFangrui Song  tail call void asm sideeffect ".4byte $0", "i"(ptr @gi)
204a190fcdfSZi Xuan Wu  ret void
205a190fcdfSZi Xuan Wu}
206a190fcdfSZi Xuan Wu
207a190fcdfSZi Xuan Wudefine void @operand_block_address() nounwind {
208a190fcdfSZi Xuan Wu; CSKY-LABEL: operand_block_address:
209a190fcdfSZi Xuan Wu; CSKY:       # %bb.0:
210a190fcdfSZi Xuan Wu; CSKY-NEXT:    subi16 sp, sp, 4
211a190fcdfSZi Xuan Wu; CSKY-NEXT:    #APP
212a190fcdfSZi Xuan Wu; CSKY-NEXT:    br32 .Ltmp0
213a190fcdfSZi Xuan Wu; CSKY-NEXT:    #NO_APP
214a190fcdfSZi Xuan Wu; CSKY-NEXT:  .Ltmp0: # Block address taken
215a190fcdfSZi Xuan Wu; CSKY-NEXT:  # %bb.1: # %bb
216a190fcdfSZi Xuan Wu; CSKY-NEXT:    addi16 sp, sp, 4
217a190fcdfSZi Xuan Wu; CSKY-NEXT:    rts16
218a190fcdfSZi Xuan Wu
219*423ac3d9SFangrui Song  call void asm sideeffect "br32 $0", "i"(ptr blockaddress(@operand_block_address, %bb))
220a190fcdfSZi Xuan Wu  br label %bb
221a190fcdfSZi Xuan Wubb:
222a190fcdfSZi Xuan Wu  ret void
223a190fcdfSZi Xuan Wu}
224a190fcdfSZi Xuan Wu
225a190fcdfSZi Xuan Wu; TODO: expand tests for more complex constraints, out of range immediates etc
226