[llvm] a258894 - Fix convertBFloatAPFloatToAPInt for NaN/Inf values
Diego Caballero via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 5 17:30:19 PDT 2020
Author: Diego Caballero
Date: 2020-06-05T17:22:43-07:00
New Revision: a2588948febccfed5ba074fc32dcb093484fa5c8
URL: https://github.com/llvm/llvm-project/commit/a2588948febccfed5ba074fc32dcb093484fa5c8
DIFF: https://github.com/llvm/llvm-project/commit/a2588948febccfed5ba074fc32dcb093484fa5c8.diff
LOG: Fix convertBFloatAPFloatToAPInt for NaN/Inf values
Bfloat type has an 8-bit exponent so the exponent of NaN/Inf numbers
must be 0xff instead of 0x1f. This is probably a copy-paste mistake
from the half float type.
Reviewed By: lattner
Differential Revision: https://reviews.llvm.org/D81302
Added:
Modified:
llvm/lib/Support/APFloat.cpp
llvm/test/Assembler/bfloat.ll
Removed:
################################################################################
diff --git a/llvm/lib/Support/APFloat.cpp b/llvm/lib/Support/APFloat.cpp
index 78f44c5e47bb..569cac790af9 100644
--- a/llvm/lib/Support/APFloat.cpp
+++ b/llvm/lib/Support/APFloat.cpp
@@ -3278,11 +3278,11 @@ APInt IEEEFloat::convertBFloatAPFloatToAPInt() const {
myexponent = 0;
mysignificand = 0;
} else if (category == fcInfinity) {
- myexponent = 0x1f;
+ myexponent = 0xff;
mysignificand = 0;
} else {
assert(category == fcNaN && "Unknown category!");
- myexponent = 0x1f;
+ myexponent = 0xff;
mysignificand = (uint32_t)*significandParts();
}
diff --git a/llvm/test/Assembler/bfloat.ll b/llvm/test/Assembler/bfloat.ll
index c9c7b6d26868..3a3b4c2b277d 100644
--- a/llvm/test/Assembler/bfloat.ll
+++ b/llvm/test/Assembler/bfloat.ll
@@ -36,3 +36,27 @@ define float @check_bfloat_convert() {
; OPT: 0x4191A00000000000
ret float %tmp
}
+
+; ASSEM-DISASS-LABEL @snan_bfloat
+define bfloat @snan_bfloat() {
+; ASSEM-DISASS: ret bfloat 0xR7F81
+ ret bfloat 0xR7F81
+}
+
+; ASSEM-DISASS-LABEL @qnan_bfloat
+define bfloat @qnan_bfloat() {
+; ASSEM-DISASS: ret bfloat 0xR7FC0
+ ret bfloat 0xR7FC0
+}
+
+; ASSEM-DISASS-LABEL @pos_inf_bfloat
+define bfloat @pos_inf_bfloat() {
+; ASSEM-DISASS: ret bfloat 0xR7F80
+ ret bfloat 0xR7F80
+}
+
+; ASSEM-DISASS-LABEL @neg_inf_bfloat
+define bfloat @neg_inf_bfloat() {
+; ASSEM-DISASS: ret bfloat 0xRFF80
+ ret bfloat 0xRFF80
+}
More information about the llvm-commits
mailing list