diff options
author | Max Kazantsev <max.kazantsev@azul.com> | 2018-05-23 10:09:53 +0000 |
---|---|---|
committer | Max Kazantsev <max.kazantsev@azul.com> | 2018-05-23 10:09:53 +0000 |
commit | d99f3bacb4b92847e8fae3be4cab4acbe107df52 (patch) | |
tree | 595221b66a878310a0f4d9e76135dcb3ccb74b70 /llvm/lib/Transforms/Scalar/LoopUnswitch.cpp | |
parent | c0099f9be7dfddab9a4c496f2c9c58f5aefe8e31 (diff) | |
download | bcm5719-llvm-d99f3bacb4b92847e8fae3be4cab4acbe107df52.tar.gz bcm5719-llvm-d99f3bacb4b92847e8fae3be4cab4acbe107df52.zip |
[LoopUnswitch] Fix SCEV invalidation in unswitching
Loop unswitching makes substantial changes to a loop that can also affect cached
SCEV info in its outer loops as well, but it only cares to invalidate SCEV cache for the
innermost loop in case of full unswitching and does not invalidate anything at all in
case of trivial unswitching. As result, we may end up with incorrect data in cache.
Differential Revision: https://reviews.llvm.org/D46045
Reviewed By: mzolotukhin
llvm-svn: 333072
Diffstat (limited to 'llvm/lib/Transforms/Scalar/LoopUnswitch.cpp')
-rw-r--r-- | llvm/lib/Transforms/Scalar/LoopUnswitch.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp index b530f7c5dbd..4aae2bfc89c 100644 --- a/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp +++ b/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp @@ -975,6 +975,10 @@ void LoopUnswitch::UnswitchTrivialCondition(Loop *L, Value *Cond, Constant *Val, << " blocks] in Function " << L->getHeader()->getParent()->getName() << " on cond: " << *Val << " == " << *Cond << "\n"); + // We are going to make essential changes to CFG. This may invalidate cached + // information for L or one of its parent loops in SCEV. + if (auto *SEWP = getAnalysisIfAvailable<ScalarEvolutionWrapperPass>()) + SEWP->getSE().forgetTopmostLoop(L); // First step, split the preheader, so that we know that there is a safe place // to insert the conditional branch. We will change loopPreheader to have a @@ -1201,8 +1205,10 @@ void LoopUnswitch::UnswitchNontrivialCondition(Value *LIC, Constant *Val, << " blocks] in Function " << F->getName() << " when '" << *Val << "' == " << *LIC << "\n"); + // We are going to make essential changes to CFG. This may invalidate cached + // information for L or one of its parent loops in SCEV. if (auto *SEWP = getAnalysisIfAvailable<ScalarEvolutionWrapperPass>()) - SEWP->getSE().forgetLoop(L); + SEWP->getSE().forgetTopmostLoop(L); LoopBlocks.clear(); NewBlocks.clear(); |