[llvm-branch-commits] [llvm-branch] r73420 - in /llvm/branches/Apple/Bender: lib/Transforms/Utils/SimplifyCFG.cpp test/Transforms/SimplifyCFG/2009-06-15-InvokeCrash.ll

Bill Wendling isanbard at gmail.com
Mon Jun 15 14:07:48 PDT 2009


Author: void
Date: Mon Jun 15 16:07:47 2009
New Revision: 73420

URL: http://llvm.org/viewvc/llvm-project?rev=73420&view=rev
Log:
--- Merging r73416 into '.':
A    test/Transforms/SimplifyCFG/2009-06-15-InvokeCrash.ll
U    lib/Transforms/Utils/SimplifyCFG.cpp

Fix the crash in this test.  This is basically the same
problem addressed in 31284, but the patch there only
addressed the case where an invoke is the first thing in
a block.

Added:
    llvm/branches/Apple/Bender/test/Transforms/SimplifyCFG/2009-06-15-InvokeCrash.ll
      - copied unchanged from r73416, llvm/trunk/test/Transforms/SimplifyCFG/2009-06-15-InvokeCrash.ll
Modified:
    llvm/branches/Apple/Bender/lib/Transforms/Utils/SimplifyCFG.cpp

Modified: llvm/branches/Apple/Bender/lib/Transforms/Utils/SimplifyCFG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Bender/lib/Transforms/Utils/SimplifyCFG.cpp?rev=73420&r1=73419&r2=73420&view=diff

==============================================================================
--- llvm/branches/Apple/Bender/lib/Transforms/Utils/SimplifyCFG.cpp (original)
+++ llvm/branches/Apple/Bender/lib/Transforms/Utils/SimplifyCFG.cpp Mon Jun 15 16:07:47 2009
@@ -881,6 +881,26 @@
   return Changed;
 }
 
+// isSafeToHoistInvoke - If we would need to insert a select that uses the
+// value of this invoke (comments in HoistThenElseCodeToIf explain why we
+// would need to do this), we can't hoist the invoke, as there is nowhere
+// to put the select in this case.
+static bool isSafeToHoistInvoke(BasicBlock *BB1, BasicBlock *BB2,
+                                Instruction *I1, Instruction *I2) {
+  for (succ_iterator SI = succ_begin(BB1), E = succ_end(BB1); SI != E; ++SI) {
+    PHINode *PN;
+    for (BasicBlock::iterator BBI = SI->begin();
+         (PN = dyn_cast<PHINode>(BBI)); ++BBI) {
+      Value *BB1V = PN->getIncomingValueForBlock(BB1);
+      Value *BB2V = PN->getIncomingValueForBlock(BB2);
+      if (BB1V != BB2V && (BB1V==I1 || BB2V==I2)) {
+        return false;
+      }
+    }
+  }
+  return true;
+}
+
 /// HoistThenElseCodeToIf - Given a conditional branch that goes to BB1 and
 /// BB2, hoist any common code in the two blocks up into the branch block.  The
 /// caller of this function guarantees that BI's block dominates BB1 and BB2.
@@ -901,8 +921,9 @@
     I1 = BB1_Itr++;
   while (isa<DbgInfoIntrinsic>(I2))
     I2 = BB2_Itr++;
-  if (I1->getOpcode() != I2->getOpcode() || isa<PHINode>(I1) || 
-      isa<InvokeInst>(I1) || !I1->isIdenticalTo(I2))
+  if (I1->getOpcode() != I2->getOpcode() || isa<PHINode>(I1) ||
+      !I1->isIdenticalTo(I2) ||
+      (isa<InvokeInst>(I1) && !isSafeToHoistInvoke(BB1, BB2, I1, I2)))
     return false;
 
   // If we get here, we can hoist at least one instruction.
@@ -933,6 +954,10 @@
   return true;
 
 HoistTerminator:
+  // It may not be possible to hoist an invoke.
+  if (isa<InvokeInst>(I1) && !isSafeToHoistInvoke(BB1, BB2, I1, I2))
+    return true;
+
   // Okay, it is safe to hoist the terminator.
   Instruction *NT = I1->clone();
   BIParent->getInstList().insert(BI, NT);





More information about the llvm-branch-commits mailing list