Skip to content

Commit

Permalink
Add overflow test in BNDCHK versioning tests
Browse files Browse the repository at this point in the history
Signed-off-by: Annabelle Huo <Annabelle.Huo@ibm.com>
  • Loading branch information
a7ehuo committed Jan 19, 2024
1 parent 44dd802 commit 2d2a5fb
Showing 1 changed file with 52 additions and 8 deletions.
60 changes: 52 additions & 8 deletions compiler/optimizer/LoopVersioner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6893,7 +6893,7 @@ void TR_LoopVersioner::buildBoundCheckComparisonsTree(
traceMsg(comp(), "Index invariant in each iter -> Creating %p (%s)\n", nextComparisonNode, nextComparisonNode->getOpCode().getName());

if (comp()->requiresSpineChecks())
findAndReplaceContigArrayLen(NULL, nextComparisonNode ,comp()->incVisitCount());
findAndReplaceContigArrayLen(NULL, nextComparisonNode, comp()->incVisitCount());

LoopEntryPrep *prep =
createLoopEntryPrep(LoopEntryPrep::TEST, nextComparisonNode);
Expand All @@ -6907,7 +6907,7 @@ void TR_LoopVersioner::buildBoundCheckComparisonsTree(
traceMsg(comp(), "Index invariant in each iter -> Creating %p (%s)\n", nextComparisonNode, nextComparisonNode->getOpCode().getName());

if (comp()->requiresSpineChecks())
findAndReplaceContigArrayLen(NULL, nextComparisonNode ,comp()->incVisitCount());
findAndReplaceContigArrayLen(NULL, nextComparisonNode, comp()->incVisitCount());

prep = createChainedLoopEntryPrep(
LoopEntryPrep::TEST,
Expand Down Expand Up @@ -7312,7 +7312,7 @@ void TR_LoopVersioner::buildBoundCheckComparisonsTree(
}

if (comp()->requiresSpineChecks())
findAndReplaceContigArrayLen(NULL, nextComparisonNode ,comp()->incVisitCount());
findAndReplaceContigArrayLen(NULL, nextComparisonNode, comp()->incVisitCount());

prep = createLoopEntryPrep(LoopEntryPrep::TEST, nextComparisonNode);
dumpOptDetails(
Expand Down Expand Up @@ -7566,6 +7566,50 @@ void TR_LoopVersioner::buildBoundCheckComparisonsTree(
maxValue = TR::Node::create(addOp, 2, entryNode, numIterations);

maxValue = TR::Node::create(TR::isub, 2, maxValue, adjustMaxValue);

if (trace())
{
traceMsg(comp(), "%s: reverseBranch %d stayInLoopOp %s incrNode n%dn numIterations n%dn maxValue n%dn loopLimit n%dn loopDrivingInductionVariable n%dn\n", __FUNCTION__,
reverseBranch, stayInLoopOp.getName(), incrNode->getGlobalIndex(), numIterations->getGlobalIndex(),
maxValue->getGlobalIndex(), loopLimit->getGlobalIndex(), _storeTrees[loopDrivingInductionVariable]->getNode()->getFirstChild()->getGlobalIndex());
}
/*
* Loop test op code: <= or <
* - (limit + step) should be greater than or equal to the limit, otherwise outside of the representable range
*
* Loop test op code: >= or >
* - (limit - step) should be less than or equal to the limit, otherwise outside of the representable range
*/
if (!_storeTrees[loopDrivingInductionVariable]->getNode()->getFirstChild()->cannotOverflow())
{
TR::Node *overflowComparisonNode = NULL;

// stayInLoopOp already considers whether or not the branch is reversed
if ((stayInLoopOp.getOpCodeValue() == TR::ificmple) || (stayInLoopOp.getOpCodeValue() == TR::ificmplt)) // <=, <
{
TR::Node *overLimit = TR::Node::create(TR::iadd, 2, loopLimit, incrNode);
overflowComparisonNode = TR::Node::createif(TR::ificmplt, overLimit, loopLimit, _exitGotoTarget);
}
else // >=, >
{
TR::Node *overLimit = TR::Node::create(TR::isub, 2, loopLimit, incrNode);
overflowComparisonNode = TR::Node::createif(TR::ificmpgt, overLimit, loopLimit, _exitGotoTarget);
}

if (comp()->requiresSpineChecks())
findAndReplaceContigArrayLen(NULL, overflowComparisonNode, comp()->incVisitCount());

prep = createChainedLoopEntryPrep(
LoopEntryPrep::TEST,
overflowComparisonNode,
prep);

dumpOptDetails(
comp(),
"Prep %p has been created for testing if exceed bounds\n",
prep);
}

loopLimit = maxValue;
dumpOptDetails(comp(), "loopLimit has been adjusted to %p\n", loopLimit);
}
Expand Down Expand Up @@ -7691,7 +7735,7 @@ void TR_LoopVersioner::buildBoundCheckComparisonsTree(
}

if (comp()->requiresSpineChecks())
findAndReplaceContigArrayLen(NULL, nextComparisonNode ,comp()->incVisitCount());
findAndReplaceContigArrayLen(NULL, nextComparisonNode, comp()->incVisitCount());

prep = createChainedLoopEntryPrep(
LoopEntryPrep::TEST,
Expand Down Expand Up @@ -7766,7 +7810,7 @@ void TR_LoopVersioner::buildBoundCheckComparisonsTree(
traceMsg(comp(), "Induction variable added in each iter -> Creating %p (%s)\n", nextComparisonNode, nextComparisonNode->getOpCode().getName());

if (comp()->requiresSpineChecks())
findAndReplaceContigArrayLen(NULL, nextComparisonNode ,comp()->incVisitCount());
findAndReplaceContigArrayLen(NULL, nextComparisonNode, comp()->incVisitCount());

prep = createChainedLoopEntryPrep(
LoopEntryPrep::TEST,
Expand Down Expand Up @@ -7798,7 +7842,7 @@ void TR_LoopVersioner::buildBoundCheckComparisonsTree(
nextComparisonNode = TR::Node::createif(TR::ificmplt, duplicateMulNode, TR::Node::create(boundCheckNode, TR::iconst, 0, 0), _exitGotoTarget);
nextComparisonNode->setIsVersionableIfWithMaxExpr(comp());
if (comp()->requiresSpineChecks())
findAndReplaceContigArrayLen(NULL, nextComparisonNode ,comp()->incVisitCount());
findAndReplaceContigArrayLen(NULL, nextComparisonNode, comp()->incVisitCount());

prep = createChainedLoopEntryPrep(
LoopEntryPrep::TEST,
Expand All @@ -7812,7 +7856,7 @@ void TR_LoopVersioner::buildBoundCheckComparisonsTree(
nextComparisonNode = TR::Node::createif(TR::ifiucmpgt, duplicateMulHNode, TR::Node::create(boundCheckNode, TR::iconst, 0, 0), _exitGotoTarget);
nextComparisonNode->setIsVersionableIfWithMaxExpr(comp());
if (comp()->requiresSpineChecks())
findAndReplaceContigArrayLen(NULL, nextComparisonNode ,comp()->incVisitCount());
findAndReplaceContigArrayLen(NULL, nextComparisonNode, comp()->incVisitCount());

prep = createChainedLoopEntryPrep(
LoopEntryPrep::TEST,
Expand All @@ -7825,7 +7869,7 @@ void TR_LoopVersioner::buildBoundCheckComparisonsTree(
//Adding multiplicative factor greater than zero check for multiplicative BNDCHKS a.i+b; a>0
nextComparisonNode = TR::Node::createif(TR::ificmple, strideNode->duplicateTree(), TR::Node::create(boundCheckNode, TR::iconst, 0, 0), _exitGotoTarget);
if (comp()->requiresSpineChecks())
findAndReplaceContigArrayLen(NULL, nextComparisonNode ,comp()->incVisitCount());
findAndReplaceContigArrayLen(NULL, nextComparisonNode, comp()->incVisitCount());

prep = createChainedLoopEntryPrep(
LoopEntryPrep::TEST,
Expand Down

0 comments on commit 2d2a5fb

Please sign in to comment.