[polly] Fix ScopDetectionDiagnostic test failure caused by r310940

Summary:
ScopDetection used to check if a loop withing a region was infinite and emitted a diagnostic in such cases. After r310940 there's no point checking against that situation, as infinite loops don't appear in regions anymore.

The test failure was observed on these two polly buildbots:
http://lab.llvm.org:8011/builders/polly-arm-linux/builds/8368
http://lab.llvm.org:8011/builders/polly-amd64-linux/builds/10310

This patch XFAILs `ReportLoopHasNoExit.ll` and turns infinite loop detection into an assert.

Reviewers: grosser, sanjoy, bollu

Reviewed By: grosser

Subscribers: efriedma, aemerson, kristof.beyls, dberlin, llvm-commits

Tags: #polly

Differential Revision: https://reviews.llvm.org/D36776

llvm-svn: 311503
This commit is contained in:
Jakub Kuderski 2017-08-22 22:01:53 +00:00
parent 4942a0b0f3
commit 0ac1e585fc
4 changed files with 14 additions and 96 deletions

View File

@ -86,7 +86,6 @@ enum class RejectReasonKind {
LastAffFunc, LastAffFunc,
LoopBound, LoopBound,
LoopHasNoExit,
LoopOnlySomeLatches, LoopOnlySomeLatches,
FuncCall, FuncCall,
@ -577,36 +576,6 @@ public:
//@} //@}
}; };
//===----------------------------------------------------------------------===//
/// Captures errors when loop has no exit.
class ReportLoopHasNoExit : public RejectReason {
//===--------------------------------------------------------------------===//
/// The loop that has no exit.
Loop *L;
const DebugLoc Loc;
public:
ReportLoopHasNoExit(Loop *L)
: RejectReason(RejectReasonKind::LoopHasNoExit), L(L),
Loc(L->getStartLoc()) {}
/// @name LLVM-RTTI interface
//@{
static bool classof(const RejectReason *RR);
//@}
/// @name RejectReason interface
//@{
virtual std::string getRemarkName() const override;
virtual const Value *getRemarkBB() const override;
virtual std::string getMessage() const override;
virtual const DebugLoc &getDebugLoc() const override;
virtual std::string getEndUserMessage() const override;
//@}
};
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
/// Captures errors when not all loop latches are part of the scop. /// Captures errors when not all loop latches are part of the scop.
class ReportLoopOnlySomeLatches : public RejectReason { class ReportLoopOnlySomeLatches : public RejectReason {

View File

@ -1180,17 +1180,6 @@ bool ScopDetection::isValidInstruction(Instruction &Inst,
return invalid<ReportUnknownInst>(Context, /*Assert=*/true, &Inst); return invalid<ReportUnknownInst>(Context, /*Assert=*/true, &Inst);
} }
/// Check whether @p L has exiting blocks.
///
/// @param L The loop of interest
///
/// @return True if the loop has exiting blocks, false otherwise.
static bool hasExitingBlocks(Loop *L) {
SmallVector<BasicBlock *, 4> ExitingBlocks;
L->getExitingBlocks(ExitingBlocks);
return !ExitingBlocks.empty();
}
bool ScopDetection::canUseISLTripCount(Loop *L, bool ScopDetection::canUseISLTripCount(Loop *L,
DetectionContext &Context) const { DetectionContext &Context) const {
// Ensure the loop has valid exiting blocks as well as latches, otherwise we // Ensure the loop has valid exiting blocks as well as latches, otherwise we
@ -1211,34 +1200,18 @@ bool ScopDetection::isValidLoop(Loop *L, DetectionContext &Context) const {
// Loops that contain part but not all of the blocks of a region cannot be // Loops that contain part but not all of the blocks of a region cannot be
// handled by the schedule generation. Such loop constructs can happen // handled by the schedule generation. Such loop constructs can happen
// because a region can contain BBs that have no path to the exit block // because a region can contain BBs that have no path to the exit block
// (Infinite loops, UnreachableInst), but such blocks are never part of a // (infinite loops, UnreachableInst).
// loop. // We do not have to verify against infinite loops here -- they are
// // postdominated only by the virtual exit and do not appear in regions.
// _______________ // Instead of an infinite loop, a dead end can also be formed by an
// | Loop Header | <-----------. // UnreachableInst. This case is already caught by isErrorBlock().
// --------------- |
// | | #ifndef NDEBUG
// _______________ ______________ // Make sure that the loop has exits (i.e. is not infinite).
// | RegionEntry |-----> | RegionExit |-----> SmallVector<BasicBlock *, 4> ExitingBlocks;
// --------------- -------------- L->getExitingBlocks(ExitingBlocks);
// | assert(!ExitingBlocks.empty() && "Region with an infinite loop found!");
// _______________ #endif
// | EndlessLoop | <--.
// --------------- |
// | |
// \------------/
//
// In the example above, the loop (LoopHeader,RegionEntry,RegionExit) is
// neither entirely contained in the region RegionEntry->RegionExit
// (containing RegionEntry,EndlessLoop) nor is the region entirely contained
// in the loop.
// The block EndlessLoop is contained in the region because Region::contains
// tests whether it is not dominated by RegionExit. This is probably to not
// having to query the PostdominatorTree. Instead of an endless loop, a dead
// end can also be formed by an UnreachableInst. This case is already caught
// by isErrorBlock(). We hence only have to reject endless loops here.
if (!hasExitingBlocks(L))
return invalid<ReportLoopHasNoExit>(Context, /*Assert=*/true, L);
if (canUseISLTripCount(L, Context)) if (canUseISLTripCount(L, Context))
return true; return true;

View File

@ -60,7 +60,6 @@ llvm::Statistic RejectStatistics[] = {
SCOP_STAT(DifferentElementSize, "Accesses with differing sizes"), SCOP_STAT(DifferentElementSize, "Accesses with differing sizes"),
SCOP_STAT(LastAffFunc, ""), SCOP_STAT(LastAffFunc, ""),
SCOP_STAT(LoopBound, "Uncomputable loop bounds"), SCOP_STAT(LoopBound, "Uncomputable loop bounds"),
SCOP_STAT(LoopHasNoExit, "Loop without exit"),
SCOP_STAT(LoopOnlySomeLatches, "Not all loop latches in scop"), SCOP_STAT(LoopOnlySomeLatches, "Not all loop latches in scop"),
SCOP_STAT(FuncCall, "Function call with side effects"), SCOP_STAT(FuncCall, "Function call with side effects"),
SCOP_STAT(NonSimpleMemoryAccess, SCOP_STAT(NonSimpleMemoryAccess,
@ -459,29 +458,6 @@ std::string ReportLoopBound::getEndUserMessage() const {
return "Failed to derive an affine function from the loop bounds."; return "Failed to derive an affine function from the loop bounds.";
} }
//===----------------------------------------------------------------------===//
// ReportLoopHasNoExit.
std::string ReportLoopHasNoExit::getRemarkName() const {
return "LoopHasNoExit";
}
const Value *ReportLoopHasNoExit::getRemarkBB() const { return L->getHeader(); }
std::string ReportLoopHasNoExit::getMessage() const {
return "Loop " + L->getHeader()->getName() + " has no exit.";
}
bool ReportLoopHasNoExit::classof(const RejectReason *RR) {
return RR->getKind() == RejectReasonKind::LoopHasNoExit;
}
const DebugLoc &ReportLoopHasNoExit::getDebugLoc() const { return Loc; }
std::string ReportLoopHasNoExit::getEndUserMessage() const {
return "Loop cannot be handled because it has no exit.";
}
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// ReportLoopOnlySomeLatches // ReportLoopOnlySomeLatches
@ -499,7 +475,7 @@ std::string ReportLoopOnlySomeLatches::getMessage() const {
} }
bool ReportLoopOnlySomeLatches::classof(const RejectReason *RR) { bool ReportLoopOnlySomeLatches::classof(const RejectReason *RR) {
return RR->getKind() == RejectReasonKind::LoopHasNoExit; return RR->getKind() == RejectReasonKind::LoopOnlySomeLatches;
} }
const DebugLoc &ReportLoopOnlySomeLatches::getDebugLoc() const { return Loc; } const DebugLoc &ReportLoopOnlySomeLatches::getDebugLoc() const { return Loc; }

View File

@ -1,7 +1,7 @@
; XFAIL: * ; XFAIL: *
; The test case stopped making sense after r310940 that added infinite loops to ; The test case stopped making sense after r310940 that added infinite loops to
; the PostDominatorTree. Infinite loops are postdominated ony by the virtual ; the PostDominatorTree. Infinite loops are postdominated only by the virtual
; root, which causes them not to appear in regions in ScopDetection anymore. ; root, which causes them not to appear in regions in ScopDetection anymore.
; RUN: opt %loadPolly -pass-remarks-missed="polly-detect" -polly-allow-nonaffine-loops -analyze -polly-detect < %s 2>&1 | FileCheck %s ; RUN: opt %loadPolly -pass-remarks-missed="polly-detect" -polly-allow-nonaffine-loops -analyze -polly-detect < %s 2>&1 | FileCheck %s