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
5 declare i32 @external_function(i32)
7 define i32 @test_call_external(i32 %a) nounwind {
8 ; RV32I-LABEL: test_call_external:
10 ; RV32I-NEXT: addi sp, sp, -16
11 ; RV32I-NEXT: sw ra, 12(sp)
12 ; RV32I-NEXT: call external_function
13 ; RV32I-NEXT: lw ra, 12(sp)
14 ; RV32I-NEXT: addi sp, sp, 16
16 %1 = call i32 @external_function(i32 %a)
20 define i32 @defined_function(i32 %a) nounwind {
21 ; RV32I-LABEL: defined_function:
23 ; RV32I-NEXT: addi a0, a0, 1
29 define i32 @test_call_defined(i32 %a) nounwind {
30 ; RV32I-LABEL: test_call_defined:
32 ; RV32I-NEXT: addi sp, sp, -16
33 ; RV32I-NEXT: sw ra, 12(sp)
34 ; RV32I-NEXT: call defined_function
35 ; RV32I-NEXT: lw ra, 12(sp)
36 ; RV32I-NEXT: addi sp, sp, 16
38 %1 = call i32 @defined_function(i32 %a)
42 define i32 @test_call_indirect(i32 (i32)* %a, i32 %b) nounwind {
43 ; RV32I-LABEL: test_call_indirect:
45 ; RV32I-NEXT: addi sp, sp, -16
46 ; RV32I-NEXT: sw ra, 12(sp)
47 ; RV32I-NEXT: mv a2, a0
48 ; RV32I-NEXT: mv a0, a1
50 ; RV32I-NEXT: lw ra, 12(sp)
51 ; RV32I-NEXT: addi sp, sp, 16
53 %1 = call i32 %a(i32 %b)
57 ; Ensure that calls to fastcc functions aren't rejected. Such calls may be
58 ; introduced when compiling with optimisation.
60 define fastcc i32 @fastcc_function(i32 %a, i32 %b) nounwind {
61 ; RV32I-LABEL: fastcc_function:
63 ; RV32I-NEXT: add a0, a0, a1
69 define i32 @test_call_fastcc(i32 %a, i32 %b) nounwind {
70 ; RV32I-LABEL: test_call_fastcc:
72 ; RV32I-NEXT: addi sp, sp, -16
73 ; RV32I-NEXT: sw ra, 12(sp)
74 ; RV32I-NEXT: sw s1, 8(sp)
75 ; RV32I-NEXT: mv s1, a0
76 ; RV32I-NEXT: call fastcc_function
77 ; RV32I-NEXT: mv a0, s1
78 ; RV32I-NEXT: lw s1, 8(sp)
79 ; RV32I-NEXT: lw ra, 12(sp)
80 ; RV32I-NEXT: addi sp, sp, 16
82 %1 = call fastcc i32 @fastcc_function(i32 %a, i32 %b)
86 declare i32 @external_many_args(i32, i32, i32, i32, i32, i32, i32, i32, i32, i32) nounwind
88 define i32 @test_call_external_many_args(i32 %a) nounwind {
89 ; RV32I-LABEL: test_call_external_many_args:
91 ; RV32I-NEXT: addi sp, sp, -16
92 ; RV32I-NEXT: sw ra, 12(sp)
93 ; RV32I-NEXT: sw s1, 8(sp)
94 ; RV32I-NEXT: mv s1, a0
95 ; RV32I-NEXT: sw a0, 4(sp)
96 ; RV32I-NEXT: sw a0, 0(sp)
97 ; RV32I-NEXT: mv a1, a0
98 ; RV32I-NEXT: mv a2, a0
99 ; RV32I-NEXT: mv a3, a0
100 ; RV32I-NEXT: mv a4, a0
101 ; RV32I-NEXT: mv a5, a0
102 ; RV32I-NEXT: mv a6, a0
103 ; RV32I-NEXT: mv a7, a0
104 ; RV32I-NEXT: call external_many_args
105 ; RV32I-NEXT: mv a0, s1
106 ; RV32I-NEXT: lw s1, 8(sp)
107 ; RV32I-NEXT: lw ra, 12(sp)
108 ; RV32I-NEXT: addi sp, sp, 16
110 %1 = call i32 @external_many_args(i32 %a, i32 %a, i32 %a, i32 %a, i32 %a,
111 i32 %a, i32 %a, i32 %a, i32 %a, i32 %a)
115 define i32 @defined_many_args(i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 %j) nounwind {
116 ; RV32I-LABEL: defined_many_args:
118 ; RV32I-NEXT: lw a0, 4(sp)
119 ; RV32I-NEXT: addi a0, a0, 1
121 %added = add i32 %j, 1
125 define i32 @test_call_defined_many_args(i32 %a) nounwind {
126 ; RV32I-LABEL: test_call_defined_many_args:
128 ; RV32I-NEXT: addi sp, sp, -16
129 ; RV32I-NEXT: sw ra, 12(sp)
130 ; RV32I-NEXT: sw a0, 4(sp)
131 ; RV32I-NEXT: sw a0, 0(sp)
132 ; RV32I-NEXT: mv a1, a0
133 ; RV32I-NEXT: mv a2, a0
134 ; RV32I-NEXT: mv a3, a0
135 ; RV32I-NEXT: mv a4, a0
136 ; RV32I-NEXT: mv a5, a0
137 ; RV32I-NEXT: mv a6, a0
138 ; RV32I-NEXT: mv a7, a0
139 ; RV32I-NEXT: call defined_many_args
140 ; RV32I-NEXT: lw ra, 12(sp)
141 ; RV32I-NEXT: addi sp, sp, 16
143 %1 = call i32 @defined_many_args(i32 %a, i32 %a, i32 %a, i32 %a, i32 %a,
144 i32 %a, i32 %a, i32 %a, i32 %a, i32 %a)