diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp --- a/llvm/lib/Transforms/Scalar/GVN.cpp +++ b/llvm/lib/Transforms/Scalar/GVN.cpp @@ -1398,6 +1398,10 @@ NewLoad->setMetadata(LLVMContext::MD_invariant_group, InvGroupMD); if (auto *RangeMD = LI->getMetadata(LLVMContext::MD_range)) NewLoad->setMetadata(LLVMContext::MD_range, RangeMD); + if (auto *AccessMD = LI->getMetadata(LLVMContext::MD_access_group)) + if (this->LI && this->LI->getLoopFor(LI->getParent()) == + this->LI->getLoopFor(UnavailablePred)) + NewLoad->setMetadata(LLVMContext::MD_access_group, AccessMD); // We do not propagate the old load's debug location, because the new // load now lives in a different BB, and we want to avoid a jumpy line diff --git a/llvm/test/Transforms/GVN/PRE/load-pre-metadata-accsess-group.ll b/llvm/test/Transforms/GVN/PRE/load-pre-metadata-accsess-group.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Transforms/GVN/PRE/load-pre-metadata-accsess-group.ll @@ -0,0 +1,33 @@ +; RUN: opt < %s -basic-aa -gvn -enable-load-pre -S | FileCheck %s + +define dso_local void @test1(i32* nocapture readonly %aa, i32* nocapture %bb) local_unnamed_addr { +; CHECK-LABEL: @test1( +entry: + %arrayidx = getelementptr inbounds i32, i32* %bb, i64 1 + %arrayidx2 = getelementptr inbounds i32, i32* %aa, i64 1 + %0 = load i32, i32* %arrayidx2, align 4 + store i32 %0, i32* %arrayidx, align 4 + br label %for.body + +for.body: + %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ] + %arrayidx4 = getelementptr inbounds i32, i32* %aa, i64 %indvars.iv + %1 = load i32, i32* %arrayidx4, align 4, !llvm.access.group !1 + %2 = load i32, i32* %arrayidx, align 4, !llvm.access.group !1 + %mul = mul nsw i32 %2, %1 + store i32 %mul, i32* %arrayidx4, align 4, !llvm.access.group !1 + %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 + %exitcond = icmp ne i64 %indvars.iv.next, 100 + br i1 %exitcond, label %for.body, label %for.end, !llvm.loop !2 + +;CHECK-LABEL: for.body.for.body_crit_edge: +;CHECK-NEXT: %.pre = load i32, i32* %arrayidx, align 4, !llvm.access.group !0 + +for.end: + ret void +} + +!1 = distinct !{} +!2 = distinct !{!2, !3, !4} +!3 = !{!"llvm.loop.parallel_accesses", !1} +!4 = !{!"llvm.loop.vectorize.enable", i1 true}