mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-03 13:31:05 +00:00
slightly simplify code and substantially improve comment. Instead of
saying "it would be bad", give an example of what is going on. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119695 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
5a7aeaa019
commit
d528be6636
@ -712,34 +712,37 @@ bool MemCpyOpt::processMemCpyMemCpyDependence(MemCpyInst *M, MemCpyInst *MDep,
|
|||||||
// the alignment past what can be read from or written to.
|
// the alignment past what can be read from or written to.
|
||||||
// TODO: Is this worth it if we're creating a less aligned memcpy? For
|
// TODO: Is this worth it if we're creating a less aligned memcpy? For
|
||||||
// example we could be moving from movaps -> movq on x86.
|
// example we could be moving from movaps -> movq on x86.
|
||||||
unsigned Align = std::min(MDep->getAlignmentCst()->getZExtValue(),
|
unsigned Align = std::min(MDep->getAlignment(), M->getAlignment());
|
||||||
M->getAlignmentCst()->getZExtValue());
|
|
||||||
LLVMContext &Context = M->getContext();
|
|
||||||
ConstantInt *AlignCI = ConstantInt::get(Type::getInt32Ty(Context), Align);
|
|
||||||
Value *Args[5] = {
|
Value *Args[5] = {
|
||||||
M->getRawDest(), MDep->getRawSource(), M->getLength(),
|
M->getRawDest(),
|
||||||
AlignCI, M->getVolatileCst()
|
MDep->getRawSource(),
|
||||||
|
M->getLength(),
|
||||||
|
ConstantInt::get(Type::getInt32Ty(M->getContext()), Align),
|
||||||
|
M->getVolatileCst()
|
||||||
};
|
};
|
||||||
CallInst *C = CallInst::Create(MemCpyFun, Args, Args+5, "", M);
|
CallInst *C = CallInst::Create(MemCpyFun, Args, Args+5, "", M);
|
||||||
|
|
||||||
|
|
||||||
MemoryDependenceAnalysis &MD = getAnalysis<MemoryDependenceAnalysis>();
|
MemoryDependenceAnalysis &MD = getAnalysis<MemoryDependenceAnalysis>();
|
||||||
|
|
||||||
// If C and M don't interfere, then this is a valid transformation. If they
|
// Verify that the copied-from memory doesn't change in between the two
|
||||||
// did, this would mean that the two sources overlap, which would be bad.
|
// transfers. For example, in:
|
||||||
MemDepResult dep = MD.getDependency(C);
|
// memcpy(a <- b)
|
||||||
if (dep.isClobber() && dep.getInst() == MDep) {
|
// *b = 42;
|
||||||
|
// memcpy(c <- a)
|
||||||
|
// It would be invalid to transform the second memcpy into memcpy(c <- b).
|
||||||
|
MemDepResult NewDep = MD.getDependency(C);
|
||||||
|
if (!NewDep.isClobber() || NewDep.getInst() != MDep) {
|
||||||
|
MD.removeInstruction(C);
|
||||||
|
C->eraseFromParent();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise we're good! Nuke the instruction we're replacing.
|
||||||
MD.removeInstruction(M);
|
MD.removeInstruction(M);
|
||||||
M->eraseFromParent();
|
M->eraseFromParent();
|
||||||
++NumMemCpyInstr;
|
++NumMemCpyInstr;
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise, there was no point in doing this, so we remove the call we
|
|
||||||
// inserted and act like nothing happened.
|
|
||||||
MD.removeInstruction(C);
|
|
||||||
C->eraseFromParent();
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user