diff options
author | Sergey Kozub <skozub@nvidia.com> | 2024-10-22 19:15:29 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-22 19:15:29 +0200 |
commit | 7b308b18c3946dd0e09c661db52f70eff3fe8104 (patch) | |
tree | 7892869f3476f146698c7929158cb12b34968cab /llvm/lib/Support/APFloat.cpp | |
parent | 2fdf49db7562eadbe01b18f0d01a955cd41b94ea (diff) | |
download | llvm-7b308b18c3946dd0e09c661db52f70eff3fe8104.zip llvm-7b308b18c3946dd0e09c661db52f70eff3fe8104.tar.gz llvm-7b308b18c3946dd0e09c661db52f70eff3fe8104.tar.bz2 |
Fix bitcasting E8M0 APFloat to APInt (#113298)
Fixes a bug in APFloat handling of E8M0 type (zero mantissa).
Related PRs:
- https://github.com/llvm/llvm-project/pull/107127
- https://github.com/llvm/llvm-project/pull/111028
Diffstat (limited to 'llvm/lib/Support/APFloat.cpp')
-rw-r--r-- | llvm/lib/Support/APFloat.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/llvm/lib/Support/APFloat.cpp b/llvm/lib/Support/APFloat.cpp index a33b6c4..5cb6de9 100644 --- a/llvm/lib/Support/APFloat.cpp +++ b/llvm/lib/Support/APFloat.cpp @@ -408,7 +408,8 @@ exponentNaN(const fltSemantics &semantics) { if (semantics.nonFiniteBehavior == fltNonfiniteBehavior::NanOnly) { if (semantics.nanEncoding == fltNanEncoding::NegativeZero) return exponentZero(semantics); - return semantics.maxExponent; + if (semantics.hasSignedRepr) + return semantics.maxExponent; } return semantics.maxExponent + 1; } @@ -3663,7 +3664,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; } |