Skip to content

Commit

Permalink
Fixed handling of +/-0 in optimizer simplifiers for fmin/fmax/dmin/dm…
Browse files Browse the repository at this point in the history
…ax nodes

when folding the min/max nodes to constants, max(+0, -0) now correctly folds to +0, and min(+0, -0) now correctly folds to -0

Signed-off-by: Matthew Hall <[email protected]>
  • Loading branch information
matthewhall2 committed Sep 25, 2024
1 parent ce7ef51 commit 0c276e5
Showing 1 changed file with 34 additions and 6 deletions.
40 changes: 34 additions & 6 deletions compiler/optimizer/OMRSimplifierHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17762,10 +17762,24 @@ TR::Node *fmaxminSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier *
fmin = fmax = secondChild->getFloat();
else
{
if (firstChild->getFloat() <= secondChild->getFloat())
float first = firstChild->getFloat();
float second = secondChild->getFloat();
int nZeroBits = 0x80000000;
if (first <= second)
{
fmin = firstChild->getFloat();
fmax = secondChild->getFloat();
if (first == second && first == 0)
{
int firstBits = *(int *)(&first);
int secondBits = *(int *)(&second);
int sign = firstBits & nZeroBits;
fmin = sign < 0 ? first : second;
fmax = sign < 0 ? second : first;
}
else
{
fmin = firstChild->getFloat();
fmax = secondChild->getFloat();
}
}
else
{
Expand Down Expand Up @@ -17797,10 +17811,24 @@ TR::Node *dmaxminSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier *
min = max = secondChild->getDouble();
else
{
if (firstChild->getDouble() <= secondChild->getDouble())
double first = firstChild->getDouble();
double second = secondChild->getDouble();
long nZeroBits = 0x8000000000000000L;
if (first <= second)
{
min = firstChild->getDouble();
max = secondChild->getDouble();
if (first == second && first == 0)
{
long firstBits = *(long *)(&first);
long secondBits = *(long *)(&second);
long sign = firstBits & nZeroBits;
min = sign < 0 ? first : second;
max = sign < 0 ? second : first;
}
else
{
min = firstChild->getDouble();
max = secondChild->getDouble();
}
}
else
{
Expand Down

0 comments on commit 0c276e5

Please sign in to comment.