calling-conv-lp64.ll
6.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s \
; RUN: | FileCheck -check-prefix=RV64I-FPELIM %s
; RUN: llc -mtriple=riscv64 -verify-machineinstrs -frame-pointer=all < %s \
; RUN: | FileCheck -check-prefix=RV64I-WITHFP %s
; As well as calling convention details, we check that ra and fp are
; consistently stored to fp-8 and fp-16.
; Any tests that would have identical output for some combination of the lp64*
; ABIs belong in calling-conv-*-common.ll. This file contains tests that will
; have different output across those ABIs. i.e. where some arguments would be
; passed according to the floating point ABI.
; TODO: softened float values can be passed anyext.
define i64 @callee_float_in_regs(i64 %a, float %b) nounwind {
; RV64I-FPELIM-LABEL: callee_float_in_regs:
; RV64I-FPELIM: # %bb.0:
; RV64I-FPELIM-NEXT: addi sp, sp, -16
; RV64I-FPELIM-NEXT: sd ra, 8(sp)
; RV64I-FPELIM-NEXT: sd s0, 0(sp)
; RV64I-FPELIM-NEXT: mv s0, a0
; RV64I-FPELIM-NEXT: mv a0, a1
; RV64I-FPELIM-NEXT: call __fixsfdi
; RV64I-FPELIM-NEXT: add a0, s0, a0
; RV64I-FPELIM-NEXT: ld s0, 0(sp)
; RV64I-FPELIM-NEXT: ld ra, 8(sp)
; RV64I-FPELIM-NEXT: addi sp, sp, 16
; RV64I-FPELIM-NEXT: ret
;
; RV64I-WITHFP-LABEL: callee_float_in_regs:
; RV64I-WITHFP: # %bb.0:
; RV64I-WITHFP-NEXT: addi sp, sp, -32
; RV64I-WITHFP-NEXT: sd ra, 24(sp)
; RV64I-WITHFP-NEXT: sd s0, 16(sp)
; RV64I-WITHFP-NEXT: sd s1, 8(sp)
; RV64I-WITHFP-NEXT: addi s0, sp, 32
; RV64I-WITHFP-NEXT: mv s1, a0
; RV64I-WITHFP-NEXT: mv a0, a1
; RV64I-WITHFP-NEXT: call __fixsfdi
; RV64I-WITHFP-NEXT: add a0, s1, a0
; RV64I-WITHFP-NEXT: ld s1, 8(sp)
; RV64I-WITHFP-NEXT: ld s0, 16(sp)
; RV64I-WITHFP-NEXT: ld ra, 24(sp)
; RV64I-WITHFP-NEXT: addi sp, sp, 32
; RV64I-WITHFP-NEXT: ret
%b_fptosi = fptosi float %b to i64
%1 = add i64 %a, %b_fptosi
ret i64 %1
}
define i64 @caller_float_in_regs() nounwind {
; RV64I-FPELIM-LABEL: caller_float_in_regs:
; RV64I-FPELIM: # %bb.0:
; RV64I-FPELIM-NEXT: addi sp, sp, -16
; RV64I-FPELIM-NEXT: sd ra, 8(sp)
; RV64I-FPELIM-NEXT: addi a0, zero, 1
; RV64I-FPELIM-NEXT: lui a1, 262144
; RV64I-FPELIM-NEXT: call callee_float_in_regs
; RV64I-FPELIM-NEXT: ld ra, 8(sp)
; RV64I-FPELIM-NEXT: addi sp, sp, 16
; RV64I-FPELIM-NEXT: ret
;
; RV64I-WITHFP-LABEL: caller_float_in_regs:
; RV64I-WITHFP: # %bb.0:
; RV64I-WITHFP-NEXT: addi sp, sp, -16
; RV64I-WITHFP-NEXT: sd ra, 8(sp)
; RV64I-WITHFP-NEXT: sd s0, 0(sp)
; RV64I-WITHFP-NEXT: addi s0, sp, 16
; RV64I-WITHFP-NEXT: addi a0, zero, 1
; RV64I-WITHFP-NEXT: lui a1, 262144
; RV64I-WITHFP-NEXT: call callee_float_in_regs
; RV64I-WITHFP-NEXT: ld s0, 0(sp)
; RV64I-WITHFP-NEXT: ld ra, 8(sp)
; RV64I-WITHFP-NEXT: addi sp, sp, 16
; RV64I-WITHFP-NEXT: ret
%1 = call i64 @callee_float_in_regs(i64 1, float 2.0)
ret i64 %1
}
define i64 @callee_float_on_stack(i128 %a, i128 %b, i128 %c, i128 %d, float %e) nounwind {
; RV64I-FPELIM-LABEL: callee_float_on_stack:
; RV64I-FPELIM: # %bb.0:
; RV64I-FPELIM-NEXT: lw a0, 0(sp)
; RV64I-FPELIM-NEXT: ret
;
; RV64I-WITHFP-LABEL: callee_float_on_stack:
; RV64I-WITHFP: # %bb.0:
; RV64I-WITHFP-NEXT: addi sp, sp, -16
; RV64I-WITHFP-NEXT: sd ra, 8(sp)
; RV64I-WITHFP-NEXT: sd s0, 0(sp)
; RV64I-WITHFP-NEXT: addi s0, sp, 16
; RV64I-WITHFP-NEXT: lw a0, 0(s0)
; RV64I-WITHFP-NEXT: ld s0, 0(sp)
; RV64I-WITHFP-NEXT: ld ra, 8(sp)
; RV64I-WITHFP-NEXT: addi sp, sp, 16
; RV64I-WITHFP-NEXT: ret
%1 = trunc i128 %d to i64
%2 = bitcast float %e to i32
%3 = sext i32 %2 to i64
%4 = add i64 %1, %3
ret i64 %3
}
define i64 @caller_float_on_stack() nounwind {
; RV64I-FPELIM-LABEL: caller_float_on_stack:
; RV64I-FPELIM: # %bb.0:
; RV64I-FPELIM-NEXT: addi sp, sp, -16
; RV64I-FPELIM-NEXT: sd ra, 8(sp)
; RV64I-FPELIM-NEXT: lui a1, 264704
; RV64I-FPELIM-NEXT: addi a0, zero, 1
; RV64I-FPELIM-NEXT: addi a2, zero, 2
; RV64I-FPELIM-NEXT: addi a4, zero, 3
; RV64I-FPELIM-NEXT: addi a6, zero, 4
; RV64I-FPELIM-NEXT: sd a1, 0(sp)
; RV64I-FPELIM-NEXT: mv a1, zero
; RV64I-FPELIM-NEXT: mv a3, zero
; RV64I-FPELIM-NEXT: mv a5, zero
; RV64I-FPELIM-NEXT: mv a7, zero
; RV64I-FPELIM-NEXT: call callee_float_on_stack
; RV64I-FPELIM-NEXT: ld ra, 8(sp)
; RV64I-FPELIM-NEXT: addi sp, sp, 16
; RV64I-FPELIM-NEXT: ret
;
; RV64I-WITHFP-LABEL: caller_float_on_stack:
; RV64I-WITHFP: # %bb.0:
; RV64I-WITHFP-NEXT: addi sp, sp, -32
; RV64I-WITHFP-NEXT: sd ra, 24(sp)
; RV64I-WITHFP-NEXT: sd s0, 16(sp)
; RV64I-WITHFP-NEXT: addi s0, sp, 32
; RV64I-WITHFP-NEXT: lui a1, 264704
; RV64I-WITHFP-NEXT: addi a0, zero, 1
; RV64I-WITHFP-NEXT: addi a2, zero, 2
; RV64I-WITHFP-NEXT: addi a4, zero, 3
; RV64I-WITHFP-NEXT: addi a6, zero, 4
; RV64I-WITHFP-NEXT: sd a1, 0(sp)
; RV64I-WITHFP-NEXT: mv a1, zero
; RV64I-WITHFP-NEXT: mv a3, zero
; RV64I-WITHFP-NEXT: mv a5, zero
; RV64I-WITHFP-NEXT: mv a7, zero
; RV64I-WITHFP-NEXT: call callee_float_on_stack
; RV64I-WITHFP-NEXT: ld s0, 16(sp)
; RV64I-WITHFP-NEXT: ld ra, 24(sp)
; RV64I-WITHFP-NEXT: addi sp, sp, 32
; RV64I-WITHFP-NEXT: ret
%1 = call i64 @callee_float_on_stack(i128 1, i128 2, i128 3, i128 4, float 5.0)
ret i64 %1
}
define float @callee_tiny_scalar_ret() nounwind {
; RV64I-FPELIM-LABEL: callee_tiny_scalar_ret:
; RV64I-FPELIM: # %bb.0:
; RV64I-FPELIM-NEXT: lui a0, 260096
; RV64I-FPELIM-NEXT: ret
;
; RV64I-WITHFP-LABEL: callee_tiny_scalar_ret:
; RV64I-WITHFP: # %bb.0:
; RV64I-WITHFP-NEXT: addi sp, sp, -16
; RV64I-WITHFP-NEXT: sd ra, 8(sp)
; RV64I-WITHFP-NEXT: sd s0, 0(sp)
; RV64I-WITHFP-NEXT: addi s0, sp, 16
; RV64I-WITHFP-NEXT: lui a0, 260096
; RV64I-WITHFP-NEXT: ld s0, 0(sp)
; RV64I-WITHFP-NEXT: ld ra, 8(sp)
; RV64I-WITHFP-NEXT: addi sp, sp, 16
; RV64I-WITHFP-NEXT: ret
ret float 1.0
}
; The sign extension of the float return is necessary, as softened floats are
; passed anyext.
define i64 @caller_tiny_scalar_ret() nounwind {
; RV64I-FPELIM-LABEL: caller_tiny_scalar_ret:
; RV64I-FPELIM: # %bb.0:
; RV64I-FPELIM-NEXT: addi sp, sp, -16
; RV64I-FPELIM-NEXT: sd ra, 8(sp)
; RV64I-FPELIM-NEXT: call callee_tiny_scalar_ret
; RV64I-FPELIM-NEXT: sext.w a0, a0
; RV64I-FPELIM-NEXT: ld ra, 8(sp)
; RV64I-FPELIM-NEXT: addi sp, sp, 16
; RV64I-FPELIM-NEXT: ret
;
; RV64I-WITHFP-LABEL: caller_tiny_scalar_ret:
; RV64I-WITHFP: # %bb.0:
; RV64I-WITHFP-NEXT: addi sp, sp, -16
; RV64I-WITHFP-NEXT: sd ra, 8(sp)
; RV64I-WITHFP-NEXT: sd s0, 0(sp)
; RV64I-WITHFP-NEXT: addi s0, sp, 16
; RV64I-WITHFP-NEXT: call callee_tiny_scalar_ret
; RV64I-WITHFP-NEXT: sext.w a0, a0
; RV64I-WITHFP-NEXT: ld s0, 0(sp)
; RV64I-WITHFP-NEXT: ld ra, 8(sp)
; RV64I-WITHFP-NEXT: addi sp, sp, 16
; RV64I-WITHFP-NEXT: ret
%1 = call float @callee_tiny_scalar_ret()
%2 = bitcast float %1 to i32
%3 = sext i32 %2 to i64
ret i64 %3
}