Index: lib/Analysis/ScopBuilder.cpp =================================================================== --- lib/Analysis/ScopBuilder.cpp +++ lib/Analysis/ScopBuilder.cpp @@ -894,12 +894,14 @@ return; // PHINodes in the SCoP region's exit block are also uses to be checked. - for (auto &Inst : *S->getRegion().getExit()) { - if (!isa(Inst)) - break; + if (!S->getRegion().isTopLevelRegion()) { + for (auto &Inst : *S->getRegion().getExit()) { + if (!isa(Inst)) + break; - for (auto &Op : Inst.operands()) - verifyUse(S, Op, LI); + for (auto &Op : Inst.operands()) + verifyUse(S, Op, LI); + } } } #endif @@ -917,7 +919,7 @@ // To handle these PHI nodes later we will now model their operands as scalar // accesses. Note that we do not model anything in the exit block if we have // an exiting block in the region, as there will not be any splitting later. - if (!scop->hasSingleExitEdge()) + if (!R.isTopLevelRegion() && !scop->hasSingleExitEdge()) buildAccessFunctions(*R.getExit(), nullptr, /* IsExitBlock */ true); Index: lib/Analysis/ScopDetection.cpp =================================================================== --- lib/Analysis/ScopDetection.cpp +++ lib/Analysis/ScopDetection.cpp @@ -578,7 +578,7 @@ return true; // Return instructions are only valid if the region is the top level region. - if (isa(TI) && !CurRegion.getExit() && TI->getNumOperands() == 0) + if (isa(TI) && CurRegion.isTopLevelRegion()) return true; Value *Condition = getConditionFromTerminator(TI); @@ -1485,13 +1485,14 @@ DEBUG(dbgs() << "Checking region: " << CurRegion.getNameStr() << "\n\t"); - if (CurRegion.isTopLevelRegion()) { + if (!AllowFullFunction && CurRegion.isTopLevelRegion()) { DEBUG(dbgs() << "Top level region is invalid\n"); return false; } DebugLoc DbgLoc; - if (isa(CurRegion.getExit()->getTerminator())) { + if (CurRegion.getExit() && + isa(CurRegion.getExit()->getTerminator())) { DEBUG(dbgs() << "Unreachable in exit\n"); return invalid(Context, /*Assert=*/true, CurRegion.getExit(), DbgLoc); Index: lib/Support/ScopHelper.cpp =================================================================== --- lib/Support/ScopHelper.cpp +++ lib/Support/ScopHelper.cpp @@ -380,9 +380,15 @@ // Basic blocks that are always executed are not considered error blocks, // as their execution can not be a rare event. bool DominatesAllPredecessors = true; - for (auto Pred : predecessors(R.getExit())) - if (R.contains(Pred) && !DT.dominates(&BB, Pred)) - DominatesAllPredecessors = false; + if (R.isTopLevelRegion()) { + for (BasicBlock &I : *R.getEntry()->getParent()) + if (isa(I.getTerminator()) && !DT.dominates(&BB, &I)) + DominatesAllPredecessors = false; + } else { + for (auto Pred : predecessors(R.getExit())) + if (R.contains(Pred) && !DT.dominates(&BB, Pred)) + DominatesAllPredecessors = false; + } if (DominatesAllPredecessors) return false;