summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-10-10 17:07:12 +0000
committerChris Lattner <sabre@nondot.org>2004-10-10 17:07:12 +0000
commit604ed7aae85ece04153add43695d952bc21aaebb (patch)
tree9112773e55bd58421dbb87306284704d3460ca4e /llvm/lib
parent89e0b39fe5e14f9fd2872c3bea0ab153b087fd69 (diff)
downloadbcm5719-llvm-604ed7aae85ece04153add43695d952bc21aaebb.tar.gz
bcm5719-llvm-604ed7aae85ece04153add43695d952bc21aaebb.zip
Fix 2004-10-10-CastStoreOnce.llx, by adjusting types back if we strip off a cast
llvm-svn: 16878
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/IPO/GlobalOpt.cpp43
1 files changed, 23 insertions, 20 deletions
diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
index 3a58afdc260..17328956d92 100644
--- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
@@ -447,27 +447,30 @@ static bool OptimizeOnceStoredGlobal(GlobalVariable *GV, Value *StoredOnceVal) {
// initializer. Instead, replace all of the loads with the stored value.
if (isa<PointerType>(GV->getInitializer()->getType()) &&
GV->getInitializer()->isNullValue()) {
- if (isa<Constant>(StoredOnceVal) &&
- AllUsesOfLoadedValueWillTrapIfNull(GV)) {
- DEBUG(std::cerr << "REPLACING STORED GLOBAL POINTER: " << *GV);
-
- //std::cerr << " Stored Value: " << *StoredOnceVal << "\n";
-
- // Replace all uses of loads with uses of uses of the stored value.
- while (!GV->use_empty())
- if (LoadInst *LI = dyn_cast<LoadInst>(GV->use_back())) {
- LI->replaceAllUsesWith(StoredOnceVal);
- LI->getParent()->getInstList().erase(LI); // Nuke the load.
- } else if (StoreInst *SI = dyn_cast<StoreInst>(GV->use_back())) {
- SI->getParent()->getInstList().erase(SI); // Nuke the store
- } else {
- assert(0 && "Unknown user of stored once global!");
- }
+ if (Constant *SOVC = dyn_cast<Constant>(StoredOnceVal))
+ if (AllUsesOfLoadedValueWillTrapIfNull(GV)) {
+ DEBUG(std::cerr << "REPLACING STORED GLOBAL POINTER: " << *GV);
+
+ if (GV->getInitializer()->getType() != SOVC->getType())
+ SOVC = ConstantExpr::getCast(SOVC, GV->getInitializer()->getType());
+
+ //std::cerr << " Stored Value: " << *SOVC << "\n";
+
+ // Replace all uses of loads with uses of uses of the stored value.
+ while (!GV->use_empty())
+ if (LoadInst *LI = dyn_cast<LoadInst>(GV->use_back())) {
+ LI->replaceAllUsesWith(SOVC);
+ LI->getParent()->getInstList().erase(LI); // Nuke the load.
+ } else if (StoreInst *SI = dyn_cast<StoreInst>(GV->use_back())) {
+ SI->getParent()->getInstList().erase(SI); // Nuke the store
+ } else {
+ assert(0 && "Unknown user of stored once global!");
+ }
- // Nuke the now-dead global.
- GV->getParent()->getGlobalList().erase(GV);
- return true;
- }
+ // Nuke the now-dead global.
+ GV->getParent()->getGlobalList().erase(GV);
+ return true;
+ }
//if (isa<MallocInst>(StoredOnceValue))
}
return false;
OpenPOWER on IntegriCloud