-
Notifications
You must be signed in to change notification settings - Fork 12k
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
Fix bitcasting E8M0 APFloat to APInt #113298
Conversation
@llvm/pr-subscribers-llvm-adt Author: Sergey Kozub (sergey-kozub) ChangesFull diff: https://github.com/llvm/llvm-project/pull/113298.diff 2 Files Affected:
diff --git a/llvm/lib/Support/APFloat.cpp b/llvm/lib/Support/APFloat.cpp
index a33b6c4a6ddc63..157a6a3c561884 100644
--- a/llvm/lib/Support/APFloat.cpp
+++ b/llvm/lib/Support/APFloat.cpp
@@ -3663,7 +3663,7 @@ APInt IEEEFloat::convertIEEEFloatToAPInt() const {
std::array<uint64_t, (S.sizeInBits + 63) / 64> words;
auto words_iter =
std::copy_n(mysignificand.begin(), mysignificand.size(), words.begin());
- if constexpr (significand_mask != 0) {
+ if constexpr (significand_mask != 0 || trailing_significand_bits == 0) {
// Clear the integer bit.
words[mysignificand.size() - 1] &= significand_mask;
}
diff --git a/llvm/unittests/ADT/APFloatTest.cpp b/llvm/unittests/ADT/APFloatTest.cpp
index 665cff9c424594..a4d72f2dd369ac 100644
--- a/llvm/unittests/ADT/APFloatTest.cpp
+++ b/llvm/unittests/ADT/APFloatTest.cpp
@@ -7614,6 +7614,15 @@ TEST(APFloatTest, ConvertDoubleToE8M0FNU) {
EXPECT_EQ(status, APFloat::opUnderflow | APFloat::opInexact);
}
+TEST(APFloatTest, Float8E8M0FNUBitcastToAPInt) {
+ // Regression test for verifying the low bit of the exponent when bitcasting
+ // to integer (zero mantissa).
+ APFloat f0(APFloat::Float8E8M0FNU(), "0.5");
+ APFloat f1(APFloat::Float8E8M0FNU(), "1.0");
+ EXPECT_EQ(f0.bitcastToAPInt(), 126) << f0;
+ EXPECT_EQ(f1.bitcastToAPInt(), 127) << f1;
+}
+
TEST(APFloatTest, Float6E3M2FNFromString) {
// Exactly representable
EXPECT_EQ(28, APFloat(APFloat::Float6E3M2FN(), "28").convertToDouble());
|
@llvm/pr-subscribers-llvm-support Author: Sergey Kozub (sergey-kozub) ChangesFull diff: https://github.com/llvm/llvm-project/pull/113298.diff 2 Files Affected:
diff --git a/llvm/lib/Support/APFloat.cpp b/llvm/lib/Support/APFloat.cpp
index a33b6c4a6ddc63..157a6a3c561884 100644
--- a/llvm/lib/Support/APFloat.cpp
+++ b/llvm/lib/Support/APFloat.cpp
@@ -3663,7 +3663,7 @@ APInt IEEEFloat::convertIEEEFloatToAPInt() const {
std::array<uint64_t, (S.sizeInBits + 63) / 64> words;
auto words_iter =
std::copy_n(mysignificand.begin(), mysignificand.size(), words.begin());
- if constexpr (significand_mask != 0) {
+ if constexpr (significand_mask != 0 || trailing_significand_bits == 0) {
// Clear the integer bit.
words[mysignificand.size() - 1] &= significand_mask;
}
diff --git a/llvm/unittests/ADT/APFloatTest.cpp b/llvm/unittests/ADT/APFloatTest.cpp
index 665cff9c424594..a4d72f2dd369ac 100644
--- a/llvm/unittests/ADT/APFloatTest.cpp
+++ b/llvm/unittests/ADT/APFloatTest.cpp
@@ -7614,6 +7614,15 @@ TEST(APFloatTest, ConvertDoubleToE8M0FNU) {
EXPECT_EQ(status, APFloat::opUnderflow | APFloat::opInexact);
}
+TEST(APFloatTest, Float8E8M0FNUBitcastToAPInt) {
+ // Regression test for verifying the low bit of the exponent when bitcasting
+ // to integer (zero mantissa).
+ APFloat f0(APFloat::Float8E8M0FNU(), "0.5");
+ APFloat f1(APFloat::Float8E8M0FNU(), "1.0");
+ EXPECT_EQ(f0.bitcastToAPInt(), 126) << f0;
+ EXPECT_EQ(f1.bitcastToAPInt(), 127) << f1;
+}
+
TEST(APFloatTest, Float6E3M2FNFromString) {
// Exactly representable
EXPECT_EQ(28, APFloat(APFloat::Float6E3M2FN(), "28").convertToDouble());
|
897bad2
to
f276e39
Compare
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/123/builds/7956 Here is the relevant piece of the build log for the reference
|
Fixes a bug in APFloat handling of E8M0 type (zero mantissa). Related PRs: - llvm#107127 - llvm#111028
Fixes a bug in APFloat handling of E8M0 type (zero mantissa).
Related PRs: