summaryrefslogtreecommitdiff
path: root/test/Transforms/SimplifyLibCalls
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2010-09-30 00:58:35 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2010-09-30 00:58:35 +0000
commit9510a2538bcf5e3b42b9ee02ff527fd6681af0ad (patch)
tree07a0e448e13c1f3a34e071bdf4c16b437323317a /test/Transforms/SimplifyLibCalls
parent3eddd98be31342af81705faf00234b954ff447cf (diff)
downloadllvm-9510a2538bcf5e3b42b9ee02ff527fd6681af0ad.tar.gz
llvm-9510a2538bcf5e3b42b9ee02ff527fd6681af0ad.tar.bz2
llvm-9510a2538bcf5e3b42b9ee02ff527fd6681af0ad.tar.xz
Add constant folding for strspn and strcspn to SimplifyLibCalls.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@115116 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Transforms/SimplifyLibCalls')
-rw-r--r--test/Transforms/SimplifyLibCalls/StrSpn.ll41
1 files changed, 41 insertions, 0 deletions
diff --git a/test/Transforms/SimplifyLibCalls/StrSpn.ll b/test/Transforms/SimplifyLibCalls/StrSpn.ll
new file mode 100644
index 0000000000..f77f32c67c
--- /dev/null
+++ b/test/Transforms/SimplifyLibCalls/StrSpn.ll
@@ -0,0 +1,41 @@
+; RUN: opt < %s -simplify-libcalls -S | FileCheck %s
+
+target datalayout = "-p:64:64:64"
+
+@abcba = constant [6 x i8] c"abcba\00"
+@abc = constant [4 x i8] c"abc\00"
+@null = constant [1 x i8] zeroinitializer
+
+declare i64 @strspn(i8*, i8*)
+
+define i64 @testspn(i8* %s1, i8* %s2) {
+ %abcba_p = getelementptr [6 x i8]* @abcba, i32 0, i32 0
+ %abc_p = getelementptr [4 x i8]* @abc, i32 0, i32 0
+ %null_p = getelementptr [1 x i8]* @null, i32 0, i32 0
+ %test1 = call i64 @strspn(i8* %s1, i8* %null_p)
+ %test2 = call i64 @strspn(i8* %null_p, i8* %s2)
+ %test3 = call i64 @strspn(i8* %abcba_p, i8* %abc_p)
+; CHECK-NOT: call i64 @strspn
+ %test4 = call i64 @strspn(i8* %s1, i8* %s2)
+; CHECK: call i64 @strspn(i8* %s1, i8* %s2)
+ ret i64 %test3
+; CHECK ret i64 5
+}
+
+declare i64 @strcspn(i8*, i8*)
+
+define i64 @testcspn(i8* %s1, i8* %s2) {
+ %abcba_p = getelementptr [6 x i8]* @abcba, i32 0, i32 0
+ %abc_p = getelementptr [4 x i8]* @abc, i32 0, i32 0
+ %null_p = getelementptr [1 x i8]* @null, i32 0, i32 0
+ %test1 = call i64 @strcspn(i8* %s1, i8* %null_p)
+; CHECK: call i64 @strlen(i8* %s1)
+ %test2 = call i64 @strcspn(i8* %null_p, i8* %s2)
+ %test3 = call i64 @strcspn(i8* %abcba_p, i8* %abc_p)
+; CHECK-NOT: call i64 @strcspn
+ %test4 = call i64 @strcspn(i8* %s1, i8* %s2)
+; CHECK: call i64 @strcspn(i8* %s1, i8* %s2)
+ %add0 = add i64 %test1, %test3
+; CHECK: add i64 %{{.+}}, 0
+ ret i64 %add0
+}