[DSE] Add test to make sure memccpy does not kill stores.
authorFlorian Hahn <flo@fhahn.com>
Tue, 20 Oct 2020 12:56:46 +0000 (13:56 +0100)
committerFlorian Hahn <flo@fhahn.com>
Tue, 20 Oct 2020 13:18:11 +0000 (14:18 +0100)
It is not known how many bytes are written by memccpy, so it cannot kill
any stores.

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

index 37f8e46..5bd0c82 100644 (file)
@@ -334,6 +334,33 @@ entry:
   ret i8* %res
 }
 
+; Make sure memccpy does not kill any stores, because it is not known how many
+; bytes are written.
+define i8* @test_memccpy_const_size_does_not_kill_stores(i8* noalias %dest, i8* noalias %foo) {
+; CHECK-LABEL: @test_memccpy_const_size_does_not_kill_stores(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    store i8 49, i8* [[DEST:%.*]], align 1
+; CHECK-NEXT:    [[GEP_1:%.*]] = getelementptr i8, i8* [[DEST]], i64 1
+; CHECK-NEXT:    store i8 50, i8* [[GEP_1]], align 1
+; CHECK-NEXT:    [[GEP_2:%.*]] = getelementptr i8, i8* [[DEST]], i64 2
+; CHECK-NEXT:    store i8 51, i8* [[GEP_2]], align 1
+; CHECK-NEXT:    [[GEP_3:%.*]] = getelementptr i8, i8* [[DEST]], i64 3
+; CHECK-NEXT:    store i8 52, i8* [[GEP_3]], align 1
+; CHECK-NEXT:    [[RES:%.*]] = call i8* @memccpy(i8* [[DEST]], i8* [[FOO:%.*]], i32 42, i64 2)
+; CHECK-NEXT:    ret i8* [[RES]]
+;
+entry:
+  store i8 49, i8* %dest, align 1
+  %gep.1 = getelementptr i8, i8* %dest, i64 1
+  store i8 50, i8* %gep.1, align 1
+  %gep.2 = getelementptr i8, i8* %dest, i64 2
+  store i8 51, i8* %gep.2, align 1
+  %gep.3 = getelementptr i8, i8* %dest, i64 3
+  store i8 52, i8* %gep.3, align 1
+  %res = call i8* @memccpy(i8* %dest, i8* %foo, i32 42, i64 2)
+  ret i8* %res
+}
+
 define void @dse_strcpy(i8* nocapture readonly %src) {
 ; CHECK-LABEL: @dse_strcpy(
 ; CHECK-NEXT:    [[A:%.*]] = alloca [256 x i8], align 16