[llvm] r305641 - Add argmononly attribute to strlen and wcslen, i.e. they only read memory (string) passed to them.
Xin Tong via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 17 20:10:26 PDT 2017
Author: trentxintong
Date: Sat Jun 17 22:10:26 2017
New Revision: 305641
URL: http://llvm.org/viewvc/llvm-project?rev=305641&view=rev
Log:
Add argmononly attribute to strlen and wcslen, i.e. they only read memory (string) passed to them.
Summary:
This allows strlen to be moved out of the loop in case its argument is
not modified in the loop in LICM.
Reviewers: hfinkel, davide, sanjoy, dberlin
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D34323
Added:
llvm/trunk/test/Transforms/LICM/strlen.ll
Modified:
llvm/trunk/lib/Transforms/Utils/BuildLibCalls.cpp
llvm/trunk/test/Transforms/InferFunctionAttrs/annotate.ll
Modified: llvm/trunk/lib/Transforms/Utils/BuildLibCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/BuildLibCalls.cpp?rev=305641&r1=305640&r2=305641&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/BuildLibCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/BuildLibCalls.cpp Sat Jun 17 22:10:26 2017
@@ -116,6 +116,7 @@ bool llvm::inferLibFuncAttributes(Functi
case LibFunc_wcslen:
Changed |= setOnlyReadsMemory(F);
Changed |= setDoesNotThrow(F);
+ Changed |= setOnlyAccessesArgMemory(F);
Changed |= setDoesNotCapture(F, 0);
return Changed;
case LibFunc_strchr:
Modified: llvm/trunk/test/Transforms/InferFunctionAttrs/annotate.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InferFunctionAttrs/annotate.ll?rev=305641&r1=305640&r2=305641&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InferFunctionAttrs/annotate.ll (original)
+++ llvm/trunk/test/Transforms/InferFunctionAttrs/annotate.ll Sat Jun 17 22:10:26 2017
@@ -844,7 +844,7 @@ declare i64 @strcspn(i8*, i8*)
; 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 @@ declare i64 @write(i32, i8*, i64)
; 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 }
Added: llvm/trunk/test/Transforms/LICM/strlen.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LICM/strlen.ll?rev=305641&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/LICM/strlen.ll (added)
+++ llvm/trunk/test/Transforms/LICM/strlen.ll Sat Jun 17 22:10:26 2017
@@ -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*)
+
+
More information about the llvm-commits
mailing list