Skip to content

[RISCV] Fix incorrect use of Zfa fli instruction for negative minimum value. #70411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
10 changes: 10 additions & 0 deletions llvm/test/CodeGen/RISCV/double-zfa.ll
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,16 @@ define double @loadfpimm17() {
ret double -2.0
}

; Ensure fli isn't incorrecty used for negative min normal value.
define double @loadfpimm18() {
; CHECK-LABEL: loadfpimm18:
; CHECK: # %bb.0:
; CHECK-NEXT: lui a0, %hi(.LCPI16_0)
; CHECK-NEXT: fld fa0, %lo(.LCPI16_0)(a0)
; CHECK-NEXT: ret
ret double 0x8010000000000000
}

declare double @llvm.minimum.f64(double, double)

define double @fminm_d(double %a, double %b) nounwind {
Expand Down
10 changes: 10 additions & 0 deletions llvm/test/CodeGen/RISCV/float-zfa.ll
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ define float @loadfpimm12() {
ret float -2.0
}

; Ensure fli isn't incorrecty used for negative min normal value.
define float @loadfpimm13() {
; CHECK-LABEL: loadfpimm13:
; CHECK: # %bb.0:
; CHECK-NEXT: lui a0, 526336
; CHECK-NEXT: fmv.w.x fa0, a0
; CHECK-NEXT: ret
ret float 0xb810000000000000
}

declare float @llvm.minimum.f32(float, float)

define float @fminm_s(float %a, float %b) nounwind {
Expand Down
17 changes: 17 additions & 0 deletions llvm/test/CodeGen/RISCV/half-zfa-fli.ll
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,20 @@ define half @loadfpimm14() {
; ZFHMIN-NEXT: ret
ret half -2.0
}

; Ensure fli isn't incorrecty used for negative min normal value.
define half @loadfpimm15() {
; CHECK-LABEL: loadfpimm15:
; CHECK: # %bb.0:
; CHECK-NEXT: lui a0, %hi(.LCPI14_0)
; CHECK-NEXT: flh fa0, %lo(.LCPI14_0)(a0)
; CHECK-NEXT: ret
;
; ZFHMIN-LABEL: loadfpimm15:
; ZFHMIN: # %bb.0:
; ZFHMIN-NEXT: lui a0, %hi(.LCPI14_0)
; ZFHMIN-NEXT: flh fa0, %lo(.LCPI14_0)(a0)
; ZFHMIN-NEXT: ret
ret half 0xH8400
}