Skip to content

[clang][bytecode][NFC] Use maxnum/minnum for fmax/fmin #129643

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
Mar 4, 2025

Conversation

tbaederr
Copy link
Contributor

@tbaederr tbaederr commented Mar 4, 2025

Equivalent of #129630 for the bytecode interpreter.

Equivalent of llvm#129630 for
the bytecode interpreter.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Mar 4, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 4, 2025

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

Changes

Equivalent of #129630 for the bytecode interpreter.


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

1 Files Affected:

  • (modified) clang/lib/AST/ByteCode/InterpBuiltin.cpp (+8-30)
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index b964906fb6594..df9c2bc24b15f 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -397,21 +397,10 @@ static bool interp__builtin_fmin(InterpState &S, CodePtr OpPC,
   const Floating &LHS = getParam<Floating>(Frame, 0);
   const Floating &RHS = getParam<Floating>(Frame, 1);
 
-  Floating Result;
-
-  if (IsNumBuiltin) {
-    Result = llvm::minimumnum(LHS.getAPFloat(), RHS.getAPFloat());
-  } else {
-    // When comparing zeroes, return -0.0 if one of the zeroes is negative.
-    if (LHS.isZero() && RHS.isZero() && RHS.isNegative())
-      Result = RHS;
-    else if (LHS.isNan() || RHS < LHS)
-      Result = RHS;
-    else
-      Result = LHS;
-  }
-
-  S.Stk.push<Floating>(Result);
+  if (IsNumBuiltin)
+    S.Stk.push<Floating>(llvm::minimumnum(LHS.getAPFloat(), RHS.getAPFloat()));
+  else
+    S.Stk.push<Floating>(minnum(LHS.getAPFloat(), RHS.getAPFloat()));
   return true;
 }
 
@@ -421,21 +410,10 @@ static bool interp__builtin_fmax(InterpState &S, CodePtr OpPC,
   const Floating &LHS = getParam<Floating>(Frame, 0);
   const Floating &RHS = getParam<Floating>(Frame, 1);
 
-  Floating Result;
-
-  if (IsNumBuiltin) {
-    Result = llvm::maximumnum(LHS.getAPFloat(), RHS.getAPFloat());
-  } else {
-    // When comparing zeroes, return +0.0 if one of the zeroes is positive.
-    if (LHS.isZero() && RHS.isZero() && LHS.isNegative())
-      Result = RHS;
-    else if (LHS.isNan() || RHS > LHS)
-      Result = RHS;
-    else
-      Result = LHS;
-  }
-
-  S.Stk.push<Floating>(Result);
+  if (IsNumBuiltin)
+    S.Stk.push<Floating>(llvm::maximumnum(LHS.getAPFloat(), RHS.getAPFloat()));
+  else
+    S.Stk.push<Floating>(maxnum(LHS.getAPFloat(), RHS.getAPFloat()));
   return true;
 }
 

@tbaederr tbaederr merged commit e9fe95a into llvm:main Mar 4, 2025
14 checks passed
jph-13 pushed a commit to jph-13/llvm-project that referenced this pull request Mar 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants