This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rGc14c34de4571: [clang][Interp] Implement __builtin_fmin (authored by tbaeder).
Changed prior to commit: https://reviews.llvm.org/D155546?vs=544691&id=545228#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D155546/new/ https://reviews.llvm.org/D155546 Files: clang/lib/AST/Interp/InterpBuiltin.cpp clang/test/AST/Interp/builtin-functions.cpp Index: clang/test/AST/Interp/builtin-functions.cpp =================================================================== --- clang/test/AST/Interp/builtin-functions.cpp +++ clang/test/AST/Interp/builtin-functions.cpp @@ -60,3 +60,15 @@ // expected-note {{read of dereferenced one-past-the-end pointer}} \ // expected-note {{in call to}} } + +namespace fmin { + constexpr float f1 = __builtin_fmin(1.0, 2.0f); + static_assert(f1 == 1.0f, ""); + + constexpr float min = __builtin_fmin(__builtin_nan(""), 1); + static_assert(min == 1, ""); + constexpr float min2 = __builtin_fmin(1, __builtin_nan("")); + static_assert(min2 == 1, ""); + constexpr float min3 = __builtin_fmin(__builtin_inf(), __builtin_nan("")); + static_assert(min3 == __builtin_inf(), ""); +} Index: clang/lib/AST/Interp/InterpBuiltin.cpp =================================================================== --- clang/lib/AST/Interp/InterpBuiltin.cpp +++ clang/lib/AST/Interp/InterpBuiltin.cpp @@ -143,6 +143,25 @@ return true; } +static bool interp__builtin_fmin(InterpState &S, CodePtr OpPC, + const InterpFrame *Frame, const Function *F) { + 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 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); + return true; +} + bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F) { InterpFrame *Frame = S.Current; APValue Dummy; @@ -195,6 +214,15 @@ return Ret<PT_Float>(S, OpPC, Dummy); break; + case Builtin::BI__builtin_fmin: + case Builtin::BI__builtin_fminf: + case Builtin::BI__builtin_fminl: + case Builtin::BI__builtin_fminf16: + case Builtin::BI__builtin_fminf128: + if (interp__builtin_fmin(S, OpPC, Frame, F)) + return Ret<PT_Float>(S, OpPC, Dummy); + break; + default: return false; }
Index: clang/test/AST/Interp/builtin-functions.cpp =================================================================== --- clang/test/AST/Interp/builtin-functions.cpp +++ clang/test/AST/Interp/builtin-functions.cpp @@ -60,3 +60,15 @@ // expected-note {{read of dereferenced one-past-the-end pointer}} \ // expected-note {{in call to}} } + +namespace fmin { + constexpr float f1 = __builtin_fmin(1.0, 2.0f); + static_assert(f1 == 1.0f, ""); + + constexpr float min = __builtin_fmin(__builtin_nan(""), 1); + static_assert(min == 1, ""); + constexpr float min2 = __builtin_fmin(1, __builtin_nan("")); + static_assert(min2 == 1, ""); + constexpr float min3 = __builtin_fmin(__builtin_inf(), __builtin_nan("")); + static_assert(min3 == __builtin_inf(), ""); +} Index: clang/lib/AST/Interp/InterpBuiltin.cpp =================================================================== --- clang/lib/AST/Interp/InterpBuiltin.cpp +++ clang/lib/AST/Interp/InterpBuiltin.cpp @@ -143,6 +143,25 @@ return true; } +static bool interp__builtin_fmin(InterpState &S, CodePtr OpPC, + const InterpFrame *Frame, const Function *F) { + 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 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); + return true; +} + bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F) { InterpFrame *Frame = S.Current; APValue Dummy; @@ -195,6 +214,15 @@ return Ret<PT_Float>(S, OpPC, Dummy); break; + case Builtin::BI__builtin_fmin: + case Builtin::BI__builtin_fminf: + case Builtin::BI__builtin_fminl: + case Builtin::BI__builtin_fminf16: + case Builtin::BI__builtin_fminf128: + if (interp__builtin_fmin(S, OpPC, Frame, F)) + return Ret<PT_Float>(S, OpPC, Dummy); + break; + default: return false; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits