Skip to content

Commit 5963bcd

Browse files
authored
Merge pull request #27 from JuliaLang/gb/patch
[InstCombine] Dont throw away noalias/alias scope metadata when inlin…
2 parents 057d350 + 23319f5 commit 5963bcd

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
@@ -185,10 +185,10 @@ Instruction *InstCombinerImpl::SimplifyAnyMemTransfer(AnyMemTransferInst *MI) {
185185

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

203203
Value *Src = Builder.CreateBitCast(MI->getArgOperand(1), NewSrcPtrTy);
204204
Value *Dest = Builder.CreateBitCast(MI->getArgOperand(0), NewDstPtrTy);
205205
LoadInst *L = Builder.CreateLoad(IntType, Src);
206206
// Alignment from the mem intrinsic will be better, so use it.
207207
L->setAlignment(*CopySrcAlign);
208-
if (CopyMD)
209-
L->setMetadata(LLVMContext::MD_tbaa, CopyMD);
208+
L->setAAMetadata(AACopyMD);
210209
MDNode *LoopMemParallelMD =
211210
MI->getMetadata(LLVMContext::MD_mem_parallel_loop_access);
212211
if (LoopMemParallelMD)
@@ -218,8 +217,7 @@ Instruction *InstCombinerImpl::SimplifyAnyMemTransfer(AnyMemTransferInst *MI) {
218217
StoreInst *S = Builder.CreateStore(L, Dest);
219218
// Alignment from the mem intrinsic will be better, so use it.
220219
S->setAlignment(*CopyDstAlign);
221-
if (CopyMD)
222-
S->setMetadata(LLVMContext::MD_tbaa, CopyMD);
220+
S->setAAMetadata(AACopyMD);
223221
if (LoopMemParallelMD)
224222
S->setMetadata(LLVMContext::MD_mem_parallel_loop_access, LoopMemParallelMD);
225223
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)