aboutsummaryrefslogtreecommitdiffstats
path: root/test/Transforms/SimplifyLibCalls/StrStr.ll
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-12-15 19:14:40 +0000
committerChris Lattner <sabre@nondot.org>2009-12-15 19:14:40 +0000
commita5b475def3406f1175162574ccbe300f9ab61bfd (patch)
tree31e4f0f4bdaa8a03369615a11f51c680b0f72a50 /test/Transforms/SimplifyLibCalls/StrStr.ll
parent0d810c281064e69c6a0cab4f9f43870628628566 (diff)
downloadexternal_llvm-a5b475def3406f1175162574ccbe300f9ab61bfd.zip
external_llvm-a5b475def3406f1175162574ccbe300f9ab61bfd.tar.gz
external_llvm-a5b475def3406f1175162574ccbe300f9ab61bfd.tar.bz2
optimize strstr, PR5783
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@91438 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Transforms/SimplifyLibCalls/StrStr.ll')
-rw-r--r--test/Transforms/SimplifyLibCalls/StrStr.ll48
1 files changed, 48 insertions, 0 deletions
diff --git a/test/Transforms/SimplifyLibCalls/StrStr.ll b/test/Transforms/SimplifyLibCalls/StrStr.ll
new file mode 100644
index 0000000..2cac2d4
--- /dev/null
+++ b/test/Transforms/SimplifyLibCalls/StrStr.ll
@@ -0,0 +1,48 @@
+; RUN: opt < %s -simplify-libcalls -S | FileCheck %s
+; PR5783
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32"
+target triple = "i386-apple-darwin9.0"
+
+@.str = private constant [1 x i8] zeroinitializer ; <[1 x i8]*> [#uses=1]
+@.str1 = private constant [2 x i8] c"a\00" ; <[2 x i8]*> [#uses=1]
+@.str2 = private constant [6 x i8] c"abcde\00" ; <[6 x i8]*> [#uses=1]
+@.str3 = private constant [4 x i8] c"bcd\00" ; <[4 x i8]*> [#uses=1]
+
+define i8* @test1(i8* %P) nounwind readonly {
+entry:
+ %call = tail call i8* @strstr(i8* %P, i8* getelementptr inbounds ([1 x i8]* @.str, i32 0, i32 0)) nounwind ; <i8*> [#uses=1]
+ ret i8* %call
+; strstr(P, "") -> P
+; CHECK: @test1
+; CHECK: ret i8* %P
+}
+
+declare i8* @strstr(i8*, i8* nocapture) nounwind readonly
+
+define i8* @test2(i8* %P) nounwind readonly {
+entry:
+ %call = tail call i8* @strstr(i8* %P, i8* getelementptr inbounds ([2 x i8]* @.str1, i32 0, i32 0)) nounwind ; <i8*> [#uses=1]
+ ret i8* %call
+; strstr(P, "a") -> strchr(P, 'a')
+; CHECK: @test2
+; CHECK: @strchr(i8* %P, i32 97)
+}
+
+define i8* @test3(i8* nocapture %P) nounwind readonly {
+entry:
+ %call = tail call i8* @strstr(i8* getelementptr inbounds ([6 x i8]* @.str2, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8]* @.str3, i32 0, i32 0)) nounwind ; <i8*> [#uses=1]
+ ret i8* %call
+; strstr("abcde", "bcd") -> "abcde"+1
+; CHECK: @test3
+; CHECK: getelementptr inbounds ([6 x i8]* @.str2, i32 0, i64 1)
+}
+
+define i8* @test4(i8* %P) nounwind readonly {
+entry:
+ %call = tail call i8* @strstr(i8* %P, i8* %P) nounwind ; <i8*> [#uses=1]
+ ret i8* %call
+; strstr(P, P) -> P
+; CHECK: @test4
+; CHECK: ret i8* %P
+}