[llvm-commits] [llvm] r85708 - /llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp

Chris Lattner sabre at nondot.org
Sat Oct 31 21:57:33 PDT 2009


Author: lattner
Date: Sat Oct 31 23:57:33 2009
New Revision: 85708

URL: http://llvm.org/viewvc/llvm-project?rev=85708&view=rev
Log:
change llvm::MergeBlockIntoPredecessor to not merge two blocks BB1->BB2 
when BB2 has its address taken.  Since it ends up doing BB2->rauw(BB1),
this can cause the address of the entry block to be taken.  Since it is
generally undesirable to nuke blocks whose address is taken, even when
we can, just unconditionally stop this xform.

Modified:
    llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp

Modified: llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp?rev=85708&r1=85707&r2=85708&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp Sat Oct 31 23:57:33 2009
@@ -94,10 +94,14 @@
 
 /// MergeBlockIntoPredecessor - Attempts to merge a block into its predecessor,
 /// if possible.  The return value indicates success or failure.
-bool llvm::MergeBlockIntoPredecessor(BasicBlock* BB, Pass* P) {
+bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, Pass *P) {
   pred_iterator PI(pred_begin(BB)), PE(pred_end(BB));
-  // Can't merge the entry block.
-  if (pred_begin(BB) == pred_end(BB)) return false;
+  // Can't merge the entry block.  Don't merge away blocks who have their
+  // address taken: this is a bug if the predecessor block is the entry node
+  // (because we'd end up taking the address of the entry) and undesirable in
+  // any case.
+  if (pred_begin(BB) == pred_end(BB) ||
+      BB->hasAddressTaken()) return false;
   
   BasicBlock *PredBB = *PI++;
   for (; PI != PE; ++PI)  // Search all predecessors, see if they are all same





More information about the llvm-commits mailing list