Skip to content

Clang: ExprConstant use maxnum/minnum for fmax/fmin #129630

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

wzssyqa
Copy link
Contributor

@wzssyqa wzssyqa commented Mar 4, 2025

In APFloat, we have defined maxnum and minnum, so let's use them directly here.

In maxnum/minnum of APFloat, we process sNaN, signed-zero as strictly as possible.

@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: YunQiang Su (wzssyqa)

Changes

In APFloat, we have defined maxnum and minnum, so let's use them directly here.


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

1 Files Affected:

  • (modified) clang/lib/AST/ExprConstant.cpp (+2-11)
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index ef1d763009453..10076a69290f2 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -15609,11 +15609,7 @@ bool FloatExprEvaluator::VisitCallExpr(const CallExpr *E) {
     if (!EvaluateFloat(E->getArg(0), Result, Info) ||
         !EvaluateFloat(E->getArg(1), RHS, Info))
       return false;
-    // When comparing zeroes, return +0.0 if one of the zeroes is positive.
-    if (Result.isZero() && RHS.isZero() && Result.isNegative())
-      Result = RHS;
-    else if (Result.isNaN() || RHS > Result)
-      Result = RHS;
+    Result = maxnum(Result, RHS);
     return true;
   }
 
@@ -15622,16 +15618,11 @@ bool FloatExprEvaluator::VisitCallExpr(const CallExpr *E) {
   case Builtin::BI__builtin_fminl:
   case Builtin::BI__builtin_fminf16:
   case Builtin::BI__builtin_fminf128: {
-    // TODO: Handle sNaN.
     APFloat RHS(0.);
     if (!EvaluateFloat(E->getArg(0), Result, Info) ||
         !EvaluateFloat(E->getArg(1), RHS, Info))
       return false;
-    // When comparing zeroes, return -0.0 if one of the zeroes is negative.
-    if (Result.isZero() && RHS.isZero() && RHS.isNegative())
-      Result = RHS;
-    else if (Result.isNaN() || RHS < Result)
-      Result = RHS;
+    Result = minnum(Result, RHS);
     return true;
   }
 

@wzssyqa wzssyqa requested a review from arsenm March 4, 2025 02:16
In APFloat, we have defined maxnum and minnum, so let's use them
directly here.
@wzssyqa wzssyqa force-pushed the clang-expr-maxnum branch from b76717f to 9498907 Compare March 4, 2025 02:17
@wzssyqa wzssyqa merged commit 50ff49e into llvm:main Mar 4, 2025
11 checks passed
@wzssyqa wzssyqa deleted the clang-expr-maxnum branch March 4, 2025 04:26
tbaederr added a commit to tbaederr/llvm-project that referenced this pull request Mar 4, 2025
Equivalent of llvm#129630 for
the bytecode interpreter.
tbaederr added a commit that referenced this pull request Mar 4, 2025
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Mar 4, 2025
jph-13 pushed a commit to jph-13/llvm-project that referenced this pull request Mar 21, 2025
In APFloat, we have defined maxnum and minnum, so let's use them
directly here.

In `maxnum`/`minnum` of APFloat, we process sNaN, signed-zero as
strictly as possible.
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.

3 participants