[BuildLibCalls] Add nounwind,willreturn to memset_pattern{4,8,16}.

Similar to memset, memset_pattern{4,8,16} all will return and do not
unwind. Use fallthrough to include all attributes also set for memset.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D114904
This commit is contained in:
Florian Hahn 2022-01-12 10:32:52 +00:00
parent 39385d4cd1
commit e3275cfa94
No known key found for this signature in database
GPG Key ID: CF59919C6547A668
3 changed files with 7 additions and 16 deletions

View File

@ -1019,12 +1019,10 @@ bool llvm::inferLibFuncAttributes(Function &F, const TargetLibraryInfo &TLI) {
case LibFunc_memset_pattern4:
case LibFunc_memset_pattern8:
case LibFunc_memset_pattern16:
Changed |= setOnlyAccessesArgMemory(F);
Changed |= setDoesNotCapture(F, 0);
Changed |= setOnlyWritesMemory(F, 0);
Changed |= setDoesNotCapture(F, 1);
Changed |= setOnlyReadsMemory(F, 1);
return Changed;
LLVM_FALLTHROUGH;
case LibFunc_memset:
Changed |= setWillReturn(F);
LLVM_FALLTHROUGH;

View File

@ -10,9 +10,7 @@ declare void @memset_pattern16(i8*, i8*, i64)
define void @test_memset_pattern4_const_size(i8* noalias %a, i8* noalias %pattern) {
; CHECK-LABEL: @test_memset_pattern4_const_size(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[A_GEP_1:%.*]] = getelementptr i8, i8* [[A:%.*]], i32 1
; CHECK-NEXT: store i8 0, i8* [[A_GEP_1]], align 1
; CHECK-NEXT: [[A_GEP_17:%.*]] = getelementptr i8, i8* [[A]], i32 17
; CHECK-NEXT: [[A_GEP_17:%.*]] = getelementptr i8, i8* [[A:%.*]], i32 17
; CHECK-NEXT: store i8 1, i8* [[A_GEP_17]], align 1
; CHECK-NEXT: call void @memset_pattern4(i8* [[A]], i8* [[PATTERN:%.*]], i64 17)
; CHECK-NEXT: ret void
@ -48,9 +46,7 @@ entry:
define void @test_memset_pattern8_const_size(i8* noalias %a, i8* noalias %pattern) {
; CHECK-LABEL: @test_memset_pattern8_const_size(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[A_GEP_1:%.*]] = getelementptr i8, i8* [[A:%.*]], i32 1
; CHECK-NEXT: store i8 0, i8* [[A_GEP_1]], align 1
; CHECK-NEXT: [[A_GEP_17:%.*]] = getelementptr i8, i8* [[A]], i32 17
; CHECK-NEXT: [[A_GEP_17:%.*]] = getelementptr i8, i8* [[A:%.*]], i32 17
; CHECK-NEXT: store i8 1, i8* [[A_GEP_17]], align 1
; CHECK-NEXT: call void @memset_pattern8(i8* [[A]], i8* [[PATTERN:%.*]], i64 17)
; CHECK-NEXT: ret void
@ -86,9 +82,7 @@ entry:
define void @test_memset_pattern16_const_size(i8* noalias %a, i8* noalias %pattern) {
; CHECK-LABEL: @test_memset_pattern16_const_size(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[A_GEP_1:%.*]] = getelementptr i8, i8* [[A:%.*]], i32 1
; CHECK-NEXT: store i8 0, i8* [[A_GEP_1]], align 1
; CHECK-NEXT: [[A_GEP_17:%.*]] = getelementptr i8, i8* [[A]], i32 17
; CHECK-NEXT: [[A_GEP_17:%.*]] = getelementptr i8, i8* [[A:%.*]], i32 17
; CHECK-NEXT: store i8 1, i8* [[A_GEP_17]], align 1
; CHECK-NEXT: call void @memset_pattern16(i8* [[A]], i8* [[PATTERN:%.*]], i64 17)
; CHECK-NEXT: ret void

View File

@ -1055,11 +1055,11 @@ declare i64 @write(i32, i8*, i64)
; memset_pattern{4,8,16} aren't available everywhere.
; CHECK-DARWIN: declare void @memset_pattern4(i8* nocapture writeonly, i8* nocapture readonly, i64) [[ARGMEMONLY_NOFREE:#[0-9]+]]
; CHECK-DARWIN: declare void @memset_pattern4(i8* nocapture writeonly, i8* nocapture readonly, i64) [[ARGMEMONLY_NOFREE_NOUNWIND_WILLRETURN]]
declare void @memset_pattern4(i8*, i8*, i64)
; CHECK-DARWIN: declare void @memset_pattern8(i8* nocapture writeonly, i8* nocapture readonly, i64) [[ARGMEMONLY_NOFREE]]
; CHECK-DARWIN: declare void @memset_pattern8(i8* nocapture writeonly, i8* nocapture readonly, i64) [[ARGMEMONLY_NOFREE_NOUNWIND_WILLRETURN]]
declare void @memset_pattern8(i8*, i8*, i64)
; CHECK-DARWIN: declare void @memset_pattern16(i8* nocapture writeonly, i8* nocapture readonly, i64) [[ARGMEMONLY_NOFREE]]
; CHECK-DARWIN: declare void @memset_pattern16(i8* nocapture writeonly, i8* nocapture readonly, i64) [[ARGMEMONLY_NOFREE_NOUNWIND_WILLRETURN]]
declare void @memset_pattern16(i8*, i8*, i64)
@ -1077,5 +1077,4 @@ declare void @memset_pattern16(i8*, i8*, i64)
; CHECK-DAG: attributes [[INACCESSIBLEMEMORARGONLY_NOFREE_NOUNWIND_WILLRETURN]] = { inaccessiblemem_or_argmemonly mustprogress nofree nounwind willreturn }
; CHECK-DAG: attributes [[ARGMEMONLY_NOFREE_NOUNWIND]] = { argmemonly nofree nounwind }
; CHECK-DARWIN-DAG: attributes [[ARGMEMONLY_NOFREE]] = { argmemonly nofree }
; CHECK-NVPTX-DAG: attributes [[NOFREE_NOUNWIND_READNONE]] = { nofree nosync nounwind readnone }