[llvm] [MemCpyOpt] Combine alias metadatas when replacing byval arguments (PR #70580)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 28 22:32:07 PDT 2023
https://github.com/DianQK updated https://github.com/llvm/llvm-project/pull/70580
>From 8cdf321394884b8f40e06ad0e930bd0fd03d8c61 Mon Sep 17 00:00:00 2001
From: DianQK <dianqk at dianqk.net>
Date: Sun, 29 Oct 2023 10:53:46 +0800
Subject: [PATCH 1/3] [MemCpyOpt] Pre-commit for byval noalias
---
llvm/test/Transforms/MemCpyOpt/memcpy.ll | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/llvm/test/Transforms/MemCpyOpt/memcpy.ll b/llvm/test/Transforms/MemCpyOpt/memcpy.ll
index f7c1c85517ffa32..2917b384ca36b0b 100644
--- a/llvm/test/Transforms/MemCpyOpt/memcpy.ll
+++ b/llvm/test/Transforms/MemCpyOpt/memcpy.ll
@@ -393,6 +393,7 @@ declare void @f1(ptr nocapture sret(%struct.big))
declare void @f2(ptr)
declare void @f(ptr)
+declare void @f_byval(ptr byval(i32))
declare void @f_full_readonly(ptr nocapture noalias readonly)
define void @immut_param(ptr align 4 noalias %val) {
@@ -709,6 +710,21 @@ define void @immut_param_noalias_metadata(ptr align 4 byval(i32) %ptr) {
ret void
}
+define void @byval_param_noalias_metadata(ptr align 4 byval(i32) %ptr) {
+; CHECK-LABEL: @byval_param_noalias_metadata(
+; CHECK-NEXT: call void @f_byval(ptr byval(i32) align 4 [[PTR:%.*]]), !alias.scope !3
+; CHECK-NEXT: ret void
+;
+ %tmp = alloca i32, align 4
+ store i32 1, ptr %ptr, !noalias !5
+ call void @llvm.memcpy.p0.p0.i64(ptr align 4 %tmp, ptr align 4 %ptr, i64 4, i1 false)
+ call void @f_byval(ptr align 4 byval(i32) %tmp), !alias.scope !5
+ ret void
+}
+
!0 = !{!0}
!1 = !{!1, !0}
!2 = !{!1}
+!3 = !{!3}
+!4 = !{!4, !3}
+!5 = !{!4}
>From 6104b84d57a335601722682876c89ebbe91e855e Mon Sep 17 00:00:00 2001
From: DianQK <dianqk at dianqk.net>
Date: Sun, 29 Oct 2023 10:55:07 +0800
Subject: [PATCH 2/3] [MemCpyOpt] Combine alias metadatas when replacing byval
arguments
---
llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp | 1 +
llvm/test/Transforms/MemCpyOpt/memcpy.ll | 3 ++-
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
index b366ec5d4c35725..a31dedafdcbc449 100644
--- a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
+++ b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
@@ -1864,6 +1864,7 @@ bool MemCpyOptPass::processByValArgument(CallBase &CB, unsigned ArgNo) {
<< " " << CB << "\n");
// Otherwise we're good! Update the byval argument.
+ combineAAMetadata(&CB, MDep);
CB.setArgOperand(ArgNo, MDep->getSource());
++NumMemCpyInstr;
return true;
diff --git a/llvm/test/Transforms/MemCpyOpt/memcpy.ll b/llvm/test/Transforms/MemCpyOpt/memcpy.ll
index 2917b384ca36b0b..7d3b4fdc1c111fe 100644
--- a/llvm/test/Transforms/MemCpyOpt/memcpy.ll
+++ b/llvm/test/Transforms/MemCpyOpt/memcpy.ll
@@ -712,7 +712,8 @@ define void @immut_param_noalias_metadata(ptr align 4 byval(i32) %ptr) {
define void @byval_param_noalias_metadata(ptr align 4 byval(i32) %ptr) {
; CHECK-LABEL: @byval_param_noalias_metadata(
-; CHECK-NEXT: call void @f_byval(ptr byval(i32) align 4 [[PTR:%.*]]), !alias.scope !3
+; CHECK-NEXT: store i32 1, ptr [[PTR:%.*]], align 4, !noalias !3
+; CHECK-NEXT: call void @f_byval(ptr byval(i32) align 4 [[PTR]])
; CHECK-NEXT: ret void
;
%tmp = alloca i32, align 4
>From 62de993bf1addc618f85c1fd6a058318718d208b Mon Sep 17 00:00:00 2001
From: DianQK <dianqk at dianqk.net>
Date: Sun, 29 Oct 2023 13:31:51 +0800
Subject: [PATCH 3/3] fixup! [MemCpyOpt] Pre-commit for byval noalias
Remove duplicate metadata
---
llvm/test/Transforms/MemCpyOpt/memcpy.ll | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/llvm/test/Transforms/MemCpyOpt/memcpy.ll b/llvm/test/Transforms/MemCpyOpt/memcpy.ll
index 7d3b4fdc1c111fe..7488203d5db16dd 100644
--- a/llvm/test/Transforms/MemCpyOpt/memcpy.ll
+++ b/llvm/test/Transforms/MemCpyOpt/memcpy.ll
@@ -712,20 +712,17 @@ define void @immut_param_noalias_metadata(ptr align 4 byval(i32) %ptr) {
define void @byval_param_noalias_metadata(ptr align 4 byval(i32) %ptr) {
; CHECK-LABEL: @byval_param_noalias_metadata(
-; CHECK-NEXT: store i32 1, ptr [[PTR:%.*]], align 4, !noalias !3
+; CHECK-NEXT: store i32 1, ptr [[PTR:%.*]], align 4, !noalias !0
; CHECK-NEXT: call void @f_byval(ptr byval(i32) align 4 [[PTR]])
; CHECK-NEXT: ret void
;
%tmp = alloca i32, align 4
- store i32 1, ptr %ptr, !noalias !5
+ store i32 1, ptr %ptr, !noalias !2
call void @llvm.memcpy.p0.p0.i64(ptr align 4 %tmp, ptr align 4 %ptr, i64 4, i1 false)
- call void @f_byval(ptr align 4 byval(i32) %tmp), !alias.scope !5
+ call void @f_byval(ptr align 4 byval(i32) %tmp), !alias.scope !2
ret void
}
!0 = !{!0}
!1 = !{!1, !0}
!2 = !{!1}
-!3 = !{!3}
-!4 = !{!4, !3}
-!5 = !{!4}
More information about the llvm-commits
mailing list