Skip to content

Commit 0ac1e58

Browse files
committed
[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
1 parent 4942a0b commit 0ac1e58

File tree

4 files changed

+14
-96
lines changed

4 files changed

+14
-96
lines changed

polly/include/polly/ScopDetectionDiagnostic.h

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ enum class RejectReasonKind {
8686
LastAffFunc,
8787

8888
LoopBound,
89-
LoopHasNoExit,
9089
LoopOnlySomeLatches,
9190

9291
FuncCall,
@@ -577,36 +576,6 @@ class ReportLoopBound : public RejectReason {
577576
//@}
578577
};
579578

580-
//===----------------------------------------------------------------------===//
581-
/// Captures errors when loop has no exit.
582-
class ReportLoopHasNoExit : public RejectReason {
583-
//===--------------------------------------------------------------------===//
584-
585-
/// The loop that has no exit.
586-
Loop *L;
587-
588-
const DebugLoc Loc;
589-
590-
public:
591-
ReportLoopHasNoExit(Loop *L)
592-
: RejectReason(RejectReasonKind::LoopHasNoExit), L(L),
593-
Loc(L->getStartLoc()) {}
594-
595-
/// @name LLVM-RTTI interface
596-
//@{
597-
static bool classof(const RejectReason *RR);
598-
//@}
599-
600-
/// @name RejectReason interface
601-
//@{
602-
virtual std::string getRemarkName() const override;
603-
virtual const Value *getRemarkBB() const override;
604-
virtual std::string getMessage() const override;
605-
virtual const DebugLoc &getDebugLoc() const override;
606-
virtual std::string getEndUserMessage() const override;
607-
//@}
608-
};
609-
610579
//===----------------------------------------------------------------------===//
611580
/// Captures errors when not all loop latches are part of the scop.
612581
class ReportLoopOnlySomeLatches : public RejectReason {

polly/lib/Analysis/ScopDetection.cpp

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,17 +1180,6 @@ bool ScopDetection::isValidInstruction(Instruction &Inst,
11801180
return invalid<ReportUnknownInst>(Context, /*Assert=*/true, &Inst);
11811181
}
11821182

1183-
/// Check whether @p L has exiting blocks.
1184-
///
1185-
/// @param L The loop of interest
1186-
///
1187-
/// @return True if the loop has exiting blocks, false otherwise.
1188-
static bool hasExitingBlocks(Loop *L) {
1189-
SmallVector<BasicBlock *, 4> ExitingBlocks;
1190-
L->getExitingBlocks(ExitingBlocks);
1191-
return !ExitingBlocks.empty();
1192-
}
1193-
11941183
bool ScopDetection::canUseISLTripCount(Loop *L,
11951184
DetectionContext &Context) const {
11961185
// 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 {
12111200
// Loops that contain part but not all of the blocks of a region cannot be
12121201
// handled by the schedule generation. Such loop constructs can happen
12131202
// because a region can contain BBs that have no path to the exit block
1214-
// (Infinite loops, UnreachableInst), but such blocks are never part of a
1215-
// loop.
1216-
//
1217-
// _______________
1218-
// | Loop Header | <-----------.
1219-
// --------------- |
1220-
// | |
1221-
// _______________ ______________
1222-
// | RegionEntry |-----> | RegionExit |----->
1223-
// --------------- --------------
1224-
// |
1225-
// _______________
1226-
// | EndlessLoop | <--.
1227-
// --------------- |
1228-
// | |
1229-
// \------------/
1230-
//
1231-
// In the example above, the loop (LoopHeader,RegionEntry,RegionExit) is
1232-
// neither entirely contained in the region RegionEntry->RegionExit
1233-
// (containing RegionEntry,EndlessLoop) nor is the region entirely contained
1234-
// in the loop.
1235-
// The block EndlessLoop is contained in the region because Region::contains
1236-
// tests whether it is not dominated by RegionExit. This is probably to not
1237-
// having to query the PostdominatorTree. Instead of an endless loop, a dead
1238-
// end can also be formed by an UnreachableInst. This case is already caught
1239-
// by isErrorBlock(). We hence only have to reject endless loops here.
1240-
if (!hasExitingBlocks(L))
1241-
return invalid<ReportLoopHasNoExit>(Context, /*Assert=*/true, L);
1203+
// (infinite loops, UnreachableInst).
1204+
// We do not have to verify against infinite loops here -- they are
1205+
// postdominated only by the virtual exit and do not appear in regions.
1206+
// Instead of an infinite loop, a dead end can also be formed by an
1207+
// UnreachableInst. This case is already caught by isErrorBlock().
1208+
1209+
#ifndef NDEBUG
1210+
// Make sure that the loop has exits (i.e. is not infinite).
1211+
SmallVector<BasicBlock *, 4> ExitingBlocks;
1212+
L->getExitingBlocks(ExitingBlocks);
1213+
assert(!ExitingBlocks.empty() && "Region with an infinite loop found!");
1214+
#endif
12421215

12431216
if (canUseISLTripCount(L, Context))
12441217
return true;

polly/lib/Analysis/ScopDetectionDiagnostic.cpp

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ llvm::Statistic RejectStatistics[] = {
6060
SCOP_STAT(DifferentElementSize, "Accesses with differing sizes"),
6161
SCOP_STAT(LastAffFunc, ""),
6262
SCOP_STAT(LoopBound, "Uncomputable loop bounds"),
63-
SCOP_STAT(LoopHasNoExit, "Loop without exit"),
6463
SCOP_STAT(LoopOnlySomeLatches, "Not all loop latches in scop"),
6564
SCOP_STAT(FuncCall, "Function call with side effects"),
6665
SCOP_STAT(NonSimpleMemoryAccess,
@@ -459,29 +458,6 @@ std::string ReportLoopBound::getEndUserMessage() const {
459458
return "Failed to derive an affine function from the loop bounds.";
460459
}
461460

462-
//===----------------------------------------------------------------------===//
463-
// ReportLoopHasNoExit.
464-
465-
std::string ReportLoopHasNoExit::getRemarkName() const {
466-
return "LoopHasNoExit";
467-
}
468-
469-
const Value *ReportLoopHasNoExit::getRemarkBB() const { return L->getHeader(); }
470-
471-
std::string ReportLoopHasNoExit::getMessage() const {
472-
return "Loop " + L->getHeader()->getName() + " has no exit.";
473-
}
474-
475-
bool ReportLoopHasNoExit::classof(const RejectReason *RR) {
476-
return RR->getKind() == RejectReasonKind::LoopHasNoExit;
477-
}
478-
479-
const DebugLoc &ReportLoopHasNoExit::getDebugLoc() const { return Loc; }
480-
481-
std::string ReportLoopHasNoExit::getEndUserMessage() const {
482-
return "Loop cannot be handled because it has no exit.";
483-
}
484-
485461
//===----------------------------------------------------------------------===//
486462
// ReportLoopOnlySomeLatches
487463

@@ -499,7 +475,7 @@ std::string ReportLoopOnlySomeLatches::getMessage() const {
499475
}
500476

501477
bool ReportLoopOnlySomeLatches::classof(const RejectReason *RR) {
502-
return RR->getKind() == RejectReasonKind::LoopHasNoExit;
478+
return RR->getKind() == RejectReasonKind::LoopOnlySomeLatches;
503479
}
504480

505481
const DebugLoc &ReportLoopOnlySomeLatches::getDebugLoc() const { return Loc; }

polly/test/ScopDetectionDiagnostics/ReportLoopHasNoExit.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
; XFAIL: *
22

33
; The test case stopped making sense after r310940 that added infinite loops to
4-
; the PostDominatorTree. Infinite loops are postdominated ony by the virtual
4+
; the PostDominatorTree. Infinite loops are postdominated only by the virtual
55
; root, which causes them not to appear in regions in ScopDetection anymore.
66

77
; RUN: opt %loadPolly -pass-remarks-missed="polly-detect" -polly-allow-nonaffine-loops -analyze -polly-detect < %s 2>&1 | FileCheck %s

0 commit comments

Comments
 (0)