Skip to content

Commit d605a11

Browse files
[Intrinsics] Added writeonly attribute to the first arg of llvm.memmove
D18714 introduced writeonly attribute: "Also start using the attribute for memset, memcpy, and memmove intrinsics, and remove their special-casing in BasicAliasAnalysis." But actually, writeonly was not attached to memmove - oversight, it seems. So let's add it. As we can see, this helps DSE to eliminate redundant stores. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D89724
1 parent 93671ff commit d605a11

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

llvm/include/llvm/IR/Intrinsics.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,8 @@ def int_memmove : Intrinsic<[],
583583
llvm_i1_ty],
584584
[IntrArgMemOnly, IntrWillReturn,
585585
NoCapture<ArgIndex<0>>, NoCapture<ArgIndex<1>>,
586-
ReadOnly<ArgIndex<1>>, ImmArg<ArgIndex<3>>]>;
586+
WriteOnly<ArgIndex<0>>, ReadOnly<ArgIndex<1>>,
587+
ImmArg<ArgIndex<3>>]>;
587588
def int_memset : Intrinsic<[],
588589
[llvm_anyptr_ty, llvm_i8_ty, llvm_anyint_ty,
589590
llvm_i1_ty],

llvm/test/Bitcode/upgrade-memory-intrinsics.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ define void @test2(i8* %p1, i8* %p2, i8* %p3) {
2929

3030
; CHECK: declare void @llvm.memset.p0i8.i64(i8* nocapture writeonly, i8, i64, i1 immarg)
3131
; CHECK: declare void @llvm.memcpy.p0i8.p0i8.i64(i8* noalias nocapture writeonly, i8* noalias nocapture readonly, i64, i1 immarg)
32-
; CHECK: declare void @llvm.memmove.p0i8.p0i8.i64(i8* nocapture, i8* nocapture readonly, i64, i1 immarg)
32+
; CHECK: declare void @llvm.memmove.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture readonly, i64, i1 immarg)
3333
declare void @llvm.memset.p0i8.i64(i8* nocapture writeonly, i8, i64, i32, i1)
3434
declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture writeonly , i8* nocapture readonly, i64, i32, i1)
35-
declare void @llvm.memmove.p0i8.p0i8.i64(i8* nocapture, i8* nocapture readonly, i64, i32, i1)
35+
declare void @llvm.memmove.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture readonly, i64, i32, i1)
3636

llvm/test/Transforms/DeadStoreElimination/MSSA/memintrinsics.ll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ define void @test1(i8* noalias %A, i8* noalias %B) {
1818
ret void
1919
}
2020

21-
; FIXME: We should eliminate this dead store.
2221
define void @test2(i8* noalias %A, i8* noalias %B) {
2322
; CHECK-LABEL: @test2(
24-
; CHECK-NEXT: store i8 0, i8* [[A:%.*]], align 1
2523
; CHECK-NEXT: call void @llvm.memmove.p0i8.p0i8.i8(i8* [[A]], i8* [[B:%.*]], i8 12, i1 false)
2624
; CHECK-NEXT: ret void
2725
;

0 commit comments

Comments
 (0)