Skip to content

Commit

Permalink
[RISCV] Fix incorrect use of Zfa fli instruction for negative minimum…
Browse files Browse the repository at this point in the history
… value. (#70411)

isSmallestNormalized() only considers the magnitude, not the sign.
  • Loading branch information
topperc committed Oct 27, 2023
1 parent be0cbe9 commit 8ff1422
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ int RISCVLoadFPImm::getLoadFPImm(APFloat FPImm) {
"Unexpected semantics");

// Handle the minimum normalized value which is different for each type.
if (FPImm.isSmallestNormalized())
if (FPImm.isSmallestNormalized() && !FPImm.isNegative())
return 1;

// Convert to single precision to use its lookup table.
Expand Down
3 changes: 2 additions & 1 deletion llvm/test/CodeGen/RISCV/double-zfa.ll
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ define double @loadfpimm17() {
define double @loadfpimm18() {
; CHECK-LABEL: loadfpimm18:
; CHECK: # %bb.0:
; CHECK-NEXT: fli.d fa0, min
; CHECK-NEXT: lui a0, %hi(.LCPI16_0)
; CHECK-NEXT: fld fa0, %lo(.LCPI16_0)(a0)
; CHECK-NEXT: ret
ret double 0x8010000000000000
}
Expand Down
3 changes: 2 additions & 1 deletion llvm/test/CodeGen/RISCV/float-zfa.ll
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ define float @loadfpimm12() {
define float @loadfpimm13() {
; CHECK-LABEL: loadfpimm13:
; CHECK: # %bb.0:
; CHECK-NEXT: fli.s fa0, min
; CHECK-NEXT: lui a0, 526336
; CHECK-NEXT: fmv.w.x fa0, a0
; CHECK-NEXT: ret
ret float 0xb810000000000000
}
Expand Down
3 changes: 2 additions & 1 deletion llvm/test/CodeGen/RISCV/half-zfa-fli.ll
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ define half @loadfpimm14() {
define half @loadfpimm15() {
; CHECK-LABEL: loadfpimm15:
; CHECK: # %bb.0:
; CHECK-NEXT: fli.h fa0, min
; CHECK-NEXT: lui a0, %hi(.LCPI14_0)
; CHECK-NEXT: flh fa0, %lo(.LCPI14_0)(a0)
; CHECK-NEXT: ret
;
; ZFHMIN-LABEL: loadfpimm15:
Expand Down

0 comments on commit 8ff1422

Please sign in to comment.