diff --git a/lib/Transforms/Scalar/DeadStoreElimination.cpp b/lib/Transforms/Scalar/DeadStoreElimination.cpp index 40986d1a36f..ba01e136db3 100644 --- a/lib/Transforms/Scalar/DeadStoreElimination.cpp +++ b/lib/Transforms/Scalar/DeadStoreElimination.cpp @@ -64,8 +64,8 @@ namespace { bool runOnBasicBlock(BasicBlock &BB); bool HandleFree(CallInst *F); bool handleEndBlock(BasicBlock &BB); - void RemoveAccessedObjects(Value *Ptr, uint64_t killPointerSize, - SmallPtrSet &deadPointers); + void RemoveAccessedObjects(const AliasAnalysis::Location &LoadedLoc, + SmallPtrSet &DeadStackObjects); void DeleteDeadInstruction(Instruction *I, SmallPtrSet *deadPointers = 0); @@ -494,18 +494,15 @@ bool DSE::handleEndBlock(BasicBlock &BB) { continue; } - Value *KillPointer = 0; - uint64_t KillPointerSize = AliasAnalysis::UnknownSize; + AliasAnalysis::Location LoadedLoc; // If we encounter a use of the pointer, it is no longer considered dead if (LoadInst *L = dyn_cast(BBI)) { - KillPointer = L->getPointerOperand(); + LoadedLoc = AA->getLocation(L); } else if (VAArgInst *V = dyn_cast(BBI)) { - KillPointer = V->getOperand(0); + LoadedLoc = AA->getLocation(V); } else if (MemTransferInst *MTI = dyn_cast(BBI)) { - KillPointer = cast(BBI)->getSource(); - if (ConstantInt *Len = dyn_cast(MTI->getLength())) - KillPointerSize = Len->getZExtValue(); + LoadedLoc = AA->getLocationForSource(MTI); } else { // Not a loading instruction. continue; @@ -513,7 +510,7 @@ bool DSE::handleEndBlock(BasicBlock &BB) { // Remove any allocas from the DeadPointer set that are loaded, as this // makes any stores above the access live. - RemoveAccessedObjects(KillPointer, KillPointerSize, DeadStackObjects); + RemoveAccessedObjects(LoadedLoc, DeadStackObjects); // If all of the allocas were clobbered by the access then we're not going // to find anything else to process. @@ -527,9 +524,9 @@ bool DSE::handleEndBlock(BasicBlock &BB) { /// RemoveAccessedObjects - Check to see if the specified location may alias any /// of the stack objects in the DeadStackObjects set. If so, they become live /// because the location is being loaded. -void DSE::RemoveAccessedObjects(Value *KillPointer, uint64_t KillPointerSize, +void DSE::RemoveAccessedObjects(const AliasAnalysis::Location &LoadedLoc, SmallPtrSet &DeadStackObjects) { - Value *UnderlyingPointer = KillPointer->getUnderlyingObject(); + const Value *UnderlyingPointer = LoadedLoc.Ptr->getUnderlyingObject(); // A constant can't be in the dead pointer set. if (isa(UnderlyingPointer)) @@ -538,17 +535,16 @@ void DSE::RemoveAccessedObjects(Value *KillPointer, uint64_t KillPointerSize, // If the kill pointer can be easily reduced to an alloca, don't bother doing // extraneous AA queries. if (isa(UnderlyingPointer) || isa(UnderlyingPointer)) { - DeadStackObjects.erase(UnderlyingPointer); + DeadStackObjects.erase(const_cast(UnderlyingPointer)); return; } SmallVector NowLive; for (SmallPtrSet::iterator I = DeadStackObjects.begin(), E = DeadStackObjects.end(); I != E; ++I) { - // See if this pointer could alias it - AliasAnalysis::AliasResult A = AA->alias(*I, getPointerSize(*I, *AA), - KillPointer, KillPointerSize); - if (A != AliasAnalysis::NoAlias) + // See if the loaded location could alias the stack location. + AliasAnalysis::Location StackLoc(*I, getPointerSize(*I, *AA)); + if (!AA->isNoAlias(StackLoc, LoadedLoc)) NowLive.push_back(*I); }