From 0c276e5dcbf101c0f595391c1a55a4eeecc5f6d7 Mon Sep 17 00:00:00 2001 From: Matthew Hall Date: Wed, 25 Sep 2024 10:06:21 -0400 Subject: [PATCH] Fixed handling of +/-0 in optimizer simplifiers for fmin/fmax/dmin/dmax 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 --- compiler/optimizer/OMRSimplifierHandlers.cpp | 40 +++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/compiler/optimizer/OMRSimplifierHandlers.cpp b/compiler/optimizer/OMRSimplifierHandlers.cpp index b53b85afa01..4518f171ffa 100644 --- a/compiler/optimizer/OMRSimplifierHandlers.cpp +++ b/compiler/optimizer/OMRSimplifierHandlers.cpp @@ -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 { @@ -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 {