Skip to content

Commit

Permalink
Merge pull request eclipse-omr#7250 from jdmpapin/fix18803
Browse files Browse the repository at this point in the history
Don't version BNDCHK based on an IV if the loop test is backwards
  • Loading branch information
vijaysun-omr authored Feb 9, 2024
2 parents ac0dab2 + 2ad3b1c commit 92e1304
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions compiler/optimizer/LoopVersioner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7475,6 +7475,8 @@ void TR_LoopVersioner::buildBoundCheckComparisonsTree(
else
incrementI = incrementJ;

bool isIncreasingI = incrementI > 0; // check before taking abs just below

if (incrementI < 0)
incrementI = -incrementI;
if (incrementJ < 0)
Expand All @@ -7488,6 +7490,19 @@ void TR_LoopVersioner::buildBoundCheckComparisonsTree(
if (reverseBranch)
stayInLoopOp = stayInLoopOp.getOpCodeForReverseBranch();

if (isIncreasingI == stayInLoopOp.isCompareTrueIfGreater())
{
dumpOptDetails(
comp(),
"Abandon versioning bound check because while condition %s "
"is incompatible with %s loop driving IV\n",
stayInLoopOp.getName(),
isIncreasingI ? "an increasing" : "a decreasing");

nextTree = nextTree->getNextElement();
continue;
}

bool strict = !stayInLoopOp.isCompareTrueIfEqual();
if (strict)
{
Expand Down

0 comments on commit 92e1304

Please sign in to comment.