From: Chris Lattner Date: Tue, 20 Jul 2004 03:58:07 +0000 (+0000) Subject: Ignore instructions that are in trivially dead functions. This allows us X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=9ce300013d5c5b9e2c7e26626ddbc8f3a42bdb88;p=oota-llvm.git Ignore instructions that are in trivially dead functions. This allows us to constify 14 globals instead of 4 in a trivial C++ testcase. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15027 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp index 6f01f25f507..97518a34fab 100644 --- a/lib/Transforms/IPO/GlobalOpt.cpp +++ b/lib/Transforms/IPO/GlobalOpt.cpp @@ -39,6 +39,16 @@ namespace { Pass *llvm::createGlobalConstifierPass() { return new Constifier(); } +/// A lot of global constants are stored only in trivially dead setter +/// functions. Because we don't want to cycle between globaldce and this pass, +/// just do a simple check to catch the common case. +static bool ContainingFunctionIsTriviallyDead(Instruction *I) { + Function *F = I->getParent()->getParent(); + if (!F->hasInternalLinkage()) return false; + F->removeDeadConstantUsers(); + return F->use_empty(); +} + /// isStoredThrough - Return false if the specified pointer is provably never /// stored through. If we can't tell, we must conservatively assume it might. /// @@ -48,10 +58,13 @@ static bool isStoredThrough(Value *V) { if (isStoredThrough(CE)) return true; } else if (Instruction *I = dyn_cast(*UI)) { - if (I->getOpcode() == Instruction::GetElementPtr) { - if (isStoredThrough(I)) return true; - } else if (!isa(*UI) && !isa(*UI)) - return true; // Any other non-load instruction might store! + if (!ContainingFunctionIsTriviallyDead(I)) { + if (I->getOpcode() == Instruction::GetElementPtr) { + if (isStoredThrough(I)) return true; + } else if (!isa(*UI) && !isa(*UI)) { + return true; // Any other non-load instruction might store! + } + } } else { // Otherwise must be a global or some other user. return true;