[llvm] 86c95dc - [test][InstCombine] Add tests for removing memcpy to an alloca that is passed to a readonly nocapture function parameter, in preparation for D136822.
Patrick Walton via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 30 02:46:19 PDT 2022
Author: Patrick Walton
Date: 2022-10-30T02:45:49-07:00
New Revision: 86c95dca5c1b09d4184e90c18a53fe6384d94fba
URL: https://github.com/llvm/llvm-project/commit/86c95dca5c1b09d4184e90c18a53fe6384d94fba
DIFF: https://github.com/llvm/llvm-project/commit/86c95dca5c1b09d4184e90c18a53fe6384d94fba.diff
LOG: [test][InstCombine] Add tests for removing memcpy to an alloca that is passed to a readonly nocapture function parameter, in preparation for D136822.
This commit adds tests to Transforms/InstCombine/memcpy-from-global.ll that
test various situations involving memcpy from a constant to an alloca that is
then passed to function parameters with various attributes. The forthcoming
D136822 allows InstCombine to remove these memcpys if they're passed to a
single readonly nocapture parameter.
Differential Revision: https://reviews.llvm.org/D137033
Added:
Modified:
llvm/test/Transforms/InstCombine/memcpy-from-global.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/memcpy-from-global.ll b/llvm/test/Transforms/InstCombine/memcpy-from-global.ll
index a0cd39b233ee..128c68c54ef8 100644
--- a/llvm/test/Transforms/InstCombine/memcpy-from-global.ll
+++ b/llvm/test/Transforms/InstCombine/memcpy-from-global.ll
@@ -380,4 +380,52 @@ define void @volatile_memcpy() {
ret void
}
+; Test that we don't yet elide a memcpy when copying a constant value onto the
+; stack and then forwarding it by readonly nocapture reference.
+define void @memcpy_to_nocapture_readonly() {
+; CHECK-LABEL: @memcpy_to_nocapture_readonly(
+; CHECK-NEXT: [[A:%.*]] = alloca [[U:%.*]], align 16
+; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(20) [[A]], ptr noundef nonnull align 16 dereferenceable(20) @H, i64 20, i1 false)
+; CHECK-NEXT: call void @bar(ptr nocapture nonnull readonly [[A]])
+; CHECK-NEXT: ret void
+;
+ %A = alloca %U, align 16
+ call void @llvm.memcpy.p0.p0.i64(ptr align 4 %A, ptr align 4 @H, i64 20, i1 false)
+ call void @bar(ptr nocapture readonly %A)
+ ret void
+}
+
+; Test that we don't elide the memcpy when copying a constant value onto the
+; stack and then forwarding it by readonly, but capturing, reference.
+define void @memcpy_to_capturing_readonly() {
+; CHECK-LABEL: @memcpy_to_capturing_readonly(
+; CHECK-NEXT: [[A:%.*]] = alloca [[U:%.*]], align 16
+; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(20) [[A]], ptr noundef nonnull align 16 dereferenceable(20) @H, i64 20, i1 false)
+; CHECK-NEXT: call void @bar(ptr nonnull readonly [[A]])
+; CHECK-NEXT: ret void
+;
+ %A = alloca %U, align 16
+ call void @llvm.memcpy.p0.p0.i64(ptr align 4 %A, ptr align 4 @H, i64 20, i1 false)
+ call void @bar(ptr readonly %A)
+ ret void
+}
+
+; Test that we don't elide the memcpy when copying a constant value onto the
+; stack and then forwarding it by read-write, nocapture reference, even if it's
+; also forwarded by readonly nocapture reference to the same function.
+define void @memcpy_to_aliased_nocapture_readonly() {
+; CHECK-LABEL: @memcpy_to_aliased_nocapture_readonly(
+; CHECK-NEXT: [[A:%.*]] = alloca [[U:%.*]], align 16
+; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(20) [[A]], ptr noundef nonnull align 16 dereferenceable(20) @H, i64 20, i1 false)
+; CHECK-NEXT: call void @two_params(ptr nocapture nonnull readonly [[A]], ptr nocapture nonnull [[A]])
+; CHECK-NEXT: ret void
+;
+ %A = alloca %U, align 16
+ call void @llvm.memcpy.p0.p0.i64(ptr align 4 %A, ptr align 4 @H, i64 20, i1 false)
+ call void @two_params(ptr nocapture readonly %A, ptr nocapture %A)
+ ret void
+}
+
+declare void @two_params(ptr nocapture readonly, ptr nocapture)
+
attributes #0 = { null_pointer_is_valid }
More information about the llvm-commits
mailing list