Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 32b3dea

Browse files
committed
[SCEV] Fix getLoopBackedgeTakenCounts
The way `getLoopBackedgeTakenCounts` is written right now isn't correct. It will try to compute and store the BE counts of a Loop #{child loop} number of times (which may be zero). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256338 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 9f5e13c commit 32b3dea

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

lib/Analysis/ScalarEvolution.cpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9439,23 +9439,22 @@ static void replaceSubString(std::string &Str, StringRef From, StringRef To) {
94399439
/// getLoopBackedgeTakenCounts - Helper method for verifyAnalysis.
94409440
static void
94419441
getLoopBackedgeTakenCounts(Loop *L, VerifyMap &Map, ScalarEvolution &SE) {
9442-
for (Loop::reverse_iterator I = L->rbegin(), E = L->rend(); I != E; ++I) {
9443-
getLoopBackedgeTakenCounts(*I, Map, SE); // recurse.
9444-
9445-
std::string &S = Map[L];
9446-
if (S.empty()) {
9447-
raw_string_ostream OS(S);
9448-
SE.getBackedgeTakenCount(L)->print(OS);
9449-
9450-
// false and 0 are semantically equivalent. This can happen in dead loops.
9451-
replaceSubString(OS.str(), "false", "0");
9452-
// Remove wrap flags, their use in SCEV is highly fragile.
9453-
// FIXME: Remove this when SCEV gets smarter about them.
9454-
replaceSubString(OS.str(), "<nw>", "");
9455-
replaceSubString(OS.str(), "<nsw>", "");
9456-
replaceSubString(OS.str(), "<nuw>", "");
9457-
}
9458-
}
9442+
std::string &S = Map[L];
9443+
if (S.empty()) {
9444+
raw_string_ostream OS(S);
9445+
SE.getBackedgeTakenCount(L)->print(OS);
9446+
9447+
// false and 0 are semantically equivalent. This can happen in dead loops.
9448+
replaceSubString(OS.str(), "false", "0");
9449+
// Remove wrap flags, their use in SCEV is highly fragile.
9450+
// FIXME: Remove this when SCEV gets smarter about them.
9451+
replaceSubString(OS.str(), "<nw>", "");
9452+
replaceSubString(OS.str(), "<nsw>", "");
9453+
replaceSubString(OS.str(), "<nuw>", "");
9454+
}
9455+
9456+
for (auto *L : reverse(*L))
9457+
getLoopBackedgeTakenCounts(L, Map, SE); // recurse.
94599458
}
94609459

94619460
void ScalarEvolution::verify() const {

0 commit comments

Comments
 (0)