Ignore conditions that are outside the loop.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@58631 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Transforms/Scalar/LoopUnswitch.cpp b/lib/Transforms/Scalar/LoopUnswitch.cpp
index 65034f5..31e8752 100644
--- a/lib/Transforms/Scalar/LoopUnswitch.cpp
+++ b/lib/Transforms/Scalar/LoopUnswitch.cpp
@@ -167,8 +167,10 @@
// TODO: Handle: br (VARIANT|INVARIANT).
// TODO: Hoist simple expressions out of loops.
- if (L->isLoopInvariant(Cond)) return Cond;
-
+ if (Instruction *I = dyn_cast<Instruction>(Cond))
+ if (!L->contains(I->getParent()))
+ return 0;
+
if (BinaryOperator *BO = dyn_cast<BinaryOperator>(Cond))
if (BO->getOpcode() == Instruction::And ||
BO->getOpcode() == Instruction::Or) {