Skip to content

Commit 4647531

Browse files
author
git apple-llvm automerger
committed
Merge commit '098e653a5bed' from llvm.org/release/17.x into stable/20230725
2 parents d283b40 + 098e653 commit 4647531

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,17 @@ static bool writtenBetween(MemorySSA *MSSA, BatchAAResults &AA,
332332
return !MSSA->dominates(Clobber, Start);
333333
}
334334

335+
// Update AA metadata
336+
static void combineAAMetadata(Instruction *ReplInst, Instruction *I) {
337+
// FIXME: MD_tbaa_struct and MD_mem_parallel_loop_access should also be
338+
// handled here, but combineMetadata doesn't support them yet
339+
unsigned KnownIDs[] = {LLVMContext::MD_tbaa, LLVMContext::MD_alias_scope,
340+
LLVMContext::MD_noalias,
341+
LLVMContext::MD_invariant_group,
342+
LLVMContext::MD_access_group};
343+
combineMetadata(ReplInst, I, KnownIDs, true);
344+
}
345+
335346
/// When scanning forward over instructions, we look for some other patterns to
336347
/// fold away. In particular, this looks for stores to neighboring locations of
337348
/// memory. If it sees enough consecutive ones, it attempts to merge them
@@ -1086,16 +1097,9 @@ bool MemCpyOptPass::performCallSlotOptzn(Instruction *cpyLoad,
10861097
MSSA->getMemoryAccess(C));
10871098
}
10881099

1089-
// Update AA metadata
1090-
// FIXME: MD_tbaa_struct and MD_mem_parallel_loop_access should also be
1091-
// handled here, but combineMetadata doesn't support them yet
1092-
unsigned KnownIDs[] = {LLVMContext::MD_tbaa, LLVMContext::MD_alias_scope,
1093-
LLVMContext::MD_noalias,
1094-
LLVMContext::MD_invariant_group,
1095-
LLVMContext::MD_access_group};
1096-
combineMetadata(C, cpyLoad, KnownIDs, true);
1100+
combineAAMetadata(C, cpyLoad);
10971101
if (cpyLoad != cpyStore)
1098-
combineMetadata(C, cpyStore, KnownIDs, true);
1102+
combineAAMetadata(C, cpyStore);
10991103

11001104
++NumCallSlot;
11011105
return true;
@@ -1694,6 +1698,7 @@ bool MemCpyOptPass::processImmutArgument(CallBase &CB, unsigned ArgNo) {
16941698
<< " " << CB << "\n");
16951699

16961700
// Otherwise we're good! Update the immut argument.
1701+
combineAAMetadata(&CB, MDep);
16971702
CB.setArgOperand(ArgNo, MDep->getSource());
16981703
++NumMemCpyInstr;
16991704
return true;

llvm/test/Transforms/MemCpyOpt/memcpy.ll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,10 +695,11 @@ define void @immut_valid_align_branched(i1 %c, ptr noalias align 4 %val) {
695695
ret void
696696
}
697697

698-
; FIXME: This is a miscompile.
698+
; Merge/drop noalias metadata when replacing parameter.
699699
define void @immut_param_noalias_metadata(ptr align 4 byval(i32) %ptr) {
700700
; CHECK-LABEL: @immut_param_noalias_metadata(
701-
; CHECK-NEXT: call void @f(ptr noalias nocapture readonly [[PTR:%.*]]), !alias.scope !0
701+
; CHECK-NEXT: store i32 1, ptr [[PTR:%.*]], align 4, !noalias !0
702+
; CHECK-NEXT: call void @f(ptr noalias nocapture readonly [[PTR]])
702703
; CHECK-NEXT: ret void
703704
;
704705
%tmp = alloca i32, align 4

0 commit comments

Comments
 (0)