Instead, teach SimplifyCFG to trim non-address-taken blocks from
authorDan Gohman <gohman@apple.com>
Mon, 16 Aug 2010 14:41:14 +0000 (14:41 +0000)
committerDan Gohman <gohman@apple.com>
Mon, 16 Aug 2010 14:41:14 +0000 (14:41 +0000)
indirectbr destination lists.

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

lib/Transforms/Utils/SimplifyCFG.cpp
test/Transforms/SimplifyCFG/indirectbr.ll

index db719a0ce4df995e91bfa7fe9f5a20ec9faf0896..28d7afbf1c33e03be239bc539d8a4e33b1c10abc 100644 (file)
@@ -2057,12 +2057,13 @@ bool SimplifyCFGOpt::run(BasicBlock *BB) {
         return true;
       }
     }
-  } else if (IndirectBrInst *IBI = dyn_cast<IndirectBrInst>(BB->getTerminator())) {
+  } else if (IndirectBrInst *IBI =
+               dyn_cast<IndirectBrInst>(BB->getTerminator())) {
     // Eliminate redundant destinations.
     SmallPtrSet<Value *, 8> Succs;
     for (unsigned i = 0, e = IBI->getNumDestinations(); i != e; ++i) {
       BasicBlock *Dest = IBI->getDestination(i);
-      if (!Succs.insert(Dest)) {
+      if (!Dest->hasAddressTaken() || !Succs.insert(Dest)) {
         Dest->removePredecessor(BB);
         IBI->removeDestination(i);
         --i; --e;
index b13433ce3068283cf2bbc7b9da35fb47012cb4e3..de4f5b607551113b1f4a86a0765e20f56d7a1819 100644 (file)
@@ -49,3 +49,16 @@ BB0:
   ret void
 }
 
+; SimplifyCFG should notice that BB0 does not have its address taken and
+; remove it from entry's successor list.
+
+; CHECK: indbrtest2
+; CHECK: entry:
+; CHECK-NEXT: unreachable
+
+define void @indbrtest2(i8* %t) {
+entry:
+  indirectbr i8* %t, [label %BB0, label %BB0]
+BB0:
+  ret void
+}