Skip to content

Instantly share code, notes, and snippets.

@rwy7
Created January 7, 2019 21:39
Show Gist options
  • Save rwy7/49a60dff20a5597c541398c87904e805 to your computer and use it in GitHub Desktop.
Save rwy7/49a60dff20a5597c541398c87904e805 to your computer and use it in GitHub Desktop.
SIMPLIFY_BRANCH_ARITHMETIC
#define SIMPLIFY_BRANCH_ARITHMETIC(Type, Width) \
if ((firstChild->getOpCode().isSub() || firstChild->getOpCode().isAdd()) \
&& (firstChild->getSecondChild()->getOpCode().isLoadConst()) \
&& (secondChild->getOpCode().isSub() || secondChild->getOpCode().isAdd()) \
&& (secondChild->getSecondChild()->getOpCode().isLoadConst()) \
&& (firstChild->getReferenceCount() == 1) \
&& (secondChild->getReferenceCount() == 1)) { \
Width konst; \
if (firstChild->getOpCode().isSub()) { \
if (secondChild->getOpCode().isSub()) \
konst = secondChild->getSecondChild()->get##Type() - firstChild->getSecondChild()->get##Type(); \
else \
konst = secondChild->getSecondChild()->get##Type() + firstChild->getSecondChild()->get##Type(); \
} else { \
if (secondChild->getOpCode().isAdd()) \
konst = secondChild->getSecondChild()->get##Type() - firstChild->getSecondChild()->get##Type(); \
else \
konst = secondChild->getSecondChild()->get##Type() + firstChild->getSecondChild()->get##Type(); \
} \
node->setAndIncChild(0, firstChild->getFirstChild()); \
firstChild->recursivelyDecReferenceCount(); \
firstChild = firstChild->getFirstChild(); \
if (konst == 0) { \
node->setAndIncChild(1, secondChild->getFirstChild()); \
secondChild->recursivelyDecReferenceCount(); \
secondChild = secondChild->getFirstChild(); \
} else { \
TR::Node* grandChild = secondChild->getSecondChild(); \
if (grandChild->getReferenceCount() == 1) \
grandChild->set##Type(konst); \
else { \
grandChild->recursivelyDecReferenceCount(); \
secondChild->setAndIncChild( \
1, TR::Node::create(grandChild, grandChild->getOpCodeValue(), 0, (int32_t)konst)); \
} \
} \
dumpOptDetails(s->comp(), \
"%ssimplified arithmetic in branch [" POINTER_PRINTF_FORMAT \
"]\n", \
s->optDetailString(), node); \
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment