TR::Node * OMR::Simplifier::unaryCancelOutWithChild(TR::Node * node, TR::Node * firstChild, TR::TreeTop *anchorTree, TR::ILOpCodes opcode, bool anchorChildren) { if (!isLegalToUnaryCancel(node, firstChild, opcode)) return NULL; if (firstChild->getOpCodeValue() == opcode && (node->getType().isAggregate() || firstChild->getType().isAggregate()) && (node->getSize() > firstChild->getSize() || node->getSize() != firstChild->getFirstChild()->getSize())) { // ensure a truncation side-effect of a conversion is not lost // o2a size=3 // a2o size=3 // conversion truncates in addition to type cast so cannot be removed // loadaddr size=4 // This restriction could be loosened to only disallow intermediate truncations (see BCD case above) but then would require a node // op that would just correct for size (e.g. addrSizeMod size=3 to replace the o2a/a2o pair) // // Do allow cases when all three sizes are the same and when the middle node widens but the top and bottom node have the same size, e.g. // // i2o size=3 // o2i size=4 // oload size=3 // // Also allow the special case where the grandchild is not really truncated as the 'truncated' bytes are known to be zero // (i.e. there really isn't an intermediate truncation of 4->3 even though it appears that way from looking at the sizes alone) // o2i // i2o size=3 // iushr // x // iconst 8 bool disallow = true; TR::Node *grandChild = firstChild->getFirstChild(); size_t nodeSize = node->getSize(); if (node->getType().isIntegral() && nodeSize == grandChild->getSize() && nodeSize > firstChild->getSize()) { size_t truncatedBits = (nodeSize - firstChild->getSize()) * 8; if (grandChild->getOpCode().isRightShift() && grandChild->getOpCode().isShiftLogical() && grandChild->getSecondChild()->getOpCode().isLoadConst() && (grandChild->getSecondChild()->get64bitIntegralValue() == truncatedBits)) { disallow = false; if (trace()) traceMsg(comp(),"do allow unaryCancel of node %s (%p) and firstChild %s (%p) as grandChild %s (%p) zeros the %d truncated bytes\n", node->getOpCode().getName(),node,firstChild->getOpCode().getName(),firstChild, grandChild->getOpCode().getName(),grandChild,truncatedBits/8); } } if (disallow) { if (trace()) traceMsg(comp(),"disallow unaryCancel of node %s (%p) and firstChild %s (%p) due to unequal sizes (nodeSize %d, firstChildSize %d, firstChild->childSize %d)\n", node->getOpCode().getName(),node,firstChild->getOpCode().getName(),firstChild, node->getSize(),firstChild->getSize(),firstChild->getFirstChild()->getSize()); return NULL; } } if (firstChild->getOpCodeValue() == opcode && performTransformation(comp(), "%sRemoving node [" POINTER_PRINTF_FORMAT "] %s and its child [" POINTER_PRINTF_FORMAT "] %s\n", optDetailString(), node, node->getOpCode().getName(), firstChild, firstChild->getOpCode().getName())) { TR::Node *grandChild = firstChild->getFirstChild(); grandChild->incReferenceCount(); bool anchorChildrenNeeded = anchorChildren && (node->getNumChildren() > 1 || firstChild->getNumChildren() > 1 || node->getOpCode().hasSymbolReference() || firstChild->getOpCode().hasSymbolReference()); prepareToStopUsingNode(node, anchorTree, anchorChildrenNeeded); node->recursivelyDecReferenceCount(); node->setVisitCount(0); return grandChild; } return NULL; }