diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -178,25 +178,21 @@ LoadInst *L = Builder.CreateLoad(IntType, Src); // Alignment from the mem intrinsic will be better, so use it. L->setAlignment(*CopySrcAlign); + L->copyMetadata(*MI, + {LLVMContext::MD_access_group, LLVMContext::MD_annotation, + LLVMContext::MD_mem_parallel_loop_access}); if (CopyMD) L->setMetadata(LLVMContext::MD_tbaa, CopyMD); - MDNode *LoopMemParallelMD = - MI->getMetadata(LLVMContext::MD_mem_parallel_loop_access); - if (LoopMemParallelMD) - L->setMetadata(LLVMContext::MD_mem_parallel_loop_access, LoopMemParallelMD); - MDNode *AccessGroupMD = MI->getMetadata(LLVMContext::MD_access_group); - if (AccessGroupMD) - L->setMetadata(LLVMContext::MD_access_group, AccessGroupMD); StoreInst *S = Builder.CreateStore(L, Dest); // Alignment from the mem intrinsic will be better, so use it. S->setAlignment(*CopyDstAlign); + + S->copyMetadata(*MI, + {LLVMContext::MD_access_group, LLVMContext::MD_annotation, + LLVMContext::MD_mem_parallel_loop_access}); if (CopyMD) S->setMetadata(LLVMContext::MD_tbaa, CopyMD); - if (LoopMemParallelMD) - S->setMetadata(LLVMContext::MD_mem_parallel_loop_access, LoopMemParallelMD); - if (AccessGroupMD) - S->setMetadata(LLVMContext::MD_access_group, AccessGroupMD); if (auto *MT = dyn_cast(MI)) { // non-atomics can be volatile @@ -265,6 +261,7 @@ S->setAlignment(Alignment); if (isa(MI)) S->setOrdering(AtomicOrdering::Unordered); + S->copyMetadata(*MI, {LLVMContext::MD_annotation}); // Set the size of the copy to 0, it will be deleted on the next iteration. MI->setLength(Constant::getNullValue(LenC->getType())); diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp --- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp @@ -1102,6 +1102,8 @@ CallInst *NewCI = B.CreateMemCpy(CI->getArgOperand(0), Align(1), CI->getArgOperand(1), Align(1), Size); NewCI->setAttributes(CI->getAttributes()); + if (MDNode *AnnotationMD = CI->getMetadata(LLVMContext::MD_annotation)) + NewCI->setMetadata(LLVMContext::MD_annotation, AnnotationMD); return CI->getArgOperand(0); } @@ -1164,6 +1166,8 @@ CallInst *NewCI = B.CreateMemMove(CI->getArgOperand(0), Align(1), CI->getArgOperand(1), Align(1), Size); NewCI->setAttributes(CI->getAttributes()); + if (MDNode *AnnotationMD = CI->getMetadata(LLVMContext::MD_annotation)) + NewCI->setMetadata(LLVMContext::MD_annotation, AnnotationMD); return CI->getArgOperand(0); } @@ -1224,6 +1228,8 @@ Value *Val = B.CreateIntCast(CI->getArgOperand(1), B.getInt8Ty(), false); CallInst *NewCI = B.CreateMemSet(CI->getArgOperand(0), Val, Size, Align(1)); NewCI->setAttributes(CI->getAttributes()); + if (MDNode *AnnotationMD = CI->getMetadata(LLVMContext::MD_annotation)) + NewCI->setMetadata(LLVMContext::MD_annotation, AnnotationMD); return CI->getArgOperand(0); } @@ -3261,6 +3267,8 @@ B.CreateMemCpy(CI->getArgOperand(0), Align(1), CI->getArgOperand(1), Align(1), CI->getArgOperand(2)); NewCI->setAttributes(CI->getAttributes()); + if (MDNode *AnnotationMD = CI->getMetadata(LLVMContext::MD_annotation)) + NewCI->setMetadata(LLVMContext::MD_annotation, AnnotationMD); return CI->getArgOperand(0); } return nullptr; @@ -3273,6 +3281,8 @@ B.CreateMemMove(CI->getArgOperand(0), Align(1), CI->getArgOperand(1), Align(1), CI->getArgOperand(2)); NewCI->setAttributes(CI->getAttributes()); + if (MDNode *AnnotationMD = CI->getMetadata(LLVMContext::MD_annotation)) + NewCI->setMetadata(LLVMContext::MD_annotation, AnnotationMD); return CI->getArgOperand(0); } return nullptr; @@ -3287,6 +3297,8 @@ CallInst *NewCI = B.CreateMemSet(CI->getArgOperand(0), Val, CI->getArgOperand(2), Align(1)); NewCI->setAttributes(CI->getAttributes()); + if (MDNode *AnnotationMD = CI->getMetadata(LLVMContext::MD_annotation)) + NewCI->setMetadata(LLVMContext::MD_annotation, AnnotationMD); return CI->getArgOperand(0); } return nullptr; diff --git a/llvm/test/Transforms/InstCombine/annotations.ll b/llvm/test/Transforms/InstCombine/annotations.ll --- a/llvm/test/Transforms/InstCombine/annotations.ll +++ b/llvm/test/Transforms/InstCombine/annotations.ll @@ -8,8 +8,8 @@ define void @copy_1_byte(i8* %d, i8* %s) { ; CHECK-LABEL: @copy_1_byte( -; CHECK-NEXT: [[TMP1:%.*]] = load i8, i8* [[S:%.*]], align 1 -; CHECK-NEXT: store i8 [[TMP1]], i8* [[D:%.*]], align 1 +; CHECK-NEXT: [[TMP1:%.*]] = load i8, i8* [[S:%.*]], align 1, !annotation !0 +; CHECK-NEXT: store i8 [[TMP1]], i8* [[D:%.*]], align 1, !annotation !0 ; CHECK-NEXT: ret void ; call void @llvm.memcpy.p0i8.p0i8.i32(i8* %d, i8* %s, i32 1, i1 false), !annotation !0 @@ -20,8 +20,8 @@ define void @libcallcopy_1_byte(i8* %d, i8* %s) { ; CHECK-LABEL: @libcallcopy_1_byte( -; CHECK-NEXT: [[TMP1:%.*]] = load i8, i8* [[S:%.*]], align 1 -; CHECK-NEXT: store i8 [[TMP1]], i8* [[D:%.*]], align 1 +; CHECK-NEXT: [[TMP1:%.*]] = load i8, i8* [[S:%.*]], align 1, !annotation !0 +; CHECK-NEXT: store i8 [[TMP1]], i8* [[D:%.*]], align 1, !annotation !0 ; CHECK-NEXT: ret void ; call i8* @memcpy(i8* %d, i8* %s, i64 1), !annotation !0 @@ -32,8 +32,8 @@ define void @libcallcopy_1_byte_chk(i8* %d, i8* %s) { ; CHECK-LABEL: @libcallcopy_1_byte_chk( -; CHECK-NEXT: [[TMP1:%.*]] = load i8, i8* [[S:%.*]], align 1 -; CHECK-NEXT: store i8 [[TMP1]], i8* [[D:%.*]], align 1 +; CHECK-NEXT: [[TMP1:%.*]] = load i8, i8* [[S:%.*]], align 1, !annotation !0 +; CHECK-NEXT: store i8 [[TMP1]], i8* [[D:%.*]], align 1, !annotation !0 ; CHECK-NEXT: ret void ; call i8* @__memcpy_chk(i8* %d, i8* %s, i64 1, i64 1), !annotation !0 @@ -44,8 +44,8 @@ define void @move_1_byte(i8* %d, i8* %s) { ; CHECK-LABEL: @move_1_byte( -; CHECK-NEXT: [[TMP1:%.*]] = load i8, i8* [[S:%.*]], align 1 -; CHECK-NEXT: store i8 [[TMP1]], i8* [[D:%.*]], align 1 +; CHECK-NEXT: [[TMP1:%.*]] = load i8, i8* [[S:%.*]], align 1, !annotation !0 +; CHECK-NEXT: store i8 [[TMP1]], i8* [[D:%.*]], align 1, !annotation !0 ; CHECK-NEXT: ret void ; call void @llvm.memmove.p0i8.p0i8.i32(i8* %d, i8* %s, i32 1, i1 false), !annotation !0 @@ -56,8 +56,8 @@ define void @libcallmove_1_byte(i8* %d, i8* %s) { ; CHECK-LABEL: @libcallmove_1_byte( -; CHECK-NEXT: [[TMP1:%.*]] = load i8, i8* [[S:%.*]], align 1 -; CHECK-NEXT: store i8 [[TMP1]], i8* [[D:%.*]], align 1 +; CHECK-NEXT: [[TMP1:%.*]] = load i8, i8* [[S:%.*]], align 1, !annotation !0 +; CHECK-NEXT: store i8 [[TMP1]], i8* [[D:%.*]], align 1, !annotation !0 ; CHECK-NEXT: ret void ; call i8* @memmove(i8* %d, i8* %s, i64 1), !annotation !0 @@ -68,8 +68,8 @@ define void @libcallmove_1_byte_chk(i8* %d, i8* %s) { ; CHECK-LABEL: @libcallmove_1_byte_chk( -; CHECK-NEXT: [[TMP1:%.*]] = load i8, i8* [[S:%.*]], align 1 -; CHECK-NEXT: store i8 [[TMP1]], i8* [[D:%.*]], align 1 +; CHECK-NEXT: [[TMP1:%.*]] = load i8, i8* [[S:%.*]], align 1, !annotation !0 +; CHECK-NEXT: store i8 [[TMP1]], i8* [[D:%.*]], align 1, !annotation !0 ; CHECK-NEXT: ret void ; call i8* @__memmove_chk(i8* %d, i8* %s, i64 1, i64 1), !annotation !0 @@ -80,7 +80,7 @@ define void @set_1_byte(i8* %d) { ; CHECK-LABEL: @set_1_byte( -; CHECK-NEXT: store i8 1, i8* [[D:%.*]], align 1 +; CHECK-NEXT: store i8 1, i8* [[D:%.*]], align 1, !annotation !0 ; CHECK-NEXT: ret void ; call void @llvm.memset.p0i8.i32(i8* %d, i8 1, i32 1, i1 false), !annotation !0 @@ -91,7 +91,7 @@ define void @libcall_set_1_byte(i8* %d) { ; CHECK-LABEL: @libcall_set_1_byte( -; CHECK-NEXT: store i8 1, i8* [[D:%.*]], align 1 +; CHECK-NEXT: store i8 1, i8* [[D:%.*]], align 1, !annotation !0 ; CHECK-NEXT: ret void ; call i8* @memset(i8* %d, i32 1, i64 1), !annotation !0 @@ -102,7 +102,7 @@ define void @libcall_set_1_byte_chk(i8* %d) { ; CHECK-LABEL: @libcall_set_1_byte_chk( -; CHECK-NEXT: store i8 1, i8* [[D:%.*]], align 1 +; CHECK-NEXT: store i8 1, i8* [[D:%.*]], align 1, !annotation !0 ; CHECK-NEXT: ret void ; call i8* @__memset_chk(i8* %d, i32 1, i64 1, i64 1), !annotation !0