eliminate a bunch of code in favor of using AliasAnalysis::getModRefInfo.

Put a some code back to handle buggy behavior that GVN expects: it wants
loads to depend on each other, and accesses to depend on their allocations.

llvm-svn: 60240
This commit is contained in:
Chris Lattner 2008-11-29 09:09:48 +00:00
parent 7f54c665a2
commit a0265f808f

View File

@ -310,68 +310,66 @@ getDependencyFrom(Instruction *QueryInst, BasicBlock::iterator ScanIt,
// Walk backwards through the basic block, looking for dependencies // Walk backwards through the basic block, looking for dependencies
while (ScanIt != BB->begin()) { while (ScanIt != BB->begin()) {
Instruction *Inst = --ScanIt; Instruction *Inst = --ScanIt;
// If this inst is a memory op, get the pointer it accessed // If the access is volatile and this is a volatile load/store, return a
Value *Pointer = 0; // dependence.
uint64_t PointerSize = 0; if (MemVolatile &&
if (StoreInst *S = dyn_cast<StoreInst>(Inst)) { ((isa<LoadInst>(Inst) && cast<LoadInst>(Inst)->isVolatile()) ||
// All volatile loads/stores depend on each other. (isa<StoreInst>(Inst) && cast<StoreInst>(Inst)->isVolatile())))
if (MemVolatile && S->isVolatile()) return MemDepResult::get(Inst);
return MemDepResult::get(S);
// MemDep is broken w.r.t. loads: it says that two loads of the same pointer
Pointer = S->getPointerOperand(); // depend on each other. :(
PointerSize = TD.getTypeStoreSize(S->getOperand(0)->getType()); // FIXME: ELIMINATE THIS!
} else if (LoadInst *L = dyn_cast<LoadInst>(Inst)) { if (LoadInst *L = dyn_cast<LoadInst>(Inst)) {
// All volatile loads/stores depend on each other Value *Pointer = L->getPointerOperand();
if (MemVolatile && L->isVolatile()) uint64_t PointerSize = TD.getTypeStoreSize(L->getType());
return MemDepResult::get(L);
// If we found a pointer, check if it could be the same as our pointer
Pointer = L->getPointerOperand(); AliasAnalysis::AliasResult R =
PointerSize = TD.getTypeStoreSize(L->getType()); AA.alias(Pointer, PointerSize, MemPtr, MemSize);
} else if (AllocationInst *AI = dyn_cast<AllocationInst>(Inst)) {
Pointer = AI; if (R == AliasAnalysis::NoAlias)
if (ConstantInt *C = dyn_cast<ConstantInt>(AI->getArraySize())) continue;
PointerSize = C->getZExtValue() *
TD.getTypeStoreSize(AI->getAllocatedType()); // May-alias loads don't depend on each other without a dependence.
else if (isa<LoadInst>(QueryInst) && R == AliasAnalysis::MayAlias)
PointerSize = ~0UL; continue;
} else if (VAArgInst *V = dyn_cast<VAArgInst>(Inst)) {
Pointer = V->getOperand(0);
PointerSize = TD.getTypeStoreSize(V->getType());
} else if (FreeInst *F = dyn_cast<FreeInst>(Inst)) {
Pointer = F->getPointerOperand();
// FreeInsts erase the entire structure.
PointerSize = ~0UL;
} else if (isa<CallInst>(Inst) || isa<InvokeInst>(Inst)) {
// Calls need special handling. Check if they can modify our pointer.
AliasAnalysis::ModRefResult MR =
AA.getModRefInfo(CallSite::get(Inst), MemPtr, MemSize);
if (MR == AliasAnalysis::NoModRef)
continue;
// Loads don't depend on read-only calls
if (isa<LoadInst>(QueryInst) && MR == AliasAnalysis::Ref)
continue;
return MemDepResult::get(Inst); return MemDepResult::get(Inst);
} else {
// Non memory instruction, move to the next one.
continue;
} }
// If we found a pointer, check if it could be the same as our pointer // FIXME: This claims that an access depends on the allocation. This may
AliasAnalysis::AliasResult R = // make sense, but is dubious at best. It would be better to fix GVN to
AA.alias(Pointer, PointerSize, MemPtr, MemSize); // handle a 'None' Query.
if (AllocationInst *AI = dyn_cast<AllocationInst>(Inst)) {
Value *Pointer = AI;
uint64_t PointerSize;
if (ConstantInt *C = dyn_cast<ConstantInt>(AI->getArraySize()))
PointerSize = C->getZExtValue() *
TD.getTypeStoreSize(AI->getAllocatedType());
else
PointerSize = ~0UL;
if (R == AliasAnalysis::NoAlias) AliasAnalysis::AliasResult R =
AA.alias(Pointer, PointerSize, MemPtr, MemSize);
if (R == AliasAnalysis::NoAlias)
continue;
return MemDepResult::get(Inst);
}
// See if this instruction mod/ref's the pointer.
AliasAnalysis::ModRefResult MRR = AA.getModRefInfo(Inst, MemPtr, MemSize);
if (MRR == AliasAnalysis::NoModRef)
continue; continue;
// May-alias loads don't depend on each other without a dependence. // Loads don't depend on read-only instructions.
if (isa<LoadInst>(QueryInst) && isa<LoadInst>(Inst) && if (isa<LoadInst>(QueryInst) && MRR == AliasAnalysis::Ref)
R == AliasAnalysis::MayAlias)
continue; continue;
// Otherwise, there is a dependence.
return MemDepResult::get(Inst); return MemDepResult::get(Inst);
} }