[SimplifyCFG] Followup fix to r280790
authorJames Molloy <james.molloy@arm.com>
Wed, 7 Sep 2016 09:01:22 +0000 (09:01 +0000)
committerJames Molloy <james.molloy@arm.com>
Wed, 7 Sep 2016 09:01:22 +0000 (09:01 +0000)
In failure cases it's not guaranteed that the PHI we're inspecting is actually in the successor block! In this case we need to bail out early, and never query getIncomingValueForBlock() as that will cause an assert.

llvm-svn: 280794

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

index 909a72c..e5da77e 100644 (file)
@@ -1401,9 +1401,11 @@ static bool canSinkInstructions(
   // we're contemplating sinking, it must already be determined to be sinkable.
   if (!isa<StoreInst>(I0)) {
     auto *PNUse = dyn_cast<PHINode>(*I0->user_begin());
-    if (!all_of(Insts, [&PNUse](const Instruction *I) -> bool {
+    auto *Succ = I0->getParent()->getTerminator()->getSuccessor(0);
+    if (!all_of(Insts, [&PNUse,&Succ](const Instruction *I) -> bool {
           auto *U = cast<Instruction>(*I->user_begin());
           return (PNUse &&
+                  PNUse->getParent() == Succ &&
                   PNUse->getIncomingValueForBlock(I->getParent()) == I) ||
                  U->getParent() == I->getParent();
         }))