[llvm] [RISCV] Fix incorrect use of Zfa fli instruction for negative minimum value. (PR #70411)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 26 21:25:09 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-risc-v
Author: Craig Topper (topperc)
<details>
<summary>Changes</summary>
isSmallestNormalized() only considers the magnitude, not the sign.
---
Full diff: https://github.com/llvm/llvm-project/pull/70411.diff
4 Files Affected:
- (modified) llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp (+1-1)
- (modified) llvm/test/CodeGen/RISCV/double-zfa.ll (+10)
- (modified) llvm/test/CodeGen/RISCV/float-zfa.ll (+10)
- (modified) llvm/test/CodeGen/RISCV/half-zfa-fli.ll (+17)
``````````diff
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp
index 7919189d198c8d1..ed8ae4a7a4550d4 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp
@@ -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.
diff --git a/llvm/test/CodeGen/RISCV/double-zfa.ll b/llvm/test/CodeGen/RISCV/double-zfa.ll
index 904dd9f2ccbef91..162f33dd5ac9dd2 100644
--- a/llvm/test/CodeGen/RISCV/double-zfa.ll
+++ b/llvm/test/CodeGen/RISCV/double-zfa.ll
@@ -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 {
diff --git a/llvm/test/CodeGen/RISCV/float-zfa.ll b/llvm/test/CodeGen/RISCV/float-zfa.ll
index baa45e00b565fb5..6f9e5ec035224df 100644
--- a/llvm/test/CodeGen/RISCV/float-zfa.ll
+++ b/llvm/test/CodeGen/RISCV/float-zfa.ll
@@ -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 {
diff --git a/llvm/test/CodeGen/RISCV/half-zfa-fli.ll b/llvm/test/CodeGen/RISCV/half-zfa-fli.ll
index 2805a8e582b34b9..577b774c27a0b36 100644
--- a/llvm/test/CodeGen/RISCV/half-zfa-fli.ll
+++ b/llvm/test/CodeGen/RISCV/half-zfa-fli.ll
@@ -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
+}
+
``````````
</details>
https://github.com/llvm/llvm-project/pull/70411
More information about the llvm-commits
mailing list