Skip to content

Commit

Permalink
Remove stale IVs in IVA
Browse files Browse the repository at this point in the history
Induction variable analysis (IVA) should not leave stale induction
variables (IVs) on the structure that may no longer be valid. IVA now
removes all preexisting IVs from structure so that the only IVs
remaining afterward are those discovered in the current pass.

Signed-off-by: Devin Papineau <devinmp@ca.ibm.com>
  • Loading branch information
jdmpapin committed Jan 15, 2019
1 parent ca3f457 commit 26fce1c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
19 changes: 18 additions & 1 deletion compiler/optimizer/InductionVariable.cpp
Expand Up @@ -5511,6 +5511,7 @@ int32_t TR_InductionVariableAnalysis::perform()

if (comp()->hasLargeNumberOfLoops())
{
removeStaleIVs(comp()->getFlowGraph()->getStructure()->asRegion());
return 0;
}

Expand All @@ -5519,7 +5520,8 @@ int32_t TR_InductionVariableAnalysis::perform()
// FIXME: Why is this allocated with heap memory?
_dominators = new (trHeapMemory()) TR_Dominators(comp());

// Gathers symrefs that are assigned inside a loop
// Gathers symrefs that are assigned inside a loop. This removes stale IVs
// in the same traversal, so there's no need to removeStaleIVs().
//
gatherCandidates(comp()->getFlowGraph()->getStructure(), NULL, NULL);

Expand All @@ -5529,11 +5531,26 @@ int32_t TR_InductionVariableAnalysis::perform()
return 1;
}

void TR_InductionVariableAnalysis::removeStaleIVs(TR_RegionStructure *region)
{
region->clearInductionVariables();

TR_RegionStructure::Cursor it(*region);
for (TR_StructureSubGraphNode *n = it.getFirst(); n != NULL; n = it.getNext())
{
TR_RegionStructure *subRegion = n->getStructure()->asRegion();
if (subRegion != NULL)
removeStaleIVs(subRegion);
}
}

void TR_InductionVariableAnalysis::gatherCandidates(TR_Structure *s, TR_BitVector *loopLocalDefs, TR_BitVector *allDefs)
{
if (s->asRegion())
{
TR_RegionStructure *region = s->asRegion();
region->clearInductionVariables(); // Remove stale IVs

TR_BitVector *myAllDefs = 0;

if (!region->isAcyclic())
Expand Down
1 change: 1 addition & 0 deletions compiler/optimizer/InductionVariable.hpp
Expand Up @@ -521,6 +521,7 @@ class TR_InductionVariableAnalysis : public TR::Optimization

static void appendPredecessors(WorkQueue &workList, TR::Block *block);

void removeStaleIVs(TR_RegionStructure *region);
void gatherCandidates(TR_Structure *s, TR_BitVector *b, TR_BitVector*);

void perform(TR_RegionStructure *str);
Expand Down

0 comments on commit 26fce1c

Please sign in to comment.