From f4e05e81fc6515520d18344cfba6d3d5a1e58242 Mon Sep 17 00:00:00 2001 From: James You Date: Mon, 11 Dec 2023 04:53:37 +0000 Subject: [PATCH] Refactor Binary Identity Simplification Macro This commit cleans up the BINARY_IDENTITY_OP and BIANRY_IDENTITY_OR_ZERO macros and replaces them with inline equivalents that use TR::DataTypes to signal which type to use for operation. Fixes: #7166 Signed-off-by: James You --- compiler/optimizer/OMRSimplifierHandlers.cpp | 322 ++++++++++++++----- compiler/optimizer/OMRSimplifierHelpers.hpp | 11 - 2 files changed, 240 insertions(+), 93 deletions(-) diff --git a/compiler/optimizer/OMRSimplifierHandlers.cpp b/compiler/optimizer/OMRSimplifierHandlers.cpp index d7f9054ea6d..5047e689ea3 100644 --- a/compiler/optimizer/OMRSimplifierHandlers.cpp +++ b/compiler/optimizer/OMRSimplifierHandlers.cpp @@ -137,32 +137,125 @@ node); \ } +int8_t getNodeByteValue(TR::Node * node) + { + return node->getByte(); + } + +int16_t getNodeShortValue(TR::Node * node) + { + return node->getShortInt(); + } + +int32_t getNodeIntValue(TR::Node * node) + { + return node->getInt(); + } + +int64_t getNodeLongValue(TR::Node * node) + { + return node->getLongInt(); + } + +uint32_t getNodeFloatBits(TR::Node * node) + { + return node->getFloatBits(); + } + +uint64_t getNodeDoubleBits(TR::Node * node) + { + return node->getDoubleBits(); + } + +void setNodeByteValue(TR::Node * node, int8_t value) + { + node->setByte(value); + } + +void setNodeShortValue(TR::Node * node, int16_t value) + { + node->setShortInt(value); + } + +void setNodeIntValue(TR::Node * node, int32_t value) + { + node->setInt(value); + } + +void setNodeLongValue(TR::Node * node, int64_t value) + { + node->setLongInt(value); + } + +void setNodeFloatBits(TR::Node * node, uint32_t bits) + { + node->setFloatBits(bits); + } + +void setNodeDoubleBits(TR::Node * node, uint64_t bits) + { + node->getDoubleBits(); + } + +inline bool isNodeLoadConst(TR::Node * node) + { + return node != NULL && node->getOpCode().isLoadConst(); + } + /** * Binary identity or zero operation * * If the second child is a constant that represents an identity operation, * replace this node with the first child. + * Binary zero operation * * If the second child is a constant that represents a zero operation, * replace this node with the second child. */ -#define BINARY_IDENTITY_OR_ZERO_OP(ConstType,Type,NullValue,ZeroValue)\ - if(secondChild->getOpCode().isLoadConst())\ - {\ - ConstType value = secondChild->get##Type();\ - if(value == NullValue)\ - return s->replaceNodeWithChild(node, firstChild, s->_curTree, block);\ - if(value == ZeroValue)\ - {\ - if(performTransformation(s->comp(), "%sFound op with iconst in node [" POINTER_PRINTF_FORMAT "]\n", s->optDetailString(),node))\ - {\ - s->anchorChildren(node, s->_curTree);\ - s->prepareToReplaceNode(node, secondChild->getOpCodeValue());\ - node->set##Type(value);\ - return node;\ - }\ - }\ - } +template +inline TR::Node * tryAndSimplifyBinaryIdentityOrZeroOp(TR::Simplifier * s, T (* getNodeValue)(TR::Node*), void (* setNodeValue)(TR::Node *, T), TR::Node * node, TR::Block * block, T nullValue, T zeroValue) + { + auto secondChild = node->getSecondChild(); + if (!isNodeLoadConst(secondChild)) + return NULL; + + auto value = getNodeValue(node); + + if (value == nullValue) + return s->replaceNodeWithChild(node, node->getFirstChild(), s->_curTree, block); + + if (value != zeroValue) + return NULL; + + if(performTransformation(s->comp(), "%sFound op with iconst in node [" POINTER_PRINTF_FORMAT "]\n", s->optDetailString(),node))\ + { + s->anchorChildren(node, s->_curTree); + s->prepareToReplaceNode(node, secondChild->getOpCodeValue()); + + setNodeValue(node, value); + return node; + } + + return NULL; + } + + /** + * Binary identity operation + * + * If the second child is a constant that represents an identity operation, + * replace this node with the first child. + */ +template +inline TR::Node * tryAndSimplifyBinaryIdentityOp(TR::Simplifier * s, T (* getNodeValue)(TR::Node*), TR::Node * node, T nullValue) { + auto secondChild = node->getSecondChild(); + if (!isNodeLoadConst(secondChild)) + return NULL; + + if (getNodeValue(secondChild) != nullValue) + return NULL; + + return s->replaceNode(node, node->getFirstChild(), s->_curTree); +} static TR::ILOpCodes addOps[TR::NumAllTypes] = { TR::BadILOp, TR::badd, TR::sadd, TR::iadd, TR::ladd, @@ -6021,7 +6114,9 @@ TR::Node *iaddSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) return node; } - BINARY_IDENTITY_OP(Int, 0) + if (auto identity = tryAndSimplifyBinaryIdentityOp(s, getNodeIntValue, node, 0)) + return identity; + TR::ILOpCodes firstChildOp = firstChild->getOpCodeValue(); TR::ILOpCodes secondChildOp = secondChild->getOpCodeValue(); TR::ILOpCodes nodeOp = node->getOpCodeValue(); @@ -6452,7 +6547,9 @@ TR::Node *laddSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) return node; } - BINARY_IDENTITY_OP(LongInt, 0L) + if (auto identity = tryAndSimplifyBinaryIdentityOp(s, getNodeLongValue, node, 0L)) + return identity; + TR::ILOpCodes firstChildOp = firstChild->getOpCodeValue(); TR::ILOpCodes secondChildOp = secondChild->getOpCodeValue(); // normalize adds of positive constants to be isubs. Have to do it this way because @@ -6704,20 +6801,11 @@ TR::Node *faddSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) orderChildren(node, firstChild, secondChild, s); - // In IEEE FP Arithmetic, f + 0.0 is f - // Pretend to be an int before doing the comparison - // The simplification was removed because when f=-0.0 - // the result of f+(+0.0) is +0.0 (and not f) - // If we would have ranges about f we might use the simplification in some cases - // BINARY_IDENTITY_OP(Int, FLOAT_POS_ZERO) - // In IEEE FP Arithmetic, f + -0.0 is f // Pretend to be an int before doing the comparison // - BINARY_IDENTITY_OP(FloatBits, FLOAT_NEG_ZERO) - - firstChild = node->getFirstChild(); - secondChild = node->getSecondChild(); + if (auto identity = tryAndSimplifyBinaryIdentityOp(s, getNodeFloatBits, node, FLOAT_NEG_ZERO)) + return identity; return node; } @@ -6744,11 +6832,12 @@ TR::Node *daddSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) // Pretend to be an int before doing the comparison // // According to the java spec -0.0 + 0.0 == 0.0 - // BINARY_IDENTITY_OP(LongInt, DOUBLE_POS_ZERO) // In IEEE FP Arithmetic, d + -0.0 is d // Pretend to be an int before doing the comparison // - BINARY_IDENTITY_OP(LongInt, DOUBLE_NEG_ZERO) + auto identity = tryAndSimplifyBinaryIdentityOp(s, getNodeDoubleBits, node, DOUBLE_NEG_ZERO); + if (identity) + return identity; return node; } @@ -6799,8 +6888,13 @@ TR::Node *isubSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) return node; } - if (!node->nodeRequiresConditionCodes()) // don't do identity op on cc nodes on zemulator - BINARY_IDENTITY_OP(Int, 0) + // don't do identity op on cc nodes on zemulator + if (!node->nodeRequiresConditionCodes()) + { + auto identity = tryAndSimplifyBinaryIdentityOp(s, getNodeIntValue, node, 0); + if (identity) + return identity; + } TR::ILOpCodes secondChildOp = secondChild->getOpCodeValue(); TR::ILOpCodes firstChildOp = firstChild->getOpCodeValue(); @@ -7252,7 +7346,10 @@ TR::Node *lsubSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) } if (!node->nodeRequiresConditionCodes()) - BINARY_IDENTITY_OP(LongInt, 0L) + { + if (auto identity = tryAndSimplifyBinaryIdentityOp(s, getNodeLongValue, node, 0L)) + return identity; + } TR::ILOpCodes firstChildOp = firstChild->getOpCodeValue(); TR::ILOpCodes secondChildOp = secondChild->getOpCodeValue(); @@ -7812,17 +7909,8 @@ TR::Node *fsubSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) // In IEEE FP Arithmetic, f - 0.0 is f // Pretend to be an int before doing the comparison // - BINARY_IDENTITY_OP(FloatBits, FLOAT_POS_ZERO) - - // In IEEE FP Arithmetic, f - -0.0 is f - // Pretend to be an int before doing the comparison - // The simplification was removed because when f=-0.0 - // the result of f-(-0.0) is +0.0 (and not f) - // If we would have ranges about f we might use the simplification in some cases - // BINARY_IDENTITY_OP(Int, FLOAT_NEG_ZERO) - - firstChild = node->getFirstChild(); - secondChild = node->getSecondChild(); + if (auto identity = tryAndSimplifyBinaryIdentityOp(s, getNodeFloatBits, node, FLOAT_POS_ZERO)) + return identity; return node; } @@ -7847,11 +7935,12 @@ TR::Node *dsubSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) // Pretend to be an int before doing the comparison // // According to the java spec -0.0 - (-0.0) == 0.0 - // BINARY_IDENTITY_OP(LongInt, DOUBLE_NEG_ZERO) // In IEEE FP Arithmetic, d - -0.0 is d // Pretend to be an int before doing the comparison // - BINARY_IDENTITY_OP(LongInt, DOUBLE_POS_ZERO) + auto identity = tryAndSimplifyBinaryIdentityOp(s, getNodeDoubleBits, node, DOUBLE_POS_ZERO); + if (identity) + return identity; return node; } @@ -7890,7 +7979,10 @@ TR::Node *imulSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) } orderChildren(node, firstChild, secondChild, s); - BINARY_IDENTITY_OR_ZERO_OP(int32_t, Int, 1, 0) + + + if (auto result = tryAndSimplifyBinaryIdentityOrZeroOp(s, getNodeIntValue, setNodeIntValue, node, block, 1, 0)) + return result; TR::ILOpCodes firstChildOp = firstChild->getOpCodeValue(); TR::ILOpCodes secondChildOp = secondChild->getOpCodeValue(); @@ -8255,7 +8347,9 @@ TR::Node *lmulSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) orderChildren(node, firstChild, secondChild, s); orderChildrenByHighWordZero(node, firstChild, secondChild, s); - BINARY_IDENTITY_OR_ZERO_OP(int64_t, LongInt, 1L, 0L) + + if (auto result = tryAndSimplifyBinaryIdentityOrZeroOp(s, getNodeLongValue, setNodeLongValue, node, block, 1L, 0L)) + return result; // TODO - strength reduction TR::ILOpCodes firstChildOp = firstChild->getOpCodeValue(); @@ -8472,7 +8566,9 @@ TR::Node *fmulSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) // In IEEE FP Arithmetic, f * 1.0 is f // Pretend to be an int before doing the comparison // - BINARY_IDENTITY_OP(FloatBits, FLOAT_ONE) + auto identity = tryAndSimplifyBinaryIdentityOp(s, getNodeFloatBits, node, FLOAT_ONE); + if (identity) + return identity; } firstChild = node->getFirstChild(); @@ -8520,7 +8616,8 @@ TR::Node *dmulSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) // In IEEE FP Arithmetic, d * 1.0 is d // Pretend to be an int before doing the comparison // - BINARY_IDENTITY_OP(LongInt, DOUBLE_ONE) + if (auto identity = tryAndSimplifyBinaryIdentityOp(s, getNodeLongValue, node, (int64_t) DOUBLE_ONE)) + return identity; } return node; } @@ -8538,7 +8635,9 @@ TR::Node *bmulSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) } orderChildren(node, firstChild, secondChild, s); - BINARY_IDENTITY_OR_ZERO_OP(int8_t, Byte, 1, 0) + + if (auto result = tryAndSimplifyBinaryIdentityOrZeroOp(s, getNodeByteValue, setNodeByteValue, node, block, 1, 0)) + return result; // TODO - strength reduction @@ -8558,7 +8657,9 @@ TR::Node *smulSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) } orderChildren(node, firstChild, secondChild, s); - BINARY_IDENTITY_OR_ZERO_OP(int16_t, ShortInt, 1, 0) + + if (auto result = tryAndSimplifyBinaryIdentityOrZeroOp(s, getNodeShortValue, setNodeShortValue, node, block, 1, 0)) + return result; // TODO - strength reduction @@ -9189,7 +9290,8 @@ TR::Node *fdivSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) // In IEEE FP Arithmetic, f / 1.0 is f // Pretend to be an int before doing the comparison // - BINARY_IDENTITY_OP(FloatBits, FLOAT_ONE) + if (auto identity = tryAndSimplifyBinaryIdentityOp(s, getNodeFloatBits, node, FLOAT_ONE)) + return identity; firstChild = node->getFirstChild(); secondChild = node->getSecondChild(); @@ -9246,7 +9348,9 @@ TR::Node *ddivSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) // In IEEE FP Arithmetic, d / 1.0 is d // Pretend to be an int before doing the comparison // - BINARY_IDENTITY_OP(LongInt, DOUBLE_ONE) + if (auto identity = tryAndSimplifyBinaryIdentityOp(s, getNodeLongValue, node, (int64_t) DOUBLE_ONE)) + return identity; + return node; } @@ -9273,7 +9377,8 @@ TR::Node *bdivSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) } // Handle the possibility of a division by constant value one - BINARY_IDENTITY_OP(Byte, 1) + if (auto identity = tryAndSimplifyBinaryIdentityOp(s, getNodeByteValue, node, 1)) + return identity; } return node; @@ -9305,7 +9410,8 @@ TR::Node *sdivSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) } // Handle the possibility of a division by constant value one - BINARY_IDENTITY_OP(ShortInt, 1) + if (auto identity = tryAndSimplifyBinaryIdentityOp(s, getNodeShortValue, node, 1)) + return identity; } return node; @@ -10081,7 +10187,9 @@ TR::Node *ishlSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) } normalizeConstantShiftAmount(node, INT_SHIFT_MASK, secondChild, s); - BINARY_IDENTITY_OP(Int, 0) + + if (auto identity = tryAndSimplifyBinaryIdentityOp(s, getNodeIntValue, node, 0)) + return identity; if (secondChild->getOpCode().isLoadConst() && performTransformation(s->comp(), "%sChanged ishl by const into imul by const in node [%s]\n", s->optDetailString(), node->getName(s->getDebug()))) @@ -10119,7 +10227,9 @@ TR::Node *lshlSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) } normalizeConstantShiftAmount(node, LONG_SHIFT_MASK, secondChild, s); - BINARY_IDENTITY_OP(Int, 0) + + if (auto identity = tryAndSimplifyBinaryIdentityOp(s, getNodeIntValue, node, 0)) + return identity; if (secondChild->getOpCode().isLoadConst()) { @@ -10160,7 +10270,9 @@ TR::Node *bshlSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) return node; } - BINARY_IDENTITY_OP(Int, 0) + if (auto identity = tryAndSimplifyBinaryIdentityOp(s, getNodeIntValue, node, 0)) + return identity; + return node; } @@ -10175,7 +10287,10 @@ TR::Node *sshlSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) foldShortIntConstant(node, firstChild->getShortInt()<<(secondChild->getInt() & INT_SHIFT_MASK), s, false /* !anchorChildren */); return node; } - BINARY_IDENTITY_OP(Int, 0) + + if (auto identity = tryAndSimplifyBinaryIdentityOp(s, getNodeIntValue, node, 0)) + return identity; + return node; } @@ -10196,7 +10311,9 @@ TR::Node *ishrSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) } normalizeConstantShiftAmount(node, INT_SHIFT_MASK, secondChild, s); - BINARY_IDENTITY_OP(Int, 0) + + if (auto identity = tryAndSimplifyBinaryIdentityOp(s, getNodeIntValue, node, 0)) + return identity; normalizeShiftAmount(node, 31, s); @@ -10216,7 +10333,9 @@ TR::Node *lshrSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) } normalizeConstantShiftAmount(node, LONG_SHIFT_MASK, secondChild, s); - BINARY_IDENTITY_OP(Int, 0) + + if (auto identity = tryAndSimplifyBinaryIdentityOp(s, getNodeIntValue, node, 0)) + return identity; normalizeShiftAmount(node, 63, s); @@ -10235,7 +10354,9 @@ TR::Node *bshrSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) return node; } - BINARY_IDENTITY_OP(Int, 0) + if (auto identity =tryAndSimplifyBinaryIdentityOp(s, getNodeIntValue, node, 0)) + return identity; + return node; } @@ -10250,7 +10371,9 @@ TR::Node *sshrSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) foldShortIntConstant(node, firstChild->getShortInt()>>(secondChild->getInt() & INT_SHIFT_MASK), s, false /* !anchorChildren */); return node; } - BINARY_IDENTITY_OP(Int, 0) + + if (auto identity =tryAndSimplifyBinaryIdentityOp(s, getNodeIntValue, node, 0)) + return identity; return node; } @@ -10272,8 +10395,9 @@ TR::Node *iushrSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s } normalizeConstantShiftAmount(node, INT_SHIFT_MASK, secondChild, s); - BINARY_IDENTITY_OP(Int, 0) + if (auto identity = tryAndSimplifyBinaryIdentityOp(s, getNodeIntValue, node, 0)) + return identity; // look for bogus code sequence used in compress to zero extend a short // using two shifts. Also catches pairs of shifts that can be performed @@ -10400,7 +10524,9 @@ TR::Node *lushrSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s } normalizeConstantShiftAmount(node, LONG_SHIFT_MASK, secondChild, s); - BINARY_IDENTITY_OP(Int, 0) + + if (auto identity =tryAndSimplifyBinaryIdentityOp(s, getNodeIntValue, node, 0)) + return identity; // look for bogus code sequence used in compress to zero extend a short // using two shifts. Also catches pairs of shifts that can be performed @@ -10496,7 +10622,9 @@ TR::Node *bushrSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s return node; } - BINARY_IDENTITY_OP(Int, 0) + if (auto identity = tryAndSimplifyBinaryIdentityOp(s, getNodeIntValue, node, 0)) + return identity; + return node; } @@ -10511,7 +10639,9 @@ TR::Node *sushrSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s foldShortIntConstant(node, firstChild->getUnsignedShortInt()>>(secondChild->getInt() & INT_SHIFT_MASK), s, false /* !anchorChildren */); return node; } - BINARY_IDENTITY_OP(Int, 0) + + if (auto identity = tryAndSimplifyBinaryIdentityOp(s, getNodeLongValue, node, 0L)) + return identity; return node; } @@ -10586,7 +10716,9 @@ TR::Node *iandSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) } orderChildren(node, firstChild, secondChild, s); - BINARY_IDENTITY_OR_ZERO_OP(int32_t, Int, -1, 0) + + if (auto result = tryAndSimplifyBinaryIdentityOrZeroOp(s, getNodeIntValue, setNodeIntValue, node, block, -1, 0)) + return result; if (TR::Node* foldedNode = tryFoldAndWidened(s, node)) { @@ -10734,7 +10866,10 @@ TR::Node *landSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) orderChildren(node, firstChild, secondChild, s); orderChildrenByHighWordZero(node, firstChild, secondChild, s); - BINARY_IDENTITY_OR_ZERO_OP(int64_t, LongInt, -1L, 0L) + + if (auto result = tryAndSimplifyBinaryIdentityOrZeroOp(s, getNodeLongValue, setNodeLongValue, node, block, -1L, 0L)) + return result; + if (TR::Node* foldedNode = tryFoldAndWidened(s, node)) { @@ -10931,7 +11066,10 @@ TR::Node *bandSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) } orderChildren(node, firstChild, secondChild, s); - BINARY_IDENTITY_OR_ZERO_OP(int8_t, Byte, -1, 0) + + if (auto result = tryAndSimplifyBinaryIdentityOrZeroOp(s, getNodeByteValue, setNodeByteValue, node, block, -1, 0)) + return result; + return node; } @@ -10947,7 +11085,9 @@ TR::Node *sandSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) return node; } orderChildren(node, firstChild, secondChild, s); - BINARY_IDENTITY_OR_ZERO_OP(int16_t, ShortInt, -1, 0) + + if (auto result = tryAndSimplifyBinaryIdentityOrZeroOp(s, getNodeShortValue, setNodeShortValue, node, block, -1, 0)) + return result; if (TR::Node* foldedNode = tryFoldAndWidened(s, node)) { @@ -11111,7 +11251,10 @@ TR::Node *iorSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) return node; } - BINARY_IDENTITY_OR_ZERO_OP(int32_t, Int, 0, -1) + + if (auto result = tryAndSimplifyBinaryIdentityOrZeroOp(s, getNodeIntValue, setNodeIntValue, node, block, 0, -1)) + return result; + TR::ILOpCodes firstChildOp = firstChild->getOpCodeValue(); TR::ILOpCodes secondChildOp = secondChild->getOpCodeValue(); @@ -11252,7 +11395,9 @@ TR::Node *lorSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) return node; } - BINARY_IDENTITY_OR_ZERO_OP(int64_t, LongInt, 0L, -1L) + if (auto result = tryAndSimplifyBinaryIdentityOrZeroOp(s, getNodeLongValue, setNodeLongValue, node, block, 0L, -1L)) + return result; + TR::ILOpCodes firstChildOp = firstChild->getOpCodeValue(); TR::ILOpCodes secondChildOp = secondChild->getOpCodeValue(); @@ -11443,7 +11588,10 @@ TR::Node *borSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) node->setVisitCount(0); s->_alteredBlock = true; } - BINARY_IDENTITY_OR_ZERO_OP(int8_t, Byte, 0, -1) + + if (auto result = tryAndSimplifyBinaryIdentityOrZeroOp(s, getNodeByteValue, setNodeByteValue, node, block, 0, -1)) + return result; + return node; } @@ -11472,7 +11620,8 @@ TR::Node *sorSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) return node; } - BINARY_IDENTITY_OR_ZERO_OP(int16_t, ShortInt, 0, -1) + if (auto result = tryAndSimplifyBinaryIdentityOrZeroOp(s, getNodeShortValue, setNodeShortValue, node, block, 0, -1)) + return result; return node; } @@ -11511,7 +11660,9 @@ TR::Node *ixorSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) return node; orderChildren(node, firstChild, secondChild, s); - BINARY_IDENTITY_OP(Int, 0) + + if (auto identity = tryAndSimplifyBinaryIdentityOp(s, getNodeIntValue, node, 0)) + return identity; TR::ILOpCodes firstChildOp = firstChild->getOpCodeValue(); TR::ILOpCodes secondChildOp = secondChild->getOpCodeValue(); @@ -11594,7 +11745,9 @@ TR::Node *lxorSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) return node; orderChildren(node, firstChild, secondChild, s); orderChildrenByHighWordZero(node, firstChild, secondChild, s); - BINARY_IDENTITY_OP(LongInt, 0L) + + if (auto identity = tryAndSimplifyBinaryIdentityOp(s, getNodeLongValue, node, 0L)) + return identity; TR::ILOpCodes firstChildOp = firstChild->getOpCodeValue(); TR::ILOpCodes secondChildOp = secondChild->getOpCodeValue(); @@ -11707,7 +11860,10 @@ TR::Node *bxorSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) } orderChildren(node, firstChild, secondChild, s); - BINARY_IDENTITY_OP(Byte, 0) + + if (auto identity = tryAndSimplifyBinaryIdentityOp(s, getNodeByteValue, node, 0)) + return identity; + return node; } @@ -11724,7 +11880,9 @@ TR::Node *sxorSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) } orderChildren(node, firstChild, secondChild, s); - BINARY_IDENTITY_OP(ShortInt, 0) + + if (auto identity = tryAndSimplifyBinaryIdentityOp(s, getNodeShortValue, node, 0)) + return identity; return node; } diff --git a/compiler/optimizer/OMRSimplifierHelpers.hpp b/compiler/optimizer/OMRSimplifierHelpers.hpp index 476fbb68784..f5d06064ef6 100644 --- a/compiler/optimizer/OMRSimplifierHelpers.hpp +++ b/compiler/optimizer/OMRSimplifierHelpers.hpp @@ -58,17 +58,6 @@ enum {XXCMP_EQ = 0, XXCMP_LT = 1, XXCMP_GT = 2}; } \ } -//************************************** -// Binary identity operation -// -// If the second child is a constant that represents an identity operation, -// replace this node with the first child. -// -#define BINARY_IDENTITY_OP(Type,NullValue) \ - if (secondChild->getOpCode().isLoadConst() && secondChild->get##Type() == NullValue) \ - return s->replaceNode(node, firstChild, s->_curTree); - - /* * Helper functions needed by simplifier handlers across projects */