mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-23 14:25:07 +00:00
[InstCombine] Properly combine metadata when replacing a load with another
Not doing this can lead to misoptimizations down the line, e.g. because of range metadata on the replacing load excluding values that are valid for the load that is being replaced. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241886 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -749,10 +749,27 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) {
|
||||
// where there are several consecutive memory accesses to the same location,
|
||||
// separated by a few arithmetic operations.
|
||||
BasicBlock::iterator BBI = &LI;
|
||||
if (Value *AvailableVal = FindAvailableLoadedValue(Op, LI.getParent(), BBI,6))
|
||||
AAMDNodes AATags;
|
||||
if (Value *AvailableVal = FindAvailableLoadedValue(Op, LI.getParent(), BBI,
|
||||
6, nullptr, &AATags)) {
|
||||
if (LoadInst *NLI = dyn_cast<LoadInst>(AvailableVal)) {
|
||||
unsigned KnownIDs[] = {
|
||||
LLVMContext::MD_tbaa,
|
||||
LLVMContext::MD_alias_scope,
|
||||
LLVMContext::MD_noalias,
|
||||
LLVMContext::MD_range,
|
||||
LLVMContext::MD_invariant_load,
|
||||
LLVMContext::MD_nonnull,
|
||||
};
|
||||
combineMetadata(NLI, &LI, KnownIDs);
|
||||
if (AATags)
|
||||
NLI->setAAMetadata(AATags);
|
||||
};
|
||||
|
||||
return ReplaceInstUsesWith(
|
||||
LI, Builder->CreateBitOrPointerCast(AvailableVal, LI.getType(),
|
||||
LI.getName() + ".cast"));
|
||||
}
|
||||
|
||||
// load(gep null, ...) -> unreachable
|
||||
if (GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(Op)) {
|
||||
|
Reference in New Issue
Block a user