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, 0(a0)
11 ; RV32IF-NEXT: flw ft1, 12(a0)
12 ; RV32IF-NEXT: fadd.s ft0, ft0, ft1
13 ; RV32IF-NEXT: fmv.x.w a0, ft0
18 ; RV64IF-NEXT: flw ft0, 0(a0)
19 ; RV64IF-NEXT: flw ft1, 12(a0)
20 ; RV64IF-NEXT: fadd.s ft0, ft0, ft1
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, 0(a0)
41 ; RV32IF-NEXT: fsw ft0, 32(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, 0(a0)
50 ; RV64IF-NEXT: fsw ft0, 32(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 a1, a0, %lo(G)
74 ; RV32IF-NEXT: flw ft1, 36(a1)
75 ; RV32IF-NEXT: fmv.x.w a0, ft0
76 ; RV32IF-NEXT: fsw ft0, 36(a1)
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 a1, a0, %lo(G)
88 ; RV64IF-NEXT: flw ft1, 36(a1)
89 ; RV64IF-NEXT: fmv.x.w a0, ft0
90 ; RV64IF-NEXT: fsw ft0, 36(a1)
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: lui a1, 912092
106 ; RV32IF-NEXT: flw ft0, -273(a1)
107 ; RV32IF-NEXT: fmv.w.x ft1, a0
108 ; RV32IF-NEXT: fadd.s ft0, ft1, ft0
109 ; RV32IF-NEXT: fmv.x.w a0, ft0
110 ; RV32IF-NEXT: fsw ft0, -273(a1)
113 ; RV64IF-LABEL: flw_fsw_constant:
115 ; RV64IF-NEXT: lui a1, 56
116 ; RV64IF-NEXT: addiw a1, a1, -1353
117 ; RV64IF-NEXT: slli a1, a1, 14
118 ; RV64IF-NEXT: flw ft0, -273(a1)
119 ; RV64IF-NEXT: fmv.w.x ft1, a0
120 ; RV64IF-NEXT: fadd.s ft0, ft1, ft0
121 ; RV64IF-NEXT: fmv.x.w a0, ft0
122 ; RV64IF-NEXT: fsw ft0, -273(a1)
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: fmv.w.x ft0, a0
139 ; RV32IF-NEXT: fsw ft0, 4(sp)
140 ; RV32IF-NEXT: addi a0, sp, 8
141 ; RV32IF-NEXT: call notdead
142 ; RV32IF-NEXT: flw ft0, 8(sp)
143 ; RV32IF-NEXT: flw ft1, 4(sp)
144 ; RV32IF-NEXT: fadd.s ft0, ft0, ft1
145 ; RV32IF-NEXT: fmv.x.w a0, ft0
146 ; RV32IF-NEXT: lw ra, 12(sp)
147 ; RV32IF-NEXT: addi sp, sp, 16
150 ; RV64IF-LABEL: flw_stack:
152 ; RV64IF-NEXT: addi sp, sp, -16
153 ; RV64IF-NEXT: sd ra, 8(sp)
154 ; RV64IF-NEXT: fmv.w.x ft0, a0
155 ; RV64IF-NEXT: fsw ft0, 0(sp)
156 ; RV64IF-NEXT: addi a0, sp, 4
157 ; RV64IF-NEXT: call notdead
158 ; RV64IF-NEXT: flw ft0, 4(sp)
159 ; RV64IF-NEXT: flw ft1, 0(sp)
160 ; RV64IF-NEXT: fadd.s ft0, ft0, ft1
161 ; RV64IF-NEXT: fmv.x.w a0, ft0
162 ; RV64IF-NEXT: ld ra, 8(sp)
163 ; RV64IF-NEXT: addi sp, sp, 16
165 %1 = alloca float, align 4
166 %2 = bitcast float* %1 to i8*
167 call void @notdead(i8* %2)
168 %3 = load float, float* %1
169 %4 = fadd float %3, %a ; force load in to FPR32
173 define void @fsw_stack(float %a, float %b) nounwind {
174 ; RV32IF-LABEL: fsw_stack:
176 ; RV32IF-NEXT: addi sp, sp, -16
177 ; RV32IF-NEXT: sw ra, 12(sp)
178 ; RV32IF-NEXT: fmv.w.x ft0, a1
179 ; RV32IF-NEXT: fmv.w.x ft1, a0
180 ; RV32IF-NEXT: fadd.s ft0, ft1, ft0
181 ; RV32IF-NEXT: fsw ft0, 8(sp)
182 ; RV32IF-NEXT: addi a0, sp, 8
183 ; RV32IF-NEXT: call notdead
184 ; RV32IF-NEXT: lw ra, 12(sp)
185 ; RV32IF-NEXT: addi sp, sp, 16
188 ; RV64IF-LABEL: fsw_stack:
190 ; RV64IF-NEXT: addi sp, sp, -16
191 ; RV64IF-NEXT: sd ra, 8(sp)
192 ; RV64IF-NEXT: fmv.w.x ft0, a1
193 ; RV64IF-NEXT: fmv.w.x ft1, a0
194 ; RV64IF-NEXT: fadd.s ft0, ft1, ft0
195 ; RV64IF-NEXT: fsw ft0, 4(sp)
196 ; RV64IF-NEXT: addi a0, sp, 4
197 ; RV64IF-NEXT: call notdead
198 ; RV64IF-NEXT: ld ra, 8(sp)
199 ; RV64IF-NEXT: addi sp, sp, 16
201 %1 = fadd float %a, %b ; force store from FPR32
202 %2 = alloca float, align 4
203 store float %1, float* %2
204 %3 = bitcast float* %2 to i8*
205 call void @notdead(i8* %3)