From 494b6961447dde7dc79c878daf6dcce811d97790 Mon Sep 17 00:00:00 2001 From: Nicholas Coughlin Date: Thu, 21 Sep 2017 11:11:11 -0400 Subject: [PATCH] Correct escape analysis loop check Escape analysis may have to create initialization code at the method start. If the first block is part of a loop, it will create a new block to hold these trees. However, the block test did not consider whether the first block was in an improper region, resulting in init code being placed inside a loop. Signed-off-by: Nicholas Coughlin --- .../trj9/optimizer/EscapeAnalysis.cpp | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/runtime/tr.source/trj9/optimizer/EscapeAnalysis.cpp b/runtime/tr.source/trj9/optimizer/EscapeAnalysis.cpp index cd3156dc715..7797837e778 100644 --- a/runtime/tr.source/trj9/optimizer/EscapeAnalysis.cpp +++ b/runtime/tr.source/trj9/optimizer/EscapeAnalysis.cpp @@ -98,6 +98,17 @@ extern void createGuardSiteForRemovedGuard(TR::Compilation *comp, TR::Node* ifNode); +static bool blockIsInLoop(TR::Block *block) + { + for (TR_Structure *s = block->getStructureOf()->getParent(); s; s = s->getParent()) + { + TR_RegionStructure *region = s->asRegion(); + if (region->isNaturalLoop() || region->containsInternalCycles()) + return true; + } + return false; + } + TR_EscapeAnalysis::TR_EscapeAnalysis(TR::OptimizationManager *manager) : TR::Optimization(manager), _newObjectNoZeroInitSymRef(NULL), @@ -1048,8 +1059,8 @@ int32_t TR_EscapeAnalysis::performAnalysisOnce() if (comp()->getStartBlock() && !_candidates.isEmpty()) { TR::Block *block = comp()->getStartBlock(); - bool isInLoop = (block->getStructureOf()->getContainingLoop() != NULL); - if (isInLoop) + + if (blockIsInLoop(block)) { comp()->getFlowGraph()->setStructure(NULL); TR::Block *firstBlockReplacement = toBlock(comp()->getFlowGraph()->addNode( @@ -1418,15 +1429,9 @@ void TR_EscapeAnalysis::findCandidates() { candidate->setExplicitlyInitialized(); } - for (TR_Structure *s = _curBlock->getStructureOf()->getParent(); s; s = s->getParent()) - { - TR_RegionStructure *region = s->asRegion(); - if (region->isNaturalLoop() || region->containsInternalCycles()) - { - candidate->setInsideALoop(); - break; - } - } + + if (blockIsInLoop(_curBlock)) + candidate->setInsideALoop(); if (inAColdBlock) candidate->setInAColdBlock(true);