[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).

llvm-svn: 256338
This commit is contained in:
Sanjoy Das 2015-12-23 17:48:14 +00:00
parent fba65d2fd3
commit 2fbfb25ad6
1 changed files with 14 additions and 15 deletions

View File

@ -9439,23 +9439,22 @@ static void replaceSubString(std::string &Str, StringRef From, StringRef To) {
/// getLoopBackedgeTakenCounts - Helper method for verifyAnalysis.
static void
getLoopBackedgeTakenCounts(Loop *L, VerifyMap &Map, ScalarEvolution &SE) {
for (Loop::reverse_iterator I = L->rbegin(), E = L->rend(); I != E; ++I) {
getLoopBackedgeTakenCounts(*I, Map, SE); // recurse.
std::string &S = Map[L];
if (S.empty()) {
raw_string_ostream OS(S);
SE.getBackedgeTakenCount(L)->print(OS);
std::string &S = Map[L];
if (S.empty()) {
raw_string_ostream OS(S);
SE.getBackedgeTakenCount(L)->print(OS);
// false and 0 are semantically equivalent. This can happen in dead loops.
replaceSubString(OS.str(), "false", "0");
// Remove wrap flags, their use in SCEV is highly fragile.
// FIXME: Remove this when SCEV gets smarter about them.
replaceSubString(OS.str(), "<nw>", "");
replaceSubString(OS.str(), "<nsw>", "");
replaceSubString(OS.str(), "<nuw>", "");
}
// false and 0 are semantically equivalent. This can happen in dead loops.
replaceSubString(OS.str(), "false", "0");
// Remove wrap flags, their use in SCEV is highly fragile.
// FIXME: Remove this when SCEV gets smarter about them.
replaceSubString(OS.str(), "<nw>", "");
replaceSubString(OS.str(), "<nsw>", "");
replaceSubString(OS.str(), "<nuw>", "");
}
for (auto *L : reverse(*L))
getLoopBackedgeTakenCounts(L, Map, SE); // recurse.
}
void ScalarEvolution::verify() const {