Skip to content

Commit 0152e1f

Browse files
authored
[RISCV] Fix incorrect codegen for Zfa with negated forms of constants in the lookup table (#68026)
The logic in `RISCVLoadFPImm::getLoadFPImm` recognises that the only supported negative value is -1.0, but due to a typo returns `false` otherwise (entry 0, which is -1.0) rather than returning -1 (indicating no match found).
1 parent 3dda104 commit 0152e1f

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ int RISCVLoadFPImm::getLoadFPImm(APFloat FPImm) {
273273
if (Sign) {
274274
if (Entry == 16)
275275
return 0;
276-
return false;
276+
return -1;
277277
}
278278

279279
return Entry;

llvm/test/CodeGen/RISCV/double-zfa.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ define double @loadfpimm16() {
143143

144144
; Ensure fli isn't incorrectly used for negated versions of numbers in the fli
145145
; table.
146-
; FIXME: Codegen is incorrect.
147146
define double @loadfpimm17() {
148147
; CHECK-LABEL: loadfpimm17:
149148
; CHECK: # %bb.0:
150-
; CHECK-NEXT: fli.d fa0, -1.0
149+
; CHECK-NEXT: lui a0, %hi(.LCPI15_0)
150+
; CHECK-NEXT: fld fa0, %lo(.LCPI15_0)(a0)
151151
; CHECK-NEXT: ret
152152
ret double -2.0
153153
}

llvm/test/CodeGen/RISCV/float-zfa.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ define float @loadfpimm11() {
9797

9898
; Ensure fli isn't incorrectly used for negated versions of numbers in the fli
9999
; table.
100-
; FIXME: Codegen is incorrect.
101100
define float @loadfpimm12() {
102101
; CHECK-LABEL: loadfpimm12:
103102
; CHECK: # %bb.0:
104-
; CHECK-NEXT: fli.s fa0, -1.0
103+
; CHECK-NEXT: lui a0, 786432
104+
; CHECK-NEXT: fmv.w.x fa0, a0
105105
; CHECK-NEXT: ret
106106
ret float -2.0
107107
}

llvm/test/CodeGen/RISCV/half-zfa-fli.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,11 @@ define half @loadfpimm13() {
197197

198198
; Ensure fli isn't incorrectly used for negated versions of numbers in the fli
199199
; table.
200-
; FIXME: Codegen is incorrect when Zfa is enabled.
201200
define half @loadfpimm14() {
202201
; CHECK-LABEL: loadfpimm14:
203202
; CHECK: # %bb.0:
204-
; CHECK-NEXT: fli.h fa0, -1.0
203+
; CHECK-NEXT: lui a0, 1048572
204+
; CHECK-NEXT: fmv.h.x fa0, a0
205205
; CHECK-NEXT: ret
206206
;
207207
; ZFHMIN-LABEL: loadfpimm14:

0 commit comments

Comments
 (0)