summaryrefslogtreecommitdiff
path: root/lib/Transforms/Scalar/LoopUnswitch.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-04-20 05:09:16 +0000
committerChris Lattner <sabre@nondot.org>2010-04-20 05:09:16 +0000
commita78130c3207e59bfb2ec0b77ca3f48677685d9ae (patch)
treed3a1523f1678b87f9ac25ccb2d4ba0a1296d0c8c /lib/Transforms/Scalar/LoopUnswitch.cpp
parentf1cfb953375b726f999976924f95fb80db3c1c97 (diff)
downloadllvm-a78130c3207e59bfb2ec0b77ca3f48677685d9ae.tar.gz
llvm-a78130c3207e59bfb2ec0b77ca3f48677685d9ae.tar.bz2
llvm-a78130c3207e59bfb2ec0b77ca3f48677685d9ae.tar.xz
RewriteLoopBodyWithConditionConstant can end up rewriting the
condition we're unswitching on. In this case, don't try to simplify the second copy of the loop which may be dead or not, but is probably a constant now. This fixes PR6879 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@101870 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/LoopUnswitch.cpp')
-rw-r--r--lib/Transforms/Scalar/LoopUnswitch.cpp19
1 files changed, 14 insertions, 5 deletions
diff --git a/lib/Transforms/Scalar/LoopUnswitch.cpp b/lib/Transforms/Scalar/LoopUnswitch.cpp
index 3918738cc8..de124d10aa 100644
--- a/lib/Transforms/Scalar/LoopUnswitch.cpp
+++ b/lib/Transforms/Scalar/LoopUnswitch.cpp
@@ -677,15 +677,22 @@ void LoopUnswitch::UnswitchNontrivialCondition(Value *LIC, Constant *Val,
LoopProcessWorklist.push_back(NewLoop);
redoLoop = true;
+ // Keep a WeakVH holding onto LIC. If the first call to RewriteLoopBody
+ // deletes the instruction (for example by simplifying a PHI that feeds into
+ // the condition that we're unswitching on), we don't rewrite the second
+ // iteration.
+ WeakVH LICHandle(LIC);
+
// Now we rewrite the original code to know that the condition is true and the
// new code to know that the condition is false.
RewriteLoopBodyWithConditionConstant(L, LIC, Val, false);
-
- // It's possible that simplifying one loop could cause the other to be
- // deleted. If so, don't simplify it.
- if (!LoopProcessWorklist.empty() && LoopProcessWorklist.back() == NewLoop)
- RewriteLoopBodyWithConditionConstant(NewLoop, LIC, Val, true);
+ // It's possible that simplifying one loop could cause the other to be
+ // changed to another value or a constant. If its a constant, don't simplify
+ // it.
+ if (!LoopProcessWorklist.empty() && LoopProcessWorklist.back() == NewLoop &&
+ LICHandle && !isa<Constant>(LICHandle))
+ RewriteLoopBodyWithConditionConstant(NewLoop, LICHandle, Val, true);
}
/// RemoveFromWorklist - Remove all instances of I from the worklist vector
@@ -981,6 +988,8 @@ void LoopUnswitch::SimplifyCode(std::vector<Instruction*> &Worklist, Loop *L) {
continue;
}
+ // FIXME: Change this to use instruction simplify interfaces!
+
// Special case hacks that appear commonly in unswitched code.
switch (I->getOpcode()) {
case Instruction::Select: