diff options
author | Devang Patel <dpatel@apple.com> | 2009-03-06 00:21:00 +0000 |
---|---|---|
committer | Devang Patel <dpatel@apple.com> | 2009-03-06 00:21:00 +0000 |
commit | f70bda2f8175db0e0ea24d080a8e5c921b95a74c (patch) | |
tree | 3b123bfc586563d33223d5e1a61b08706923ef83 /lib/Transforms | |
parent | c79e1182470ed12f1f3d0d35c1725366519a9af7 (diff) |
Do not let debug info prevert globalopt from shriking a global vars to boolean.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66224 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/IPO/GlobalOpt.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp index 9284500a86..69753b399d 100644 --- a/lib/Transforms/IPO/GlobalOpt.cpp +++ b/lib/Transforms/IPO/GlobalOpt.cpp @@ -23,6 +23,7 @@ #include "llvm/Module.h" #include "llvm/Pass.h" #include "llvm/Analysis/ConstantFolding.h" +#include "llvm/Transforms/Utils/Local.h" #include "llvm/Target/TargetData.h" #include "llvm/Support/CallSite.h" #include "llvm/Support/Compiler.h" @@ -1562,7 +1563,7 @@ static bool TryToShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal) { // Walk the use list of the global seeing if all the uses are load or store. // If there is anything else, bail out. for (Value::use_iterator I = GV->use_begin(), E = GV->use_end(); I != E; ++I) - if (!isa<LoadInst>(I) && !isa<StoreInst>(I)) + if (!isa<LoadInst>(I) && !isa<StoreInst>(I) && !UserIsDebugInfo(*I)) return false; DOUT << " *** SHRINKING TO BOOL: " << *GV; @@ -1585,8 +1586,8 @@ static bool TryToShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal) { IsOneZero = InitVal->isNullValue() && CI->isOne(); while (!GV->use_empty()) { - Instruction *UI = cast<Instruction>(GV->use_back()); - if (StoreInst *SI = dyn_cast<StoreInst>(UI)) { + User *GVU = GV->use_back(); + if (StoreInst *SI = dyn_cast<StoreInst>(GVU)) { // Change the store into a boolean store. bool StoringOther = SI->getOperand(0) == OtherVal; // Only do this if we weren't storing a loaded value. @@ -1614,9 +1615,9 @@ static bool TryToShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal) { } } new StoreInst(StoreVal, NewGV, SI); - } else { + SI->eraseFromParent(); + } else if (LoadInst *LI = dyn_cast<LoadInst>(GVU)) { // Change the load into a load of bool then a select. - LoadInst *LI = cast<LoadInst>(UI); LoadInst *NLI = new LoadInst(NewGV, LI->getName()+".b", LI); Value *NSI; if (IsOneZero) @@ -1625,8 +1626,9 @@ static bool TryToShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal) { NSI = SelectInst::Create(NLI, OtherVal, InitVal, "", LI); NSI->takeName(LI); LI->replaceAllUsesWith(NSI); - } - UI->eraseFromParent(); + LI->eraseFromParent(); + } else + RemoveDbgInfoUser(GVU); } GV->eraseFromParent(); |