1 ; NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2 ; RUN: llc -mtriple=riscv32 -global-isel -stop-after=irtranslator -verify-machineinstrs < %s \
3 ; RUN: | FileCheck -check-prefix=RV32I %s
4 ; RUN: llc -mtriple=riscv64 -global-isel -stop-after=irtranslator -verify-machineinstrs < %s \
5 ; RUN: | FileCheck -check-prefix=RV64I %s
7 declare void @void_noargs()
9 define void @test_call_void_noargs() {
11 ; RV32I-LABEL: name: test_call_void_noargs
13 ; RV32I-NEXT: PseudoCALL target-flags(riscv-call) @void_noargs, implicit-def $x1
14 ; RV32I-NEXT: PseudoRET
15 ; RV64I-LABEL: name: test_call_void_noargs
17 ; RV64I-NEXT: PseudoCALL target-flags(riscv-call) @void_noargs, implicit-def $x1
18 ; RV64I-NEXT: PseudoRET
20 call void @void_noargs()
24 declare void @void_args_i8(i8, i8)
26 define void @test_call_void_args_i8() {
28 ; RV32I-LABEL: name: test_call_void_args_i8
30 ; RV32I-NEXT: [[C:%[0-9]+]]:_(s8) = G_CONSTANT i8 0
31 ; RV32I-NEXT: [[C1:%[0-9]+]]:_(s8) = G_CONSTANT i8 1
32 ; RV32I-NEXT: [[ANYEXT:%[0-9]+]]:_(s32) = G_ANYEXT [[C]](s8)
33 ; RV32I-NEXT: [[ANYEXT1:%[0-9]+]]:_(s32) = G_ANYEXT [[C1]](s8)
34 ; RV32I-NEXT: $x10 = COPY [[ANYEXT]](s32)
35 ; RV32I-NEXT: $x11 = COPY [[ANYEXT1]](s32)
36 ; RV32I-NEXT: PseudoCALL target-flags(riscv-call) @void_args_i8, implicit-def $x1, implicit $x10, implicit $x11
37 ; RV32I-NEXT: PseudoRET
38 ; RV64I-LABEL: name: test_call_void_args_i8
40 ; RV64I-NEXT: [[C:%[0-9]+]]:_(s8) = G_CONSTANT i8 0
41 ; RV64I-NEXT: [[C1:%[0-9]+]]:_(s8) = G_CONSTANT i8 1
42 ; RV64I-NEXT: [[ANYEXT:%[0-9]+]]:_(s64) = G_ANYEXT [[C]](s8)
43 ; RV64I-NEXT: [[ANYEXT1:%[0-9]+]]:_(s64) = G_ANYEXT [[C1]](s8)
44 ; RV64I-NEXT: $x10 = COPY [[ANYEXT]](s64)
45 ; RV64I-NEXT: $x11 = COPY [[ANYEXT1]](s64)
46 ; RV64I-NEXT: PseudoCALL target-flags(riscv-call) @void_args_i8, implicit-def $x1, implicit $x10, implicit $x11
47 ; RV64I-NEXT: PseudoRET
49 call void @void_args_i8(i8 0, i8 1)
53 declare void @void_args_i8_zext(i8 zeroext, i8 zeroext)
55 define void @test_call_void_args_i8_zext() {
57 ; RV32I-LABEL: name: test_call_void_args_i8_zext
59 ; RV32I-NEXT: [[C:%[0-9]+]]:_(s8) = G_CONSTANT i8 0
60 ; RV32I-NEXT: [[C1:%[0-9]+]]:_(s8) = G_CONSTANT i8 1
61 ; RV32I-NEXT: [[ZEXT:%[0-9]+]]:_(s32) = G_ZEXT [[C]](s8)
62 ; RV32I-NEXT: [[ZEXT1:%[0-9]+]]:_(s32) = G_ZEXT [[C1]](s8)
63 ; RV32I-NEXT: $x10 = COPY [[ZEXT]](s32)
64 ; RV32I-NEXT: $x11 = COPY [[ZEXT1]](s32)
65 ; RV32I-NEXT: PseudoCALL target-flags(riscv-call) @void_args_i8_zext, implicit-def $x1, implicit $x10, implicit $x11
66 ; RV32I-NEXT: PseudoRET
67 ; RV64I-LABEL: name: test_call_void_args_i8_zext
69 ; RV64I-NEXT: [[C:%[0-9]+]]:_(s8) = G_CONSTANT i8 0
70 ; RV64I-NEXT: [[C1:%[0-9]+]]:_(s8) = G_CONSTANT i8 1
71 ; RV64I-NEXT: [[ZEXT:%[0-9]+]]:_(s64) = G_ZEXT [[C]](s8)
72 ; RV64I-NEXT: [[ZEXT1:%[0-9]+]]:_(s64) = G_ZEXT [[C1]](s8)
73 ; RV64I-NEXT: $x10 = COPY [[ZEXT]](s64)
74 ; RV64I-NEXT: $x11 = COPY [[ZEXT1]](s64)
75 ; RV64I-NEXT: PseudoCALL target-flags(riscv-call) @void_args_i8_zext, implicit-def $x1, implicit $x10, implicit $x11
76 ; RV64I-NEXT: PseudoRET
78 call void @void_args_i8_zext(i8 zeroext 0, i8 zeroext 1)
82 declare void @void_args_i16_sext(i16 signext, i16 signext)
84 define void @test_call_void_args_i16_sext() {
86 ; RV32I-LABEL: name: test_call_void_args_i16_sext
88 ; RV32I-NEXT: [[C:%[0-9]+]]:_(s16) = G_CONSTANT i16 0
89 ; RV32I-NEXT: [[C1:%[0-9]+]]:_(s16) = G_CONSTANT i16 1
90 ; RV32I-NEXT: [[SEXT:%[0-9]+]]:_(s32) = G_SEXT [[C]](s16)
91 ; RV32I-NEXT: [[SEXT1:%[0-9]+]]:_(s32) = G_SEXT [[C1]](s16)
92 ; RV32I-NEXT: $x10 = COPY [[SEXT]](s32)
93 ; RV32I-NEXT: $x11 = COPY [[SEXT1]](s32)
94 ; RV32I-NEXT: PseudoCALL target-flags(riscv-call) @void_args_i16_sext, implicit-def $x1, implicit $x10, implicit $x11
95 ; RV32I-NEXT: PseudoRET
96 ; RV64I-LABEL: name: test_call_void_args_i16_sext
98 ; RV64I-NEXT: [[C:%[0-9]+]]:_(s16) = G_CONSTANT i16 0
99 ; RV64I-NEXT: [[C1:%[0-9]+]]:_(s16) = G_CONSTANT i16 1
100 ; RV64I-NEXT: [[SEXT:%[0-9]+]]:_(s64) = G_SEXT [[C]](s16)
101 ; RV64I-NEXT: [[SEXT1:%[0-9]+]]:_(s64) = G_SEXT [[C1]](s16)
102 ; RV64I-NEXT: $x10 = COPY [[SEXT]](s64)
103 ; RV64I-NEXT: $x11 = COPY [[SEXT1]](s64)
104 ; RV64I-NEXT: PseudoCALL target-flags(riscv-call) @void_args_i16_sext, implicit-def $x1, implicit $x10, implicit $x11
105 ; RV64I-NEXT: PseudoRET
107 call void @void_args_i16_sext(i16 signext 0, i16 signext 1)
111 declare void @void_args_i32(i32, i32)
113 define void @test_call_void_args_i32() {
115 ; RV32I-LABEL: name: test_call_void_args_i32
117 ; RV32I-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
118 ; RV32I-NEXT: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
119 ; RV32I-NEXT: $x10 = COPY [[C]](s32)
120 ; RV32I-NEXT: $x11 = COPY [[C1]](s32)
121 ; RV32I-NEXT: PseudoCALL target-flags(riscv-call) @void_args_i32, implicit-def $x1, implicit $x10, implicit $x11
122 ; RV32I-NEXT: PseudoRET
123 ; RV64I-LABEL: name: test_call_void_args_i32
125 ; RV64I-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
126 ; RV64I-NEXT: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
127 ; RV64I-NEXT: [[ANYEXT:%[0-9]+]]:_(s64) = G_ANYEXT [[C]](s32)
128 ; RV64I-NEXT: [[ANYEXT1:%[0-9]+]]:_(s64) = G_ANYEXT [[C1]](s32)
129 ; RV64I-NEXT: $x10 = COPY [[ANYEXT]](s64)
130 ; RV64I-NEXT: $x11 = COPY [[ANYEXT1]](s64)
131 ; RV64I-NEXT: PseudoCALL target-flags(riscv-call) @void_args_i32, implicit-def $x1, implicit $x10, implicit $x11
132 ; RV64I-NEXT: PseudoRET
134 call void @void_args_i32(i32 0, i32 1)
138 declare void @void_args_i64(i64, i64)
140 define void @test_call_void_args_i64() {
142 ; RV32I-LABEL: name: test_call_void_args_i64
144 ; RV32I-NEXT: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 0
145 ; RV32I-NEXT: [[C1:%[0-9]+]]:_(s64) = G_CONSTANT i64 1
146 ; RV32I-NEXT: [[UV:%[0-9]+]]:_(s32), [[UV1:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[C]](s64)
147 ; RV32I-NEXT: [[UV2:%[0-9]+]]:_(s32), [[UV3:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[C1]](s64)
148 ; RV32I-NEXT: $x10 = COPY [[UV]](s32)
149 ; RV32I-NEXT: $x11 = COPY [[UV1]](s32)
150 ; RV32I-NEXT: $x12 = COPY [[UV2]](s32)
151 ; RV32I-NEXT: $x13 = COPY [[UV3]](s32)
152 ; RV32I-NEXT: PseudoCALL target-flags(riscv-call) @void_args_i64, implicit-def $x1, implicit $x10, implicit $x11, implicit $x12, implicit $x13
153 ; RV32I-NEXT: PseudoRET
154 ; RV64I-LABEL: name: test_call_void_args_i64
156 ; RV64I-NEXT: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 0
157 ; RV64I-NEXT: [[C1:%[0-9]+]]:_(s64) = G_CONSTANT i64 1
158 ; RV64I-NEXT: $x10 = COPY [[C]](s64)
159 ; RV64I-NEXT: $x11 = COPY [[C1]](s64)
160 ; RV64I-NEXT: PseudoCALL target-flags(riscv-call) @void_args_i64, implicit-def $x1, implicit $x10, implicit $x11
161 ; RV64I-NEXT: PseudoRET
163 call void @void_args_i64(i64 0, i64 1)
167 declare i8 @i8_noargs()
169 define void @test_call_i8_noargs() {
171 ; RV32I-LABEL: name: test_call_i8_noargs
173 ; RV32I-NEXT: PseudoCALL target-flags(riscv-call) @i8_noargs, implicit-def $x1, implicit-def $x10
174 ; RV32I-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $x10
175 ; RV32I-NEXT: [[TRUNC:%[0-9]+]]:_(s8) = G_TRUNC [[COPY]](s32)
176 ; RV32I-NEXT: PseudoRET
177 ; RV64I-LABEL: name: test_call_i8_noargs
179 ; RV64I-NEXT: PseudoCALL target-flags(riscv-call) @i8_noargs, implicit-def $x1, implicit-def $x10
180 ; RV64I-NEXT: [[COPY:%[0-9]+]]:_(s64) = COPY $x10
181 ; RV64I-NEXT: [[TRUNC:%[0-9]+]]:_(s8) = G_TRUNC [[COPY]](s64)
182 ; RV64I-NEXT: PseudoRET
184 %a = call i8 @i8_noargs()
188 declare i16 @i16_noargs()
190 define void @test_call_i16_noargs() {
192 ; RV32I-LABEL: name: test_call_i16_noargs
194 ; RV32I-NEXT: PseudoCALL target-flags(riscv-call) @i16_noargs, implicit-def $x1, implicit-def $x10
195 ; RV32I-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $x10
196 ; RV32I-NEXT: [[TRUNC:%[0-9]+]]:_(s16) = G_TRUNC [[COPY]](s32)
197 ; RV32I-NEXT: PseudoRET
198 ; RV64I-LABEL: name: test_call_i16_noargs
200 ; RV64I-NEXT: PseudoCALL target-flags(riscv-call) @i16_noargs, implicit-def $x1, implicit-def $x10
201 ; RV64I-NEXT: [[COPY:%[0-9]+]]:_(s64) = COPY $x10
202 ; RV64I-NEXT: [[TRUNC:%[0-9]+]]:_(s16) = G_TRUNC [[COPY]](s64)
203 ; RV64I-NEXT: PseudoRET
205 %a = call i16 @i16_noargs()
209 declare i32 @i32_noargs()
211 define void @test_call_i32_noargs() {
213 ; RV32I-LABEL: name: test_call_i32_noargs
215 ; RV32I-NEXT: PseudoCALL target-flags(riscv-call) @i32_noargs, implicit-def $x1, implicit-def $x10
216 ; RV32I-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $x10
217 ; RV32I-NEXT: PseudoRET
218 ; RV64I-LABEL: name: test_call_i32_noargs
220 ; RV64I-NEXT: PseudoCALL target-flags(riscv-call) @i32_noargs, implicit-def $x1, implicit-def $x10
221 ; RV64I-NEXT: [[COPY:%[0-9]+]]:_(s64) = COPY $x10
222 ; RV64I-NEXT: [[TRUNC:%[0-9]+]]:_(s32) = G_TRUNC [[COPY]](s64)
223 ; RV64I-NEXT: PseudoRET
225 %a = call i32 @i32_noargs()
229 declare i64 @i64_noargs()
231 define void @test_call_i64_noargs() {
233 ; RV32I-LABEL: name: test_call_i64_noargs
235 ; RV32I-NEXT: PseudoCALL target-flags(riscv-call) @i64_noargs, implicit-def $x1, implicit-def $x10, implicit-def $x11
236 ; RV32I-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $x10
237 ; RV32I-NEXT: [[COPY1:%[0-9]+]]:_(s32) = COPY $x11
238 ; RV32I-NEXT: [[MV:%[0-9]+]]:_(s64) = G_MERGE_VALUES [[COPY]](s32), [[COPY1]](s32)
239 ; RV32I-NEXT: PseudoRET
240 ; RV64I-LABEL: name: test_call_i64_noargs
242 ; RV64I-NEXT: PseudoCALL target-flags(riscv-call) @i64_noargs, implicit-def $x1, implicit-def $x10
243 ; RV64I-NEXT: [[COPY:%[0-9]+]]:_(s64) = COPY $x10
244 ; RV64I-NEXT: PseudoRET
246 %a = call i64 @i64_noargs()
250 declare ptr @ptr_noargs()
252 define void @test_call_ptr_noargs() {
253 ; RV32I-LABEL: name: test_call_ptr_noargs
255 ; RV32I-NEXT: PseudoCALL target-flags(riscv-call) @ptr_noargs, implicit-def $x1, implicit-def $x10
256 ; RV32I-NEXT: [[COPY:%[0-9]+]]:_(p0) = COPY $x10
257 ; RV32I-NEXT: PseudoRET
258 ; RV64I-LABEL: name: test_call_ptr_noargs
260 ; RV64I-NEXT: PseudoCALL target-flags(riscv-call) @ptr_noargs, implicit-def $x1, implicit-def $x10
261 ; RV64I-NEXT: [[COPY:%[0-9]+]]:_(p0) = COPY $x10
262 ; RV64I-NEXT: PseudoRET
264 %a = call ptr @ptr_noargs()
268 declare [2 x i32] @i32x2_noargs()
270 define void @test_call_i32x2_noargs() {
271 ; RV32I-LABEL: name: test_call_i32x2_noargs
273 ; RV32I-NEXT: PseudoCALL target-flags(riscv-call) @i32x2_noargs, implicit-def $x1, implicit-def $x10, implicit-def $x11
274 ; RV32I-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $x10
275 ; RV32I-NEXT: [[COPY1:%[0-9]+]]:_(s32) = COPY $x11
276 ; RV32I-NEXT: PseudoRET
277 ; RV64I-LABEL: name: test_call_i32x2_noargs
279 ; RV64I-NEXT: PseudoCALL target-flags(riscv-call) @i32x2_noargs, implicit-def $x1, implicit-def $x10, implicit-def $x11
280 ; RV64I-NEXT: [[COPY:%[0-9]+]]:_(s64) = COPY $x10
281 ; RV64I-NEXT: [[TRUNC:%[0-9]+]]:_(s32) = G_TRUNC [[COPY]](s64)
282 ; RV64I-NEXT: [[COPY1:%[0-9]+]]:_(s64) = COPY $x11
283 ; RV64I-NEXT: [[TRUNC1:%[0-9]+]]:_(s32) = G_TRUNC [[COPY1]](s64)
284 ; RV64I-NEXT: PseudoRET
286 %a = call [2 x i32] @i32x2_noargs()
290 %struct.Foo = type { i32, i32, i32, i16, i8 }
291 @foo = global %struct.Foo { i32 1, i32 2, i32 3, i16 4, i8 5 }, align 4
293 declare void @void_byval_args(ptr byval(%struct.Foo) %f)
295 define void @test_void_byval_args() {
296 ; RV32I-LABEL: name: test_void_byval_args
298 ; RV32I-NEXT: [[GV:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @foo
299 ; RV32I-NEXT: $x10 = COPY [[GV]](p0)
300 ; RV32I-NEXT: PseudoCALL target-flags(riscv-call) @void_byval_args, implicit-def $x1, implicit $x10
301 ; RV32I-NEXT: PseudoRET
302 ; RV64I-LABEL: name: test_void_byval_args
304 ; RV64I-NEXT: [[GV:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @foo
305 ; RV64I-NEXT: $x10 = COPY [[GV]](p0)
306 ; RV64I-NEXT: PseudoCALL target-flags(riscv-call) @void_byval_args, implicit-def $x1, implicit $x10
307 ; RV64I-NEXT: PseudoRET
309 call void @void_byval_args(ptr byval(%struct.Foo) @foo)
313 declare void @void_sret_args(ptr sret(%struct.Foo) %f)
315 define void @test_void_sret_args() {
316 ; RV32I-LABEL: name: test_void_sret_args
318 ; RV32I-NEXT: [[GV:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @foo
319 ; RV32I-NEXT: $x10 = COPY [[GV]](p0)
320 ; RV32I-NEXT: PseudoCALL target-flags(riscv-call) @void_sret_args, implicit-def $x1, implicit $x10
321 ; RV32I-NEXT: PseudoRET
322 ; RV64I-LABEL: name: test_void_sret_args
324 ; RV64I-NEXT: [[GV:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @foo
325 ; RV64I-NEXT: $x10 = COPY [[GV]](p0)
326 ; RV64I-NEXT: PseudoCALL target-flags(riscv-call) @void_sret_args, implicit-def $x1, implicit $x10
327 ; RV64I-NEXT: PseudoRET
329 call void @void_sret_args(ptr sret(%struct.Foo) @foo)