diff --git a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp --- a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp +++ b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp @@ -186,6 +186,7 @@ return Changed; case LibFunc_strchr: case LibFunc_strrchr: + Changed |= setOnlyAccessesArgMemory(F); Changed |= setOnlyReadsMemory(F); Changed |= setDoesNotThrow(F); return Changed; @@ -225,9 +226,17 @@ case LibFunc_strspn: // 0,1 case LibFunc_strncmp: // 0,1 case LibFunc_strcspn: // 0,1 - case LibFunc_strcoll: // 0,1 + Changed |= setDoesNotThrow(F); + Changed |= setOnlyAccessesArgMemory(F); + Changed |= setOnlyReadsMemory(F); + Changed |= setDoesNotCapture(F, 0); + Changed |= setDoesNotCapture(F, 1); + return Changed; + case LibFunc_strcoll: case LibFunc_strcasecmp: // 0,1 case LibFunc_strncasecmp: // + // Those functions may depend on the locale, which may be accessed through + // global memory. Changed |= setOnlyReadsMemory(F); Changed |= setDoesNotThrow(F); Changed |= setDoesNotCapture(F, 0); @@ -310,6 +319,7 @@ Changed |= setRetDoesNotAlias(F); return Changed; case LibFunc_memcmp: + Changed |= setOnlyAccessesArgMemory(F); Changed |= setOnlyReadsMemory(F); Changed |= setDoesNotThrow(F); Changed |= setDoesNotCapture(F, 0); @@ -317,8 +327,9 @@ return Changed; case LibFunc_memchr: case LibFunc_memrchr: - Changed |= setOnlyReadsMemory(F); Changed |= setDoesNotThrow(F); + Changed |= setOnlyAccessesArgMemory(F); + Changed |= setOnlyReadsMemory(F); return Changed; case LibFunc_modf: case LibFunc_modff: @@ -327,24 +338,27 @@ Changed |= setDoesNotCapture(F, 1); return Changed; case LibFunc_memcpy: + Changed |= setDoesNotThrow(F); + Changed |= setOnlyAccessesArgMemory(F); Changed |= setDoesNotAlias(F, 0); - Changed |= setDoesNotAlias(F, 1); Changed |= setReturnedArg(F, 0); - Changed |= setDoesNotThrow(F); + Changed |= setDoesNotAlias(F, 1); Changed |= setDoesNotCapture(F, 1); Changed |= setOnlyReadsMemory(F, 1); return Changed; case LibFunc_memmove: - Changed |= setReturnedArg(F, 0); Changed |= setDoesNotThrow(F); + Changed |= setOnlyAccessesArgMemory(F); + Changed |= setReturnedArg(F, 0); Changed |= setDoesNotCapture(F, 1); Changed |= setOnlyReadsMemory(F, 1); return Changed; case LibFunc_mempcpy: case LibFunc_memccpy: + Changed |= setDoesNotThrow(F); + Changed |= setOnlyAccessesArgMemory(F); Changed |= setDoesNotAlias(F, 0); Changed |= setDoesNotAlias(F, 1); - Changed |= setDoesNotThrow(F); Changed |= setDoesNotCapture(F, 1); Changed |= setOnlyReadsMemory(F, 1); return Changed; @@ -416,6 +430,7 @@ return Changed; case LibFunc_bcmp: Changed |= setDoesNotThrow(F); + Changed |= setOnlyAccessesArgMemory(F); Changed |= setOnlyReadsMemory(F); Changed |= setDoesNotCapture(F, 0); Changed |= setDoesNotCapture(F, 1); diff --git a/llvm/test/Transforms/InferFunctionAttrs/annotate.ll b/llvm/test/Transforms/InferFunctionAttrs/annotate.ll --- a/llvm/test/Transforms/InferFunctionAttrs/annotate.ll +++ b/llvm/test/Transforms/InferFunctionAttrs/annotate.ll @@ -241,7 +241,7 @@ ; CHECK: declare i64 @atoll(i8* nocapture) [[G2]] declare i64 @atoll(i8*) -; CHECK-LINUX: declare i32 @bcmp(i8* nocapture, i8* nocapture, i64) [[G2]] +; CHECK-LINUX: declare i32 @bcmp(i8* nocapture, i8* nocapture, i64) [[ARGMEMONLY_NOFREE_NOUNWIND_READONLY:#[0-9]+]] ; CHECK-DARWIN-NOT: declare i32 @bcmp(i8* nocapture, i8* nocapture, i64) [[G2]] ; CHECK-UNKNOWN-NOT: declare i32 @bcmp(i8* nocapture, i8* nocapture, i64) [[G2]] ; CHECK-NVPTX-NOT: declare i32 @bcmp(i8* nocapture, i8* nocapture, i64) [[G2]] @@ -619,22 +619,24 @@ ; CHECK-LINUX: declare noalias i8* @memalign(i64, i64) [[G0]] declare i8* @memalign(i64, i64) -; CHECK: declare i8* @memccpy(i8* noalias, i8* noalias nocapture readonly, i32, i64) [[G1]] +; CHECK: declare i8* @memccpy(i8* noalias, i8* noalias nocapture readonly, i32, i64) [[ARGMEMONLY_NOFREE_NOUNWIND:#[0-9]+]] declare i8* @memccpy(i8*, i8*, i32, i64) -; CHECK: declare i8* @memchr(i8*, i32, i64) [[G2]] +; CHECK-LINUX: declare i8* @memchr(i8*, i32, i64) [[ARGMEMONLY_NOFREE_NOUNWIND_READONLY]] +; CHECK-DARWIN: declare i8* @memchr(i8*, i32, i64) [[ARGMEMONLY_NOFREE_NOUNWIND_READONLY:#[0-9]+]] +; CHECK-UNKNOWN: declare i8* @memchr(i8*, i32, i64) [[ARGMEMONLY_NOFREE_NOUNWIND_READONLY:#[0-9]+]] declare i8* @memchr(i8*, i32, i64) -; CHECK: declare i32 @memcmp(i8* nocapture, i8* nocapture, i64) [[G2]] +; CHECK: declare i32 @memcmp(i8* nocapture, i8* nocapture, i64) [[ARGMEMONLY_NOFREE_NOUNWIND_READONLY]] declare i32 @memcmp(i8*, i8*, i64) -; CHECK: declare i8* @memcpy(i8* noalias returned, i8* noalias nocapture readonly, i64) [[G1]] +; CHECK: declare i8* @memcpy(i8* noalias returned, i8* noalias nocapture readonly, i64) [[ARGMEMONLY_NOFREE_NOUNWIND]] declare i8* @memcpy(i8*, i8*, i64) -; CHECK: declare i8* @mempcpy(i8* noalias, i8* noalias nocapture readonly, i64) [[G1]] +; CHECK: declare i8* @mempcpy(i8* noalias, i8* noalias nocapture readonly, i64) [[ARGMEMONLY_NOFREE_NOUNWIND]] declare i8* @mempcpy(i8*, i8*, i64) -; CHECK: declare i8* @memmove(i8* returned, i8* nocapture readonly, i64) [[G1]] +; CHECK: declare i8* @memmove(i8* returned, i8* nocapture readonly, i64) [[ARGMEMONLY_NOFREE_NOUNWIND]] declare i8* @memmove(i8*, i8*, i64) ; CHECK: declare i8* @memset(i8*, i32, i64) [[G0]] @@ -835,10 +837,10 @@ ; CHECK: declare i8* @strcat(i8* returned, i8* nocapture readonly) [[G1]] declare i8* @strcat(i8*, i8*) -; CHECK: declare i8* @strchr(i8*, i32) [[G2]] +; CHECK: declare i8* @strchr(i8*, i32) [[ARGMEMONLY_NOFREE_NOUNWIND_READONLY]] declare i8* @strchr(i8*, i32) -; CHECK: declare i32 @strcmp(i8* nocapture, i8* nocapture) [[G2]] +; CHECK: declare i32 @strcmp(i8* nocapture, i8* nocapture) [[ARGMEMONLY_NOFREE_NOUNWIND_READONLY]] declare i32 @strcmp(i8*, i8*) ; CHECK: declare i32 @strcoll(i8* nocapture, i8* nocapture) [[G2]] @@ -847,13 +849,13 @@ ; CHECK: declare i8* @strcpy(i8* noalias returned, i8* noalias nocapture readonly) [[G1]] declare i8* @strcpy(i8*, i8*) -; CHECK: declare i64 @strcspn(i8* nocapture, i8* nocapture) [[G2]] +; CHECK: declare i64 @strcspn(i8* nocapture, i8* nocapture) [[ARGMEMONLY_NOFREE_NOUNWIND_READONLY]] declare i64 @strcspn(i8*, i8*) ; CHECK: declare noalias i8* @strdup(i8* nocapture readonly) [[G1]] declare i8* @strdup(i8*) -; CHECK: declare i64 @strlen(i8* nocapture) [[G4:#[0-9]+]] +; CHECK: declare i64 @strlen(i8* nocapture) [[ARGMEMONLY_NOFREE_NOUNWIND_READONLY]] declare i64 @strlen(i8*) ; CHECK: declare i32 @strncasecmp(i8* nocapture, i8* nocapture, i64) [[G2]] @@ -862,7 +864,7 @@ ; CHECK: declare i8* @strncat(i8* returned, i8* nocapture readonly, i64) [[G1]] declare i8* @strncat(i8*, i8*, i64) -; CHECK: declare i32 @strncmp(i8* nocapture, i8* nocapture, i64) [[G2]] +; CHECK: declare i32 @strncmp(i8* nocapture, i8* nocapture, i64) [[ARGMEMONLY_NOFREE_NOUNWIND_READONLY]] declare i32 @strncmp(i8*, i8*, i64) ; CHECK: declare i8* @strncpy(i8* noalias returned, i8* noalias nocapture readonly, i64) [[G1]] @@ -877,10 +879,10 @@ ; CHECK: declare i8* @strpbrk(i8*, i8* nocapture) [[G2]] declare i8* @strpbrk(i8*, i8*) -; CHECK: declare i8* @strrchr(i8*, i32) [[G2]] +; CHECK: declare i8* @strrchr(i8*, i32) [[ARGMEMONLY_NOFREE_NOUNWIND_READONLY]] declare i8* @strrchr(i8*, i32) -; CHECK: declare i64 @strspn(i8* nocapture, i8* nocapture) [[G2]] +; CHECK: declare i64 @strspn(i8* nocapture, i8* nocapture) [[ARGMEMONLY_NOFREE_NOUNWIND_READONLY]] declare i64 @strspn(i8*, i8*) ; CHECK: declare i8* @strstr(i8*, i8* nocapture) [[G2]] @@ -1005,12 +1007,13 @@ ; memset_pattern16 isn't available everywhere. -; CHECK-DARWIN: declare void @memset_pattern16(i8* nocapture, i8* nocapture readonly, i64) [[G5:#[0-9]+]] +; CHECK-DARWIN: declare void @memset_pattern16(i8* nocapture, i8* nocapture readonly, i64) [[G6:#[0-9]+]] declare void @memset_pattern16(i8*, i8*, i64) ; CHECK: attributes [[G0]] = { nofree } ; CHECK: attributes [[G1]] = { nofree nounwind } -; CHECK: attributes [[G2]] = { nofree nounwind readonly } -; CHECK: attributes [[G3]] = { nounwind } -; CHECK: attributes [[G4]] = { argmemonly nofree nounwind readonly } -; CHECK-DARWIN: attributes [[G5]] = { argmemonly nofree } +; CHECK-DAG: attributes [[G2]] = { nofree nounwind readonly } +; CHECK-DAG: attributes [[ARGMEMONLY_NOFREE_NOUNWIND_READONLY]] = { argmemonly nofree nounwind readonly } +; CHECK-DAG: attributes [[G3]] = { nounwind } +; CHECK-DAG: attributes [[ARGMEMONLY_NOFREE_NOUNWIND]] = { argmemonly nofree nounwind } +; CHECK-DARWIN: attributes [[G6]] = { argmemonly nofree }