[libc-commits] [libc] [libc][math] Fix some mis-optimization issue with hypotf16. (PR #141960)

via libc-commits libc-commits at lists.llvm.org
Thu May 29 08:03:13 PDT 2025


https://github.com/lntue created https://github.com/llvm/llvm-project/pull/141960

None

>From 51038f9949e3fd6246ac847c6c42ec2882d70987 Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue.h at gmail.com>
Date: Thu, 29 May 2025 14:57:56 +0000
Subject: [PATCH] [libc][math] Fix some mis-optimization issue with hypotf16.

---
 libc/src/math/generic/hypotf16.cpp | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libc/src/math/generic/hypotf16.cpp b/libc/src/math/generic/hypotf16.cpp
index 8f80986204b27..d782c2687cdb6 100644
--- a/libc/src/math/generic/hypotf16.cpp
+++ b/libc/src/math/generic/hypotf16.cpp
@@ -48,10 +48,13 @@ LLVM_LIBC_FUNCTION(float16, hypotf16, (float16 x, float16 y)) {
     return a_bits.get_val();
   }
 
+  // TODO: Investigate why replacing the return line below with:
+  //   return x_bits.get_val() + y_bits.get_val();
+  // fails the hypotf16 smoke tests.
   if (LIBC_UNLIKELY(a_u - b_u >=
                     static_cast<uint16_t>((FPBits::FRACTION_LEN + 2)
                                           << FPBits::FRACTION_LEN)))
-    return x_abs.get_val() + y_abs.get_val();
+    return a_bits.get_val() + b_bits.get_val();
 
   float af = fputil::cast<float>(a_bits.get_val());
   float bf = fputil::cast<float>(b_bits.get_val());



More information about the libc-commits mailing list