mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-10-31 09:11:13 +00:00
Fix 2004-10-10-CastStoreOnce.llx, by adjusting types back if we strip off a cast
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16878 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
b3deddcf25
commit
8be8012ba4
@ -447,27 +447,30 @@ static bool OptimizeOnceStoredGlobal(GlobalVariable *GV, Value *StoredOnceVal) {
|
|||||||
// initializer. Instead, replace all of the loads with the stored value.
|
// initializer. Instead, replace all of the loads with the stored value.
|
||||||
if (isa<PointerType>(GV->getInitializer()->getType()) &&
|
if (isa<PointerType>(GV->getInitializer()->getType()) &&
|
||||||
GV->getInitializer()->isNullValue()) {
|
GV->getInitializer()->isNullValue()) {
|
||||||
if (isa<Constant>(StoredOnceVal) &&
|
if (Constant *SOVC = dyn_cast<Constant>(StoredOnceVal))
|
||||||
AllUsesOfLoadedValueWillTrapIfNull(GV)) {
|
if (AllUsesOfLoadedValueWillTrapIfNull(GV)) {
|
||||||
DEBUG(std::cerr << "REPLACING STORED GLOBAL POINTER: " << *GV);
|
DEBUG(std::cerr << "REPLACING STORED GLOBAL POINTER: " << *GV);
|
||||||
|
|
||||||
//std::cerr << " Stored Value: " << *StoredOnceVal << "\n";
|
if (GV->getInitializer()->getType() != SOVC->getType())
|
||||||
|
SOVC = ConstantExpr::getCast(SOVC, GV->getInitializer()->getType());
|
||||||
|
|
||||||
// Replace all uses of loads with uses of uses of the stored value.
|
//std::cerr << " Stored Value: " << *SOVC << "\n";
|
||||||
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!");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Nuke the now-dead global.
|
// Replace all uses of loads with uses of uses of the stored value.
|
||||||
GV->getParent()->getGlobalList().erase(GV);
|
while (!GV->use_empty())
|
||||||
return true;
|
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;
|
||||||
|
}
|
||||||
//if (isa<MallocInst>(StoredOnceValue))
|
//if (isa<MallocInst>(StoredOnceValue))
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user