Skip to content
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

Fix fmin/fmax/dmin/dmax node simplifier for const 0s #7471

Merged
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
96 changes: 56 additions & 40 deletions compiler/optimizer/OMRSimplifierHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17752,30 +17752,38 @@ TR::Node *fmaxminSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier *
TR::Node * secondChild = node->getSecondChild();
bool isBothConst = firstChild->getOpCode().isLoadConst() && secondChild->getOpCode().isLoadConst();
float fmin = 0, fmax = 0;
bool maxOpcode = node->getOpCodeValue() == TR::fmax;
bool isMaxOpcode = node->getOpCodeValue() == TR::fmax;

if (isBothConst)
if (!isBothConst) return node;

float first = firstChild->getFloat();
float second = secondChild->getFloat();

uint32_t firstBits = firstChild->getFloatBits();
uint32_t secondBits = secondChild->getFloatBits();

// if either or both operands is a NaN, the result is the first NaN.
// +0.0f compares as strictly greater than -0.0f
if (isNaNFloat(firstChild))
hzongaro marked this conversation as resolved.
Show resolved Hide resolved
{
if (isNaNFloat(firstChild))
fmin = fmax = firstChild->getFloat();
else if (isNaNFloat(secondChild))
fmin = fmax = secondChild->getFloat();
else
{
if (firstChild->getFloat() <= secondChild->getFloat())
{
fmin = firstChild->getFloat();
fmax = secondChild->getFloat();
}
else
{
fmin = secondChild->getFloat();
fmax = firstChild->getFloat();
}
}
foldFloatConstant(node, maxOpcode ? fmax : fmin, s);
fmin = fmax = first;
}
else if (isNaNFloat(secondChild))
{
fmin = fmax = second;
}
else if (first > second || (firstBits == 0 && secondBits == FLOAT_NEG_ZERO))
{
fmax = first;
fmin = second;
}
else
{
fmax = second;
fmin = first;
}

foldFloatConstant(node, isMaxOpcode ? fmax : fmin, s);
return node;
}

Expand All @@ -17787,30 +17795,38 @@ TR::Node *dmaxminSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier *
TR::Node * firstChild = node->getFirstChild();
TR::Node * secondChild = node->getSecondChild();
bool isBothConst = firstChild->getOpCode().isLoadConst() && secondChild->getOpCode().isLoadConst();
bool maxOpcode = node->getOpCodeValue() == TR::dmax;
bool isMaxOpcode = node->getOpCodeValue() == TR::dmax;

if (isBothConst)
if (!isBothConst) return node;

double first = firstChild->getDouble();
double second = secondChild->getDouble();

uint64_t firstBits = firstChild->getDoubleBits();
uint64_t secondBits = secondChild->getDoubleBits();

// if either or both operands is a NaN, the result is the first NaN.
// +0.0d compares as strictly greater than -0.0d
if (isNaNDouble(firstChild))
{
if (isNaNDouble(firstChild))
min = max = firstChild->getDouble();
else if (isNaNDouble(secondChild))
min = max = secondChild->getDouble();
else
{
if (firstChild->getDouble() <= secondChild->getDouble())
{
min = firstChild->getDouble();
max = secondChild->getDouble();
}
else
{
min = secondChild->getDouble();
max = firstChild->getDouble();
}
}
foldDoubleConstant(node, maxOpcode ? max : min, s);
min = max = first;
}
else if (isNaNDouble(secondChild))
{
min = max = second;
}
else if (first > second || (firstBits == 0L && secondBits == DOUBLE_NEG_ZERO))
{
max = first;
min = second;
}
else
{
max = second;
min = first;
}

foldDoubleConstant(node, isMaxOpcode ? max : min, s);
return node;
}

Expand Down