Skip to content

Commit ea8124d

Browse files
authored
Merge pull request #197 from a7ehuo/loopVersioner-BNDCHK-test-pr-v0.43.0
(0.43.0) Add overflow test in BNDCHK versioning tests
2 parents d915dcf + 4672faf commit ea8124d

File tree

1 file changed

+51
-8
lines changed

1 file changed

+51
-8
lines changed

compiler/optimizer/LoopVersioner.cpp

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6906,7 +6906,7 @@ void TR_LoopVersioner::buildBoundCheckComparisonsTree(
69066906
traceMsg(comp(), "Index invariant in each iter -> Creating %p (%s)\n", nextComparisonNode, nextComparisonNode->getOpCode().getName());
69076907

69086908
if (comp()->requiresSpineChecks())
6909-
findAndReplaceContigArrayLen(NULL, nextComparisonNode ,comp()->incVisitCount());
6909+
findAndReplaceContigArrayLen(NULL, nextComparisonNode, comp()->incVisitCount());
69106910

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

69226922
if (comp()->requiresSpineChecks())
6923-
findAndReplaceContigArrayLen(NULL, nextComparisonNode ,comp()->incVisitCount());
6923+
findAndReplaceContigArrayLen(NULL, nextComparisonNode, comp()->incVisitCount());
69246924

69256925
prep = createChainedLoopEntryPrep(
69266926
LoopEntryPrep::TEST,
@@ -7325,7 +7325,7 @@ void TR_LoopVersioner::buildBoundCheckComparisonsTree(
73257325
}
73267326

73277327
if (comp()->requiresSpineChecks())
7328-
findAndReplaceContigArrayLen(NULL, nextComparisonNode ,comp()->incVisitCount());
7328+
findAndReplaceContigArrayLen(NULL, nextComparisonNode, comp()->incVisitCount());
73297329

73307330
prep = createLoopEntryPrep(LoopEntryPrep::TEST, nextComparisonNode);
73317331
dumpOptDetails(
@@ -7524,6 +7524,49 @@ void TR_LoopVersioner::buildBoundCheckComparisonsTree(
75247524
maxValue = TR::Node::create(TR::isub, 2, maxValue, adjustMaxValue);
75257525
}
75267526

7527+
if (trace())
7528+
{
7529+
traceMsg(comp(), "%s: reverseBranch %d stayInLoopOp %s incrNode n%dn numIterations n%dn maxValue n%dn loopLimit n%dn loopDrivingInductionVariable n%dn\n", __FUNCTION__,
7530+
reverseBranch, stayInLoopOp.getName(), incrNode->getGlobalIndex(), numIterations->getGlobalIndex(),
7531+
maxValue->getGlobalIndex(), loopLimit->getGlobalIndex(), _storeTrees[loopDrivingInductionVariable]->getNode()->getFirstChild()->getGlobalIndex());
7532+
}
7533+
/*
7534+
* Loop test op code: <= or <
7535+
* - (limit + step) should be greater than or equal to the limit, otherwise outside of the representable range
7536+
*
7537+
* Loop test op code: >= or >
7538+
* - (limit - step) should be less than or equal to the limit, otherwise outside of the representable range
7539+
*/
7540+
if (!_storeTrees[loopDrivingInductionVariable]->getNode()->getFirstChild()->cannotOverflow())
7541+
{
7542+
TR::Node *overflowComparisonNode = NULL;
7543+
7544+
// stayInLoopOp already considers whether or not the branch is reversed
7545+
if ((stayInLoopOp.getOpCodeValue() == TR::ificmple) || (stayInLoopOp.getOpCodeValue() == TR::ificmplt)) // <=, <
7546+
{
7547+
TR::Node *overLimit = TR::Node::create(TR::iadd, 2, loopLimit, incrNode);
7548+
overflowComparisonNode = TR::Node::createif(TR::ificmplt, overLimit, loopLimit, _exitGotoTarget);
7549+
}
7550+
else // >=, >
7551+
{
7552+
TR::Node *overLimit = TR::Node::create(TR::isub, 2, loopLimit, incrNode);
7553+
overflowComparisonNode = TR::Node::createif(TR::ificmpgt, overLimit, loopLimit, _exitGotoTarget);
7554+
}
7555+
7556+
if (comp()->requiresSpineChecks())
7557+
findAndReplaceContigArrayLen(NULL, overflowComparisonNode, comp()->incVisitCount());
7558+
7559+
prep = createChainedLoopEntryPrep(
7560+
LoopEntryPrep::TEST,
7561+
overflowComparisonNode,
7562+
prep);
7563+
7564+
dumpOptDetails(
7565+
comp(),
7566+
"Prep %p has been created for testing if exceed bounds\n",
7567+
prep);
7568+
}
7569+
75277570
loopLimit = maxValue;
75287571
dumpOptDetails(comp(), "loopLimit has been adjusted to %p\n", loopLimit);
75297572
}
@@ -7604,7 +7647,7 @@ void TR_LoopVersioner::buildBoundCheckComparisonsTree(
76047647
}
76057648

76067649
if (comp()->requiresSpineChecks())
7607-
findAndReplaceContigArrayLen(NULL, nextComparisonNode ,comp()->incVisitCount());
7650+
findAndReplaceContigArrayLen(NULL, nextComparisonNode, comp()->incVisitCount());
76087651

76097652
prep = createChainedLoopEntryPrep(
76107653
LoopEntryPrep::TEST,
@@ -7679,7 +7722,7 @@ void TR_LoopVersioner::buildBoundCheckComparisonsTree(
76797722
traceMsg(comp(), "Induction variable added in each iter -> Creating %p (%s)\n", nextComparisonNode, nextComparisonNode->getOpCode().getName());
76807723

76817724
if (comp()->requiresSpineChecks())
7682-
findAndReplaceContigArrayLen(NULL, nextComparisonNode ,comp()->incVisitCount());
7725+
findAndReplaceContigArrayLen(NULL, nextComparisonNode, comp()->incVisitCount());
76837726

76847727
prep = createChainedLoopEntryPrep(
76857728
LoopEntryPrep::TEST,
@@ -7711,7 +7754,7 @@ void TR_LoopVersioner::buildBoundCheckComparisonsTree(
77117754
nextComparisonNode = TR::Node::createif(TR::ificmplt, duplicateMulNode, TR::Node::create(boundCheckNode, TR::iconst, 0, 0), _exitGotoTarget);
77127755
nextComparisonNode->setIsVersionableIfWithMaxExpr(comp());
77137756
if (comp()->requiresSpineChecks())
7714-
findAndReplaceContigArrayLen(NULL, nextComparisonNode ,comp()->incVisitCount());
7757+
findAndReplaceContigArrayLen(NULL, nextComparisonNode, comp()->incVisitCount());
77157758

77167759
prep = createChainedLoopEntryPrep(
77177760
LoopEntryPrep::TEST,
@@ -7725,7 +7768,7 @@ void TR_LoopVersioner::buildBoundCheckComparisonsTree(
77257768
nextComparisonNode = TR::Node::createif(TR::ifiucmpgt, duplicateMulHNode, TR::Node::create(boundCheckNode, TR::iconst, 0, 0), _exitGotoTarget);
77267769
nextComparisonNode->setIsVersionableIfWithMaxExpr(comp());
77277770
if (comp()->requiresSpineChecks())
7728-
findAndReplaceContigArrayLen(NULL, nextComparisonNode ,comp()->incVisitCount());
7771+
findAndReplaceContigArrayLen(NULL, nextComparisonNode, comp()->incVisitCount());
77297772

77307773
prep = createChainedLoopEntryPrep(
77317774
LoopEntryPrep::TEST,
@@ -7738,7 +7781,7 @@ void TR_LoopVersioner::buildBoundCheckComparisonsTree(
77387781
//Adding multiplicative factor greater than zero check for multiplicative BNDCHKS a.i+b; a>0
77397782
nextComparisonNode = TR::Node::createif(TR::ificmple, strideNode->duplicateTree(), TR::Node::create(boundCheckNode, TR::iconst, 0, 0), _exitGotoTarget);
77407783
if (comp()->requiresSpineChecks())
7741-
findAndReplaceContigArrayLen(NULL, nextComparisonNode ,comp()->incVisitCount());
7784+
findAndReplaceContigArrayLen(NULL, nextComparisonNode, comp()->incVisitCount());
77427785

77437786
prep = createChainedLoopEntryPrep(
77447787
LoopEntryPrep::TEST,

0 commit comments

Comments
 (0)