This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG89e44e33edec: [clang][Interp] Implement __builtin_fmax 
(authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155401/new/

https://reviews.llvm.org/D155401

Files:
  clang/lib/AST/Interp/InterpBuiltin.cpp
  clang/test/Sema/constant-builtins-fmax.cpp


Index: clang/test/Sema/constant-builtins-fmax.cpp
===================================================================
--- clang/test/Sema/constant-builtins-fmax.cpp
+++ clang/test/Sema/constant-builtins-fmax.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify 
-fexperimental-new-constant-interpreter %s
 // expected-no-diagnostics
 
 constexpr double NaN = __builtin_nan("");
Index: clang/lib/AST/Interp/InterpBuiltin.cpp
===================================================================
--- clang/lib/AST/Interp/InterpBuiltin.cpp
+++ clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -173,6 +173,26 @@
   return true;
 }
 
+static bool interp__builtin_fmax(InterpState &S, CodePtr OpPC,
+                                 const InterpFrame *Frame,
+                                 const Function *Func) {
+  const Floating &LHS = getParam<Floating>(Frame, 0);
+  const Floating &RHS = getParam<Floating>(Frame, 1);
+
+  Floating Result;
+
+  // 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);
+  return true;
+}
+
 /// Defined as __builtin_isnan(...), to accommodate the fact that it can
 /// take a float, double, long double, etc.
 /// But for us, that's all a Floating anyway.
@@ -341,6 +361,15 @@
       return Ret<PT_Float>(S, OpPC, Dummy);
     break;
 
+  case Builtin::BI__builtin_fmax:
+  case Builtin::BI__builtin_fmaxf:
+  case Builtin::BI__builtin_fmaxl:
+  case Builtin::BI__builtin_fmaxf16:
+  case Builtin::BI__builtin_fmaxf128:
+    if (interp__builtin_fmax(S, OpPC, Frame, F))
+      return Ret<PT_Float>(S, OpPC, Dummy);
+    break;
+
   case Builtin::BI__builtin_isnan:
     if (interp__builtin_isnan(S, OpPC, Frame, F))
       return Ret<PT_Sint32>(S, OpPC, Dummy);


Index: clang/test/Sema/constant-builtins-fmax.cpp
===================================================================
--- clang/test/Sema/constant-builtins-fmax.cpp
+++ clang/test/Sema/constant-builtins-fmax.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify -fexperimental-new-constant-interpreter %s
 // expected-no-diagnostics
 
 constexpr double NaN = __builtin_nan("");
Index: clang/lib/AST/Interp/InterpBuiltin.cpp
===================================================================
--- clang/lib/AST/Interp/InterpBuiltin.cpp
+++ clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -173,6 +173,26 @@
   return true;
 }
 
+static bool interp__builtin_fmax(InterpState &S, CodePtr OpPC,
+                                 const InterpFrame *Frame,
+                                 const Function *Func) {
+  const Floating &LHS = getParam<Floating>(Frame, 0);
+  const Floating &RHS = getParam<Floating>(Frame, 1);
+
+  Floating Result;
+
+  // 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);
+  return true;
+}
+
 /// Defined as __builtin_isnan(...), to accommodate the fact that it can
 /// take a float, double, long double, etc.
 /// But for us, that's all a Floating anyway.
@@ -341,6 +361,15 @@
       return Ret<PT_Float>(S, OpPC, Dummy);
     break;
 
+  case Builtin::BI__builtin_fmax:
+  case Builtin::BI__builtin_fmaxf:
+  case Builtin::BI__builtin_fmaxl:
+  case Builtin::BI__builtin_fmaxf16:
+  case Builtin::BI__builtin_fmaxf128:
+    if (interp__builtin_fmax(S, OpPC, Frame, F))
+      return Ret<PT_Float>(S, OpPC, Dummy);
+    break;
+
   case Builtin::BI__builtin_isnan:
     if (interp__builtin_isnan(S, OpPC, Frame, F))
       return Ret<PT_Sint32>(S, OpPC, Dummy);
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to