Skip to content

[libc][math] Fix some mis-optimization issue with hypotf16. #141960

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

Merged
merged 1 commit into from
May 29, 2025

Conversation

lntue
Copy link
Contributor

@lntue lntue commented May 29, 2025

No description provided.

@llvmbot
Copy link
Member

llvmbot commented May 29, 2025

@llvm/pr-subscribers-libc

Author: None (lntue)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/141960.diff

1 Files Affected:

  • (modified) libc/src/math/generic/hypotf16.cpp (+4-1)
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());

@lntue lntue merged commit 062d24a into llvm:main May 29, 2025
15 of 17 checks passed
@lntue lntue deleted the hypotf16 branch May 29, 2025 15:34
google-yfyang pushed a commit to google-yfyang/llvm-project that referenced this pull request May 29, 2025
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Jun 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants