-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…ized value. We only use fli for the positive normalized value.
… value. isSmallestNormalized() only considers the magnitude, not the sign.
@llvm/pr-subscribers-backend-risc-v Author: Craig Topper (topperc) ChangesisSmallestNormalized() only considers the magnitude, not the sign. Full diff: https://github.com/llvm/llvm-project/pull/70411.diff 4 Files Affected:
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
+}
+
|
wangpc-pp
approved these changes
Oct 27, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
topperc
added a commit
that referenced
this pull request
Oct 27, 2023
… value. (#70411) isSmallestNormalized() only considers the magnitude, not the sign.
Committed as 8ff1422 |
Guzhu-AMD
pushed a commit
to GPUOpen-Drivers/llvm-project
that referenced
this pull request
Nov 2, 2023
Local branch amd-gfx 7b33fe8 Merged main:6ca5b814f331 into amd-gfx:fdba192c72b2 Remote branch main 8ff1422 [RISCV] Fix incorrect use of Zfa fli instruction for negative minimum value. (llvm#70411)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
isSmallestNormalized() only considers the magnitude, not the sign.