From 7a4994356b0e9726384edda57f7db65e5bc10673 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Mon, 16 Aug 2010 14:41:14 +0000 Subject: [PATCH] Instead, teach SimplifyCFG to trim non-address-taken blocks from 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 | 5 +++-- test/Transforms/SimplifyCFG/indirectbr.ll | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index db719a0ce4d..28d7afbf1c3 100644 --- a/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/lib/Transforms/Utils/SimplifyCFG.cpp @@ -2057,12 +2057,13 @@ bool SimplifyCFGOpt::run(BasicBlock *BB) { return true; } } - } else if (IndirectBrInst *IBI = dyn_cast(BB->getTerminator())) { + } else if (IndirectBrInst *IBI = + dyn_cast(BB->getTerminator())) { // Eliminate redundant destinations. SmallPtrSet 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; diff --git a/test/Transforms/SimplifyCFG/indirectbr.ll b/test/Transforms/SimplifyCFG/indirectbr.ll index b13433ce306..de4f5b60755 100644 --- a/test/Transforms/SimplifyCFG/indirectbr.ll +++ b/test/Transforms/SimplifyCFG/indirectbr.ll @@ -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 +}