If a condition is not inside a loop then the condition is suitable
authorDevang Patel <dpatel@apple.com>
Thu, 28 Jun 2007 00:44:10 +0000 (00:44 +0000)
committerDevang Patel <dpatel@apple.com>
Thu, 28 Jun 2007 00:44:10 +0000 (00:44 +0000)
to loop unswitch candidate for the loop.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37770 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/LoopUnswitch.cpp

index 7ad3bd626c13f7dd8aefabb1a37dc04c62fdb214..b79791890da6c14e5e8a1f76d196b1baa5cf7bd7 100644 (file)
@@ -128,6 +128,13 @@ LoopPass *llvm::createLoopUnswitchPass(bool Os) {
 static Value *FindLIVLoopCondition(Value *Cond, Loop *L, bool &Changed) {
   // Constants should be folded, not unswitched on!
   if (isa<Constant>(Cond)) return false;
+
+  // If cond is not in loop then it is not suitable.
+  if (Instruction *I = dyn_cast<Instruction>(Cond))
+    if (!L->contains(I->getParent()))
+      return 0;
+  if (isa<Argument>(Cond))
+    return 0;
   
   // TODO: Handle: br (VARIANT|INVARIANT).
   // TODO: Hoist simple expressions out of loops.