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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 8 additions & 30 deletions clang/lib/AST/ByteCode/InterpBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down
Loading