diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2012-10-27 10:45:01 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2012-10-27 10:45:01 +0000 |
commit | 24d270db5763b7566ad3885b7b7f218f68c0d9a0 (patch) | |
tree | 05191bef8679e278f5a5b32b5dd1475b8f20d375 /llvm/lib/Analysis/ScalarEvolution.cpp | |
parent | 19a429e7e68711909d3549f484e539e53057661f (diff) | |
download | bcm5719-llvm-24d270db5763b7566ad3885b7b7f218f68c0d9a0.tar.gz bcm5719-llvm-24d270db5763b7566ad3885b7b7f218f68c0d9a0.zip |
SCEV validator: Add workarounds for some common false positives due to the way it handles strings.
llvm-svn: 166872
Diffstat (limited to 'llvm/lib/Analysis/ScalarEvolution.cpp')
-rw-r--r-- | llvm/lib/Analysis/ScalarEvolution.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 8c2ba6ae83a..806eafa6a21 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -6941,6 +6941,16 @@ void ScalarEvolution::forgetMemoizedResults(const SCEV *S) { } typedef DenseMap<const Loop *, std::string> VerifyMap; + +/// replaceSubString - Replaces all occurences of From in Str with To. +static void replaceSubString(std::string &Str, StringRef From, StringRef To) { + size_t Pos = 0; + while ((Pos = Str.find(From, Pos)) != std::string::npos) { + Str.replace(Pos, From.size(), To.data(), To.size()); + Pos += To.size(); + } +} + /// getLoopBackedgeTakenCounts - Helper method for verifyAnalysis. static void getLoopBackedgeTakenCounts(Loop *L, VerifyMap &Map, ScalarEvolution &SE) { @@ -6951,6 +6961,14 @@ getLoopBackedgeTakenCounts(Loop *L, VerifyMap &Map, ScalarEvolution &SE) { 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>", ""); } } } |