Fix
authorDevang Patel <dpatel@apple.com>
Wed, 25 Apr 2007 00:37:04 +0000 (00:37 +0000)
committerDevang Patel <dpatel@apple.com>
Wed, 25 Apr 2007 00:37:04 +0000 (00:37 +0000)
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070423/048376.html

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

lib/Transforms/Scalar/CodeGenPrepare.cpp

index 8c321f4719b24013e6d9c1d3b30f02bba8a7c110..7a3eac78c56fd3533e1c7d6835e1a81019a39b3a 100644 (file)
@@ -129,6 +129,18 @@ bool CodeGenPrepare::CanMergeBlocks(const BasicBlock *BB,
       const Instruction *User = cast<Instruction>(*UI);
       if (User->getParent() != DestBB || !isa<PHINode>(User))
         return false;
+      // If User is inside DestBB block and it is a PHINode then check 
+      // incoming value. If incoming value is not from BB then this is 
+      // a complex condition (e.g. preheaders) we want to avoid here.
+      if (User->getParent() == DestBB) {
+        if (const PHINode *UPN = dyn_cast<PHINode>(User))
+          for (unsigned I = 0, E = UPN->getNumIncomingValues(); I != E; ++I) {
+            Instruction *Insn = dyn_cast<Instruction>(UPN->getIncomingValue(I));
+            if (Insn && Insn->getParent() == BB &&
+                Insn->getParent() != UPN->getIncomingBlock(I))
+              return false;
+          }
+      }
     }
   }