From 2f17b625a7ebdd2d9c4a444ee730a57a5426a732 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 by implementing a struct to replace template instantions of the functions tryAndSimplifyBinaryOp*. This change limits the number of template instantiations potential call sites have to create as well as abstracts some captured variables inside the struct to minimize the number of arguments passed to actual calls. A closure is emulated by the struct. Through escape analysis, scalar replacement and inlining, the overhead of creating this struct should be minimal on -O3 Related: #7166 Signed-off-by: James You --- compiler/optimizer/OMRSimplifierHandlers.cpp | 448 +++++++++++++++---- compiler/optimizer/OMRSimplifierHelpers.hpp | 11 - 2 files changed, 358 insertions(+), 101 deletions(-) diff --git a/compiler/optimizer/OMRSimplifierHandlers.cpp b/compiler/optimizer/OMRSimplifierHandlers.cpp index 9096b7514a6..557ce6c78a7 100644 --- a/compiler/optimizer/OMRSimplifierHandlers.cpp +++ b/compiler/optimizer/OMRSimplifierHandlers.cpp @@ -137,32 +137,162 @@ node); \ } -/** - * Binary identity or zero operation - * - * If the second child is a constant that represents an identity operation, - * replace this node with the first child. - * - * 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;\ - }\ - }\ +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->setDoubleBits(bits); + } + +inline bool isNodeLoadConst(TR::Node * node) + { + return node != NULL && node->getOpCode().isLoadConst(); + } + +template +struct BinaryOpSimplifier + { + TR::Simplifier * s; + T (* getNodeValue)(TR::Node *); + void (* setNodeValue)(TR::Node *, T); + + /** + * Binary identity operation + * + * If the second child is a constant that represents an identity operation, + * replace this node with the first child. + */ + inline TR::Node * tryAndSimplifyIdentityOp(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); + } + + /** + * 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. + */ + inline TR::Node * tryAndSimplifyIdentityOrZeroOp(TR::Block * block, TR::Node * node, T nullValue, T zeroValue) + { + auto secondChild = node->getSecondChild(); + if (!isNodeLoadConst(secondChild)) + return NULL; + + auto value = getNodeValue(secondChild); + + 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; } + }; + +BinaryOpSimplifier getByteBinaryOpSimplifier(TR::Simplifier * s) + { + return BinaryOpSimplifier{s, getNodeByteValue, setNodeByteValue}; + } + +BinaryOpSimplifier getShortBinaryOpSimplifier(TR::Simplifier * s) + { + return BinaryOpSimplifier{s, getNodeShortValue, setNodeShortValue}; + } + +BinaryOpSimplifier getIntBinaryOpSimplifier(TR::Simplifier * s) + { + return BinaryOpSimplifier{s, getNodeIntValue, setNodeIntValue}; + } + +BinaryOpSimplifier getLongBinaryOpSimplifier(TR::Simplifier * s) + { + return BinaryOpSimplifier{s, getNodeLongValue, setNodeLongValue}; + } + +BinaryOpSimplifier getFloatBinaryOpSimplifier(TR::Simplifier * s) + { + return BinaryOpSimplifier{s, getNodeFloatBits, setNodeFloatBits}; + } + +BinaryOpSimplifier getDoubleBinaryOpSimplifier(TR::Simplifier * s) + { + return BinaryOpSimplifier{s, getNodeDoubleBits, setNodeDoubleBits}; + } static TR::ILOpCodes addOps[TR::NumAllTypes] = { TR::BadILOp, TR::badd, TR::sadd, TR::iadd, TR::ladd, @@ -6020,8 +6150,11 @@ TR::Node *iaddSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) { return node; } + auto binOpSimplifier = getIntBinaryOpSimplifier(s); + auto identity = binOpSimplifier.tryAndSimplifyIdentityOp(node, 0); + if (identity) + return identity; - BINARY_IDENTITY_OP(Int, 0) TR::ILOpCodes firstChildOp = firstChild->getOpCodeValue(); TR::ILOpCodes secondChildOp = secondChild->getOpCodeValue(); TR::ILOpCodes nodeOp = node->getOpCodeValue(); @@ -6451,8 +6584,11 @@ TR::Node *laddSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) { return node; } + auto binOpSimplifier = getLongBinaryOpSimplifier(s); + auto identity = binOpSimplifier.tryAndSimplifyIdentityOp(node, 0L); + if (identity) + return identity; - BINARY_IDENTITY_OP(LongInt, 0L) 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 +6840,13 @@ 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(); + auto binOpSimplifier = getFloatBinaryOpSimplifier(s); + auto identity = binOpSimplifier.tryAndSimplifyIdentityOp(node, FLOAT_NEG_ZERO); + if (identity) + return identity; return node; } @@ -6744,11 +6873,13 @@ 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 binOpSimplifier = getDoubleBinaryOpSimplifier(s); + auto identity = binOpSimplifier.tryAndSimplifyIdentityOp(node, DOUBLE_NEG_ZERO); + if (identity) + return identity; return node; } @@ -6799,8 +6930,14 @@ 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 binOpSimplifier = getIntBinaryOpSimplifier(s); + auto identity = binOpSimplifier.tryAndSimplifyIdentityOp(node, 0); + if (identity) + return identity; + } TR::ILOpCodes secondChildOp = secondChild->getOpCodeValue(); TR::ILOpCodes firstChildOp = firstChild->getOpCodeValue(); @@ -7252,7 +7389,12 @@ TR::Node *lsubSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) } if (!node->nodeRequiresConditionCodes()) - BINARY_IDENTITY_OP(LongInt, 0L) + { + auto binOpSimplifier = getLongBinaryOpSimplifier(s); + auto identity = binOpSimplifier.tryAndSimplifyIdentityOp(node, 0L); + if (identity) + return identity; + } TR::ILOpCodes firstChildOp = firstChild->getOpCodeValue(); TR::ILOpCodes secondChildOp = secondChild->getOpCodeValue(); @@ -7824,17 +7966,10 @@ 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(); + auto binOpSimplifier = getFloatBinaryOpSimplifier(s); + auto identity = binOpSimplifier.tryAndSimplifyIdentityOp(node, FLOAT_POS_ZERO); + if (identity) + return identity; return node; } @@ -7859,11 +7994,13 @@ 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 binOpSimplifier = getDoubleBinaryOpSimplifier(s); + auto identity = binOpSimplifier.tryAndSimplifyIdentityOp(node, DOUBLE_POS_ZERO); + if (identity) + return identity; return node; } @@ -7902,7 +8039,11 @@ 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) + + auto binOpSimplifier = getIntBinaryOpSimplifier(s); + auto result = binOpSimplifier.tryAndSimplifyIdentityOrZeroOp(block, node, 1, 0); + if (result) + return result; TR::ILOpCodes firstChildOp = firstChild->getOpCodeValue(); TR::ILOpCodes secondChildOp = secondChild->getOpCodeValue(); @@ -8267,7 +8408,11 @@ 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) + + auto binOpSimplifier = getLongBinaryOpSimplifier(s); + auto result = binOpSimplifier.tryAndSimplifyIdentityOrZeroOp(block, node, 1L, 0L); + if (result) + return result; // TODO - strength reduction TR::ILOpCodes firstChildOp = firstChild->getOpCodeValue(); @@ -8484,7 +8629,10 @@ 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 binOpSimplifier = getFloatBinaryOpSimplifier(s); + auto identity = binOpSimplifier.tryAndSimplifyIdentityOp(node, FLOAT_ONE); + if (identity) + return identity; } firstChild = node->getFirstChild(); @@ -8532,7 +8680,10 @@ 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) + auto binOpSimplifier = getLongBinaryOpSimplifier(s); + auto identity = binOpSimplifier.tryAndSimplifyIdentityOp(node, (int64_t) DOUBLE_ONE); + if (identity) + return identity; } return node; } @@ -8550,7 +8701,11 @@ 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) + + auto binOpSimplifier = getByteBinaryOpSimplifier(s); + auto result = binOpSimplifier.tryAndSimplifyIdentityOrZeroOp(block, node, 1, 0); + if (result) + return result; // TODO - strength reduction @@ -8570,7 +8725,11 @@ 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) + + auto binOpSimplifier = getShortBinaryOpSimplifier(s); + auto result = binOpSimplifier.tryAndSimplifyIdentityOrZeroOp(block, node, 1, 0); + if (result) + return result; // TODO - strength reduction @@ -9201,7 +9360,10 @@ 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) + auto binOpSimplifier = getFloatBinaryOpSimplifier(s); + auto identity = binOpSimplifier.tryAndSimplifyIdentityOp(node, FLOAT_ONE); + if (identity) + return identity; firstChild = node->getFirstChild(); secondChild = node->getSecondChild(); @@ -9258,7 +9420,11 @@ 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) + auto binOpSimplifier = getLongBinaryOpSimplifier(s); + auto identity = binOpSimplifier.tryAndSimplifyIdentityOp(node, (int64_t) DOUBLE_ONE); + if (identity) + return identity; + return node; } @@ -9285,7 +9451,10 @@ 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) + auto binOpSimplifier = getByteBinaryOpSimplifier(s); + auto identity = binOpSimplifier.tryAndSimplifyIdentityOp(node, 1); + if (identity) + return identity; } return node; @@ -9317,7 +9486,10 @@ 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) + auto binOpSimplifier = getShortBinaryOpSimplifier(s); + auto identity = binOpSimplifier.tryAndSimplifyIdentityOp(node, 1); + if (identity) + return identity; } return node; @@ -10093,7 +10265,11 @@ TR::Node *ishlSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) } normalizeConstantShiftAmount(node, INT_SHIFT_MASK, secondChild, s); - BINARY_IDENTITY_OP(Int, 0) + + auto binOpSimplifier = getIntBinaryOpSimplifier(s); + auto identity = binOpSimplifier.tryAndSimplifyIdentityOp(node, 0); + if (identity) + 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()))) @@ -10131,7 +10307,11 @@ TR::Node *lshlSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) } normalizeConstantShiftAmount(node, LONG_SHIFT_MASK, secondChild, s); - BINARY_IDENTITY_OP(Int, 0) + + auto binOpSimplifier = getIntBinaryOpSimplifier(s); + auto identity = binOpSimplifier.tryAndSimplifyIdentityOp(node, 0); + if (identity) + return identity; if (secondChild->getOpCode().isLoadConst()) { @@ -10172,7 +10352,11 @@ TR::Node *bshlSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) return node; } - BINARY_IDENTITY_OP(Int, 0) + auto binOpSimplifier = getIntBinaryOpSimplifier(s); + auto identity = binOpSimplifier.tryAndSimplifyIdentityOp(node, 0); + if (identity) + return identity; + return node; } @@ -10187,7 +10371,12 @@ 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) + + auto binOpSimplifier = getIntBinaryOpSimplifier(s); + auto identity = binOpSimplifier.tryAndSimplifyIdentityOp(node, 0); + if (identity) + return identity; + return node; } @@ -10208,7 +10397,11 @@ TR::Node *ishrSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) } normalizeConstantShiftAmount(node, INT_SHIFT_MASK, secondChild, s); - BINARY_IDENTITY_OP(Int, 0) + + auto binOpSimplifier = getIntBinaryOpSimplifier(s); + auto identity = binOpSimplifier.tryAndSimplifyIdentityOp(node, 0); + if (identity) + return identity; normalizeShiftAmount(node, 31, s); @@ -10228,7 +10421,11 @@ TR::Node *lshrSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) } normalizeConstantShiftAmount(node, LONG_SHIFT_MASK, secondChild, s); - BINARY_IDENTITY_OP(Int, 0) + + auto binOpSimplifier = getIntBinaryOpSimplifier(s); + auto identity = binOpSimplifier.tryAndSimplifyIdentityOp(node, 0); + if (identity) + return identity; normalizeShiftAmount(node, 63, s); @@ -10247,7 +10444,11 @@ TR::Node *bshrSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) return node; } - BINARY_IDENTITY_OP(Int, 0) + auto binOpSimplifier = getIntBinaryOpSimplifier(s); + auto identity = binOpSimplifier.tryAndSimplifyIdentityOp(node, 0); + if (identity) + return identity; + return node; } @@ -10262,7 +10463,11 @@ 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) + + auto binOpSimplifier = getIntBinaryOpSimplifier(s); + auto identity = binOpSimplifier.tryAndSimplifyIdentityOp(node, 0); + if (identity) + return identity; return node; } @@ -10284,8 +10489,11 @@ TR::Node *iushrSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s } normalizeConstantShiftAmount(node, INT_SHIFT_MASK, secondChild, s); - BINARY_IDENTITY_OP(Int, 0) + auto binOpSimplifier = getShortBinaryOpSimplifier(s); + auto identity = binOpSimplifier.tryAndSimplifyIdentityOp(node, 0); + if (identity) + 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 @@ -10412,7 +10620,11 @@ TR::Node *lushrSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s } normalizeConstantShiftAmount(node, LONG_SHIFT_MASK, secondChild, s); - BINARY_IDENTITY_OP(Int, 0) + + auto binOpSimplifier = getIntBinaryOpSimplifier(s); + auto identity = binOpSimplifier.tryAndSimplifyIdentityOp(node, 0); + if (identity) + 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 @@ -10508,7 +10720,11 @@ TR::Node *bushrSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s return node; } - BINARY_IDENTITY_OP(Int, 0) + auto binOpSimplifier = getIntBinaryOpSimplifier(s); + auto identity = binOpSimplifier.tryAndSimplifyIdentityOp(node, 0); + if (identity) + return identity; + return node; } @@ -10523,7 +10739,11 @@ 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) + + auto binOpSimplifier = getIntBinaryOpSimplifier(s); + auto identity = binOpSimplifier.tryAndSimplifyIdentityOp(node, 0); + if (identity) + return identity; return node; } @@ -10598,7 +10818,11 @@ 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) + + auto binOpSimplifier = getIntBinaryOpSimplifier(s); + auto result = binOpSimplifier.tryAndSimplifyIdentityOrZeroOp(block, node, -1, 0); + if (result) + return result; if (TR::Node* foldedNode = tryFoldAndWidened(s, node)) { @@ -10746,7 +10970,11 @@ 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) + + auto binOpSimplifier = getLongBinaryOpSimplifier(s); + auto result = binOpSimplifier.tryAndSimplifyIdentityOrZeroOp(block, node, -1L, 0L); + if (result) + return result; if (TR::Node* foldedNode = tryFoldAndWidened(s, node)) { @@ -10943,7 +11171,12 @@ 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) + + auto binOpSimplifier = getByteBinaryOpSimplifier(s); + auto result = binOpSimplifier.tryAndSimplifyIdentityOrZeroOp(block, node, -1, 0); + if (result) + return result; + return node; } @@ -10959,7 +11192,11 @@ 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) + + auto binOpSimplifier = getShortBinaryOpSimplifier(s); + auto result = binOpSimplifier.tryAndSimplifyIdentityOrZeroOp(block, node, -1, 0); + if (result) + return result; if (TR::Node* foldedNode = tryFoldAndWidened(s, node)) { @@ -11123,7 +11360,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) + auto binOpSimplifier = getIntBinaryOpSimplifier(s); + auto result = binOpSimplifier.tryAndSimplifyIdentityOrZeroOp(block, node, 0, -1); + if (result) + return result; TR::ILOpCodes firstChildOp = firstChild->getOpCodeValue(); TR::ILOpCodes secondChildOp = secondChild->getOpCodeValue(); @@ -11264,7 +11504,10 @@ TR::Node *lorSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) return node; } - BINARY_IDENTITY_OR_ZERO_OP(int64_t, LongInt, 0L, -1L) + auto binOpSimplifier = getLongBinaryOpSimplifier(s); + auto result = binOpSimplifier.tryAndSimplifyIdentityOrZeroOp(block, node, 0L, -1L); + if (result) + return result; TR::ILOpCodes firstChildOp = firstChild->getOpCodeValue(); TR::ILOpCodes secondChildOp = secondChild->getOpCodeValue(); @@ -11455,7 +11698,12 @@ 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) + + auto binOpSimplifier = getByteBinaryOpSimplifier(s); + auto result = binOpSimplifier.tryAndSimplifyIdentityOrZeroOp(block, node, 0, -1); + if (result) + return result; + return node; } @@ -11484,7 +11732,10 @@ TR::Node *sorSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) return node; } - BINARY_IDENTITY_OR_ZERO_OP(int16_t, ShortInt, 0, -1) + auto binOpSimplifier = getShortBinaryOpSimplifier(s); + auto result = binOpSimplifier.tryAndSimplifyIdentityOrZeroOp(block, node, 0, -1); + if (result) + return result; return node; } @@ -11523,7 +11774,11 @@ TR::Node *ixorSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) return node; orderChildren(node, firstChild, secondChild, s); - BINARY_IDENTITY_OP(Int, 0) + + auto binOpSimplifier = getIntBinaryOpSimplifier(s); + auto identity = binOpSimplifier.tryAndSimplifyIdentityOp(node, 0); + if (identity) + return identity; TR::ILOpCodes firstChildOp = firstChild->getOpCodeValue(); TR::ILOpCodes secondChildOp = secondChild->getOpCodeValue(); @@ -11606,7 +11861,11 @@ 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) + + auto binOpSimplifier = getLongBinaryOpSimplifier(s); + auto identity = binOpSimplifier.tryAndSimplifyIdentityOp(node, 0L); + if (identity) + return identity; TR::ILOpCodes firstChildOp = firstChild->getOpCodeValue(); TR::ILOpCodes secondChildOp = secondChild->getOpCodeValue(); @@ -11719,7 +11978,12 @@ TR::Node *bxorSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) } orderChildren(node, firstChild, secondChild, s); - BINARY_IDENTITY_OP(Byte, 0) + + auto binOpSimplifier = getByteBinaryOpSimplifier(s); + auto identity = binOpSimplifier.tryAndSimplifyIdentityOp(node, 0); + if (identity) + return identity; + return node; } @@ -11736,7 +12000,11 @@ TR::Node *sxorSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s) } orderChildren(node, firstChild, secondChild, s); - BINARY_IDENTITY_OP(ShortInt, 0) + + auto binOpSimplifier = getShortBinaryOpSimplifier(s); + auto identity = binOpSimplifier.tryAndSimplifyIdentityOp(node, 0); + if (identity) + 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 */