Skip to content

Commit 499f878

Browse files
authored
Backport llvm#74805 to 16.x (#24)
1 parent 3c83f17 commit 499f878

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,10 @@ Instruction *InstCombinerImpl::SimplifyAnyMemTransfer(AnyMemTransferInst *MI) {
184184

185185
// If the memcpy has metadata describing the members, see if we can get the
186186
// TBAA tag describing our copy.
187-
MDNode *CopyMD = nullptr;
188-
if (MDNode *M = MI->getMetadata(LLVMContext::MD_tbaa)) {
189-
CopyMD = M;
190-
} else if (MDNode *M = MI->getMetadata(LLVMContext::MD_tbaa_struct)) {
187+
AAMDNodes AACopyMD = MI->getAAMetadata();
188+
189+
if (MDNode *M = AACopyMD.TBAAStruct) {
190+
AACopyMD.TBAAStruct = nullptr;
191191
if (M->getNumOperands() == 3 && M->getOperand(0) &&
192192
mdconst::hasa<ConstantInt>(M->getOperand(0)) &&
193193
mdconst::extract<ConstantInt>(M->getOperand(0))->isZero() &&
@@ -196,16 +196,15 @@ Instruction *InstCombinerImpl::SimplifyAnyMemTransfer(AnyMemTransferInst *MI) {
196196
mdconst::extract<ConstantInt>(M->getOperand(1))->getValue() ==
197197
Size &&
198198
M->getOperand(2) && isa<MDNode>(M->getOperand(2)))
199-
CopyMD = cast<MDNode>(M->getOperand(2));
199+
AACopyMD.TBAA = cast<MDNode>(M->getOperand(2));
200200
}
201201

202202
Value *Src = Builder.CreateBitCast(MI->getArgOperand(1), NewSrcPtrTy);
203203
Value *Dest = Builder.CreateBitCast(MI->getArgOperand(0), NewDstPtrTy);
204204
LoadInst *L = Builder.CreateLoad(IntType, Src);
205205
// Alignment from the mem intrinsic will be better, so use it.
206206
L->setAlignment(*CopySrcAlign);
207-
if (CopyMD)
208-
L->setMetadata(LLVMContext::MD_tbaa, CopyMD);
207+
L->setAAMetadata(AACopyMD);
209208
MDNode *LoopMemParallelMD =
210209
MI->getMetadata(LLVMContext::MD_mem_parallel_loop_access);
211210
if (LoopMemParallelMD)
@@ -217,8 +216,7 @@ Instruction *InstCombinerImpl::SimplifyAnyMemTransfer(AnyMemTransferInst *MI) {
217216
StoreInst *S = Builder.CreateStore(L, Dest);
218217
// Alignment from the mem intrinsic will be better, so use it.
219218
S->setAlignment(*CopyDstAlign);
220-
if (CopyMD)
221-
S->setMetadata(LLVMContext::MD_tbaa, CopyMD);
219+
S->setAAMetadata(AACopyMD);
222220
if (LoopMemParallelMD)
223221
S->setMetadata(LLVMContext::MD_mem_parallel_loop_access, LoopMemParallelMD);
224222
if (AccessGroupMD)

llvm/test/Transforms/InstCombine/memcpy-to-load.ll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,19 @@ define void @copy_16_bytes(ptr %d, ptr %s) {
7979
ret void
8080
}
8181

82+
define void @copy_8_bytes_noalias(ptr %d, ptr %s) {
83+
; CHECK-LABEL: @copy_8_bytes_noalias(
84+
; CHECK-NEXT: [[TMP1:%.*]] = load i64, ptr [[S:%.*]], align 1, !alias.scope [[META0:![0-9]+]], !noalias [[META3:![0-9]+]]
85+
; CHECK-NEXT: store i64 [[TMP1]], ptr [[D:%.*]], align 1, !alias.scope [[META0]], !noalias [[META3]]
86+
; CHECK-NEXT: ret void
87+
;
88+
call void @llvm.memcpy.p0.p0.i32(ptr %d, ptr %s, i32 8, i1 false), !alias.scope !4, !noalias !5
89+
ret void
90+
}
91+
92+
!0 = distinct !{!0, !"The domain"}
93+
!1 = distinct !{!1}
94+
!2 = !{!2, !0}
95+
!3 = !{!3, !1}
96+
!4 = !{!2}
97+
!5 = !{!3}

0 commit comments

Comments
 (0)