@@ -6906,7 +6906,7 @@ void TR_LoopVersioner::buildBoundCheckComparisonsTree(
6906
6906
traceMsg (comp (), " Index invariant in each iter -> Creating %p (%s)\n " , nextComparisonNode, nextComparisonNode->getOpCode ().getName ());
6907
6907
6908
6908
if (comp ()->requiresSpineChecks ())
6909
- findAndReplaceContigArrayLen (NULL , nextComparisonNode , comp ()->incVisitCount ());
6909
+ findAndReplaceContigArrayLen (NULL , nextComparisonNode, comp ()->incVisitCount ());
6910
6910
6911
6911
LoopEntryPrep *prep =
6912
6912
createLoopEntryPrep (LoopEntryPrep::TEST, nextComparisonNode);
@@ -6920,7 +6920,7 @@ void TR_LoopVersioner::buildBoundCheckComparisonsTree(
6920
6920
traceMsg (comp (), " Index invariant in each iter -> Creating %p (%s)\n " , nextComparisonNode, nextComparisonNode->getOpCode ().getName ());
6921
6921
6922
6922
if (comp ()->requiresSpineChecks ())
6923
- findAndReplaceContigArrayLen (NULL , nextComparisonNode , comp ()->incVisitCount ());
6923
+ findAndReplaceContigArrayLen (NULL , nextComparisonNode, comp ()->incVisitCount ());
6924
6924
6925
6925
prep = createChainedLoopEntryPrep (
6926
6926
LoopEntryPrep::TEST,
@@ -7325,7 +7325,7 @@ void TR_LoopVersioner::buildBoundCheckComparisonsTree(
7325
7325
}
7326
7326
7327
7327
if (comp ()->requiresSpineChecks ())
7328
- findAndReplaceContigArrayLen (NULL , nextComparisonNode , comp ()->incVisitCount ());
7328
+ findAndReplaceContigArrayLen (NULL , nextComparisonNode, comp ()->incVisitCount ());
7329
7329
7330
7330
prep = createLoopEntryPrep (LoopEntryPrep::TEST, nextComparisonNode);
7331
7331
dumpOptDetails (
@@ -7524,6 +7524,49 @@ void TR_LoopVersioner::buildBoundCheckComparisonsTree(
7524
7524
maxValue = TR::Node::create (TR::isub, 2 , maxValue, adjustMaxValue);
7525
7525
}
7526
7526
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
+
7527
7570
loopLimit = maxValue;
7528
7571
dumpOptDetails (comp (), " loopLimit has been adjusted to %p\n " , loopLimit);
7529
7572
}
@@ -7604,7 +7647,7 @@ void TR_LoopVersioner::buildBoundCheckComparisonsTree(
7604
7647
}
7605
7648
7606
7649
if (comp ()->requiresSpineChecks ())
7607
- findAndReplaceContigArrayLen (NULL , nextComparisonNode , comp ()->incVisitCount ());
7650
+ findAndReplaceContigArrayLen (NULL , nextComparisonNode, comp ()->incVisitCount ());
7608
7651
7609
7652
prep = createChainedLoopEntryPrep (
7610
7653
LoopEntryPrep::TEST,
@@ -7679,7 +7722,7 @@ void TR_LoopVersioner::buildBoundCheckComparisonsTree(
7679
7722
traceMsg (comp (), " Induction variable added in each iter -> Creating %p (%s)\n " , nextComparisonNode, nextComparisonNode->getOpCode ().getName ());
7680
7723
7681
7724
if (comp ()->requiresSpineChecks ())
7682
- findAndReplaceContigArrayLen (NULL , nextComparisonNode , comp ()->incVisitCount ());
7725
+ findAndReplaceContigArrayLen (NULL , nextComparisonNode, comp ()->incVisitCount ());
7683
7726
7684
7727
prep = createChainedLoopEntryPrep (
7685
7728
LoopEntryPrep::TEST,
@@ -7711,7 +7754,7 @@ void TR_LoopVersioner::buildBoundCheckComparisonsTree(
7711
7754
nextComparisonNode = TR::Node::createif (TR::ificmplt, duplicateMulNode, TR::Node::create (boundCheckNode, TR::iconst, 0 , 0 ), _exitGotoTarget);
7712
7755
nextComparisonNode->setIsVersionableIfWithMaxExpr (comp ());
7713
7756
if (comp ()->requiresSpineChecks ())
7714
- findAndReplaceContigArrayLen (NULL , nextComparisonNode , comp ()->incVisitCount ());
7757
+ findAndReplaceContigArrayLen (NULL , nextComparisonNode, comp ()->incVisitCount ());
7715
7758
7716
7759
prep = createChainedLoopEntryPrep (
7717
7760
LoopEntryPrep::TEST,
@@ -7725,7 +7768,7 @@ void TR_LoopVersioner::buildBoundCheckComparisonsTree(
7725
7768
nextComparisonNode = TR::Node::createif (TR::ifiucmpgt, duplicateMulHNode, TR::Node::create (boundCheckNode, TR::iconst, 0 , 0 ), _exitGotoTarget);
7726
7769
nextComparisonNode->setIsVersionableIfWithMaxExpr (comp ());
7727
7770
if (comp ()->requiresSpineChecks ())
7728
- findAndReplaceContigArrayLen (NULL , nextComparisonNode , comp ()->incVisitCount ());
7771
+ findAndReplaceContigArrayLen (NULL , nextComparisonNode, comp ()->incVisitCount ());
7729
7772
7730
7773
prep = createChainedLoopEntryPrep (
7731
7774
LoopEntryPrep::TEST,
@@ -7738,7 +7781,7 @@ void TR_LoopVersioner::buildBoundCheckComparisonsTree(
7738
7781
// Adding multiplicative factor greater than zero check for multiplicative BNDCHKS a.i+b; a>0
7739
7782
nextComparisonNode = TR::Node::createif (TR::ificmple, strideNode->duplicateTree (), TR::Node::create (boundCheckNode, TR::iconst, 0 , 0 ), _exitGotoTarget);
7740
7783
if (comp ()->requiresSpineChecks ())
7741
- findAndReplaceContigArrayLen (NULL , nextComparisonNode , comp ()->incVisitCount ());
7784
+ findAndReplaceContigArrayLen (NULL , nextComparisonNode, comp ()->incVisitCount ());
7742
7785
7743
7786
prep = createChainedLoopEntryPrep (
7744
7787
LoopEntryPrep::TEST,
0 commit comments