1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv32 -mattr=+f -verify-machineinstrs < %s \
3 ; RUN: | FileCheck -check-prefix=RV32IF %s
4 ; RUN: llc -mtriple=riscv64 -mattr=+f -verify-machineinstrs < %s \
5 ; RUN: | FileCheck -check-prefix=RV64IF %s
7 define float @flw(float *%a) nounwind {
10 ; RV32IF-NEXT: flw ft0, 12(a0)
11 ; RV32IF-NEXT: flw ft1, 0(a0)
12 ; RV32IF-NEXT: fadd.s ft0, ft1, ft0
13 ; RV32IF-NEXT: fmv.x.w a0, ft0
18 ; RV64IF-NEXT: flw ft0, 12(a0)
19 ; RV64IF-NEXT: flw ft1, 0(a0)
20 ; RV64IF-NEXT: fadd.s ft0, ft1, ft0
21 ; RV64IF-NEXT: fmv.x.w a0, ft0
23 %1 = load float, float* %a
24 %2 = getelementptr float, float* %a, i32 3
25 %3 = load float, float* %2
26 ; Use both loaded values in an FP op to ensure an flw is used, even for the
28 %4 = fadd float %1, %3
32 define void @fsw(float *%a, float %b, float %c) nounwind {
33 ; Use %b and %c in an FP op to ensure floating point registers are used, even
34 ; for the soft float ABI
37 ; RV32IF-NEXT: fmv.w.x ft0, a2
38 ; RV32IF-NEXT: fmv.w.x ft1, a1
39 ; RV32IF-NEXT: fadd.s ft0, ft1, ft0
40 ; RV32IF-NEXT: fsw ft0, 32(a0)
41 ; RV32IF-NEXT: fsw ft0, 0(a0)
46 ; RV64IF-NEXT: fmv.w.x ft0, a2
47 ; RV64IF-NEXT: fmv.w.x ft1, a1
48 ; RV64IF-NEXT: fadd.s ft0, ft1, ft0
49 ; RV64IF-NEXT: fsw ft0, 32(a0)
50 ; RV64IF-NEXT: fsw ft0, 0(a0)
52 %1 = fadd float %b, %c
53 store float %1, float* %a
54 %2 = getelementptr float, float* %a, i32 8
55 store float %1, float* %2
59 ; Check load and store to a global
62 define float @flw_fsw_global(float %a, float %b) nounwind {
63 ; Use %a and %b in an FP op to ensure floating point registers are used, even
64 ; for the soft float ABI
65 ; RV32IF-LABEL: flw_fsw_global:
67 ; RV32IF-NEXT: fmv.w.x ft0, a1
68 ; RV32IF-NEXT: fmv.w.x ft1, a0
69 ; RV32IF-NEXT: fadd.s ft0, ft1, ft0
70 ; RV32IF-NEXT: lui a0, %hi(G)
71 ; RV32IF-NEXT: flw ft1, %lo(G)(a0)
72 ; RV32IF-NEXT: fsw ft0, %lo(G)(a0)
73 ; RV32IF-NEXT: addi a0, a0, %lo(G)
74 ; RV32IF-NEXT: flw ft1, 36(a0)
75 ; RV32IF-NEXT: fsw ft0, 36(a0)
76 ; RV32IF-NEXT: fmv.x.w a0, ft0
79 ; RV64IF-LABEL: flw_fsw_global:
81 ; RV64IF-NEXT: fmv.w.x ft0, a1
82 ; RV64IF-NEXT: fmv.w.x ft1, a0
83 ; RV64IF-NEXT: fadd.s ft0, ft1, ft0
84 ; RV64IF-NEXT: lui a0, %hi(G)
85 ; RV64IF-NEXT: flw ft1, %lo(G)(a0)
86 ; RV64IF-NEXT: fsw ft0, %lo(G)(a0)
87 ; RV64IF-NEXT: addi a0, a0, %lo(G)
88 ; RV64IF-NEXT: flw ft1, 36(a0)
89 ; RV64IF-NEXT: fsw ft0, 36(a0)
90 ; RV64IF-NEXT: fmv.x.w a0, ft0
92 %1 = fadd float %a, %b
93 %2 = load volatile float, float* @G
94 store float %1, float* @G
95 %3 = getelementptr float, float* @G, i32 9
96 %4 = load volatile float, float* %3
97 store float %1, float* %3
101 ; Ensure that 1 is added to the high 20 bits if bit 11 of the low part is 1
102 define float @flw_fsw_constant(float %a) nounwind {
103 ; RV32IF-LABEL: flw_fsw_constant:
105 ; RV32IF-NEXT: fmv.w.x ft0, a0
106 ; RV32IF-NEXT: lui a0, 912092
107 ; RV32IF-NEXT: flw ft1, -273(a0)
108 ; RV32IF-NEXT: fadd.s ft0, ft0, ft1
109 ; RV32IF-NEXT: fsw ft0, -273(a0)
110 ; RV32IF-NEXT: fmv.x.w a0, ft0
113 ; RV64IF-LABEL: flw_fsw_constant:
115 ; RV64IF-NEXT: fmv.w.x ft0, a0
116 ; RV64IF-NEXT: lui a0, 56
117 ; RV64IF-NEXT: addiw a0, a0, -1353
118 ; RV64IF-NEXT: slli a0, a0, 14
119 ; RV64IF-NEXT: flw ft1, -273(a0)
120 ; RV64IF-NEXT: fadd.s ft0, ft0, ft1
121 ; RV64IF-NEXT: fsw ft0, -273(a0)
122 ; RV64IF-NEXT: fmv.x.w a0, ft0
124 %1 = inttoptr i32 3735928559 to float*
125 %2 = load volatile float, float* %1
126 %3 = fadd float %a, %2
127 store float %3, float* %1
131 declare void @notdead(i8*)
133 define float @flw_stack(float %a) nounwind {
134 ; RV32IF-LABEL: flw_stack:
136 ; RV32IF-NEXT: addi sp, sp, -16
137 ; RV32IF-NEXT: sw ra, 12(sp)
138 ; RV32IF-NEXT: sw s0, 8(sp)
139 ; RV32IF-NEXT: mv s0, a0
140 ; RV32IF-NEXT: addi a0, sp, 4
141 ; RV32IF-NEXT: call notdead
142 ; RV32IF-NEXT: fmv.w.x ft0, s0
143 ; RV32IF-NEXT: flw ft1, 4(sp)
144 ; RV32IF-NEXT: fadd.s ft0, ft1, ft0
145 ; RV32IF-NEXT: fmv.x.w a0, ft0
146 ; RV32IF-NEXT: lw s0, 8(sp)
147 ; RV32IF-NEXT: lw ra, 12(sp)
148 ; RV32IF-NEXT: addi sp, sp, 16
151 ; RV64IF-LABEL: flw_stack:
153 ; RV64IF-NEXT: addi sp, sp, -32
154 ; RV64IF-NEXT: sd ra, 24(sp)
155 ; RV64IF-NEXT: sd s0, 16(sp)
156 ; RV64IF-NEXT: mv s0, a0
157 ; RV64IF-NEXT: addi a0, sp, 12
158 ; RV64IF-NEXT: call notdead
159 ; RV64IF-NEXT: fmv.w.x ft0, s0
160 ; RV64IF-NEXT: flw ft1, 12(sp)
161 ; RV64IF-NEXT: fadd.s ft0, ft1, ft0
162 ; RV64IF-NEXT: fmv.x.w a0, ft0
163 ; RV64IF-NEXT: ld s0, 16(sp)
164 ; RV64IF-NEXT: ld ra, 24(sp)
165 ; RV64IF-NEXT: addi sp, sp, 32
167 %1 = alloca float, align 4
168 %2 = bitcast float* %1 to i8*
169 call void @notdead(i8* %2)
170 %3 = load float, float* %1
171 %4 = fadd float %3, %a ; force load in to FPR32
175 define void @fsw_stack(float %a, float %b) nounwind {
176 ; RV32IF-LABEL: fsw_stack:
178 ; RV32IF-NEXT: addi sp, sp, -16
179 ; RV32IF-NEXT: sw ra, 12(sp)
180 ; RV32IF-NEXT: fmv.w.x ft0, a1
181 ; RV32IF-NEXT: fmv.w.x ft1, a0
182 ; RV32IF-NEXT: fadd.s ft0, ft1, ft0
183 ; RV32IF-NEXT: fsw ft0, 8(sp)
184 ; RV32IF-NEXT: addi a0, sp, 8
185 ; RV32IF-NEXT: call notdead
186 ; RV32IF-NEXT: lw ra, 12(sp)
187 ; RV32IF-NEXT: addi sp, sp, 16
190 ; RV64IF-LABEL: fsw_stack:
192 ; RV64IF-NEXT: addi sp, sp, -16
193 ; RV64IF-NEXT: sd ra, 8(sp)
194 ; RV64IF-NEXT: fmv.w.x ft0, a1
195 ; RV64IF-NEXT: fmv.w.x ft1, a0
196 ; RV64IF-NEXT: fadd.s ft0, ft1, ft0
197 ; RV64IF-NEXT: fsw ft0, 4(sp)
198 ; RV64IF-NEXT: addi a0, sp, 4
199 ; RV64IF-NEXT: call notdead
200 ; RV64IF-NEXT: ld ra, 8(sp)
201 ; RV64IF-NEXT: addi sp, sp, 16
203 %1 = fadd float %a, %b ; force store from FPR32
204 %2 = alloca float, align 4
205 store float %1, float* %2
206 %3 = bitcast float* %2 to i8*
207 call void @notdead(i8* %3)