[PATCH] D34323: Add ArgMemOnly attribute to strlen and wcslen, i.e. they only read memory (string) passed to them.
Xin Tong via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 17 20:11:26 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL305641: Add argmononly attribute to strlen and wcslen, i.e. they only read memory… (authored by trentxintong).
Changed prior to commit:
https://reviews.llvm.org/D34323?vs=102953&id=102954#toc
Repository:
rL LLVM
https://reviews.llvm.org/D34323
Files:
llvm/trunk/lib/Transforms/Utils/BuildLibCalls.cpp
llvm/trunk/test/Transforms/InferFunctionAttrs/annotate.ll
llvm/trunk/test/Transforms/LICM/strlen.ll
Index: llvm/trunk/test/Transforms/InferFunctionAttrs/annotate.ll
===================================================================
--- llvm/trunk/test/Transforms/InferFunctionAttrs/annotate.ll
+++ llvm/trunk/test/Transforms/InferFunctionAttrs/annotate.ll
@@ -844,7 +844,7 @@
; CHECK: declare noalias i8* @strdup(i8* nocapture readonly) [[G0]]
declare i8* @strdup(i8*)
-; CHECK: declare i64 @strlen(i8* nocapture) [[G1]]
+; CHECK: declare i64 @strlen(i8* nocapture) [[G2:#[0-9]+]]
declare i64 @strlen(i8*)
; CHECK: declare i32 @strncasecmp(i8* nocapture, i8* nocapture, i64) [[G1]]
@@ -996,10 +996,11 @@
; memset_pattern16 isn't available everywhere.
-; CHECK-DARWIN: declare void @memset_pattern16(i8* nocapture, i8* nocapture readonly, i64) [[G2:#[0-9]+]]
+; CHECK-DARWIN: declare void @memset_pattern16(i8* nocapture, i8* nocapture readonly, i64) [[G3:#[0-9]+]]
declare void @memset_pattern16(i8*, i8*, i64)
; CHECK: attributes [[G0]] = { nounwind }
; CHECK: attributes [[G1]] = { nounwind readonly }
-; CHECK-DARWIN: attributes [[G2]] = { argmemonly }
+; CHECK: attributes [[G2]] = { argmemonly nounwind readonly }
+; CHECK-DARWIN: attributes [[G3]] = { argmemonly }
Index: llvm/trunk/test/Transforms/LICM/strlen.ll
===================================================================
--- llvm/trunk/test/Transforms/LICM/strlen.ll
+++ llvm/trunk/test/Transforms/LICM/strlen.ll
@@ -0,0 +1,19 @@
+; RUN: opt -S -inferattrs -basicaa -licm < %s | FileCheck %s
+
+define void @test(i64* noalias %loc, i8* noalias %a) {
+; CHECK-LABEL: @test
+; CHECK: @strlen
+; CHECK-LABEL: loop:
+ br label %loop
+
+loop:
+ %res = call i64 @strlen(i8* %a)
+ store i64 %res, i64* %loc
+ br label %loop
+}
+
+; CHECK: declare i64 @strlen(i8* nocapture) #0
+; CHECK: attributes #0 = { argmemonly nounwind readonly }
+declare i64 @strlen(i8*)
+
+
Index: llvm/trunk/lib/Transforms/Utils/BuildLibCalls.cpp
===================================================================
--- llvm/trunk/lib/Transforms/Utils/BuildLibCalls.cpp
+++ llvm/trunk/lib/Transforms/Utils/BuildLibCalls.cpp
@@ -116,6 +116,7 @@
case LibFunc_wcslen:
Changed |= setOnlyReadsMemory(F);
Changed |= setDoesNotThrow(F);
+ Changed |= setOnlyAccessesArgMemory(F);
Changed |= setDoesNotCapture(F, 0);
return Changed;
case LibFunc_strchr:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34323.102954.patch
Type: text/x-patch
Size: 2334 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170618/cc9ba64f/attachment.bin>
More information about the llvm-commits
mailing list