; Test that the StrChrOptimizer works correctly
-; RUN: llvm-upgrade < %s | llvm-as | opt -simplify-libcalls | llvm-dis | not grep 'call.*%strchr'
+; RUN: opt < %s -simplify-libcalls -S | FileCheck %s
-declare sbyte* %strchr(sbyte*,int)
-declare int %puts(sbyte*)
-%hello = constant [14 x sbyte] c"hello world\n\00"
-%null = constant [1 x sbyte] c"\00"
+; This transformation requires the pointer size, as it assumes that size_t is
+; the size of a pointer.
+target datalayout = "-p:64:64:64"
-implementation ; Functions:
+@hello = constant [14 x i8] c"hello world\5Cn\00"
+@null = constant [1 x i8] zeroinitializer
-int %main () {
- %hello_p = getelementptr [14 x sbyte]* %hello, int 0, int 0
- %null_p = getelementptr [1 x sbyte]* %null, int 0, int 0
+declare i8* @strchr(i8*, i32)
- %world = call sbyte* %strchr(sbyte* %hello_p, int 119 )
- %ignore = call sbyte* %strchr(sbyte* %null_p, int 119 )
- %len = call int %puts(sbyte* %world)
- %index = add int %len, 112
- %result = call sbyte* %strchr(sbyte* %hello_p, int %index)
- ret int %index
+define i32 @foo(i32 %index) {
+ %hello_p = getelementptr [14 x i8]* @hello, i32 0, i32 0
+ %null_p = getelementptr [1 x i8]* @null, i32 0, i32 0
+ %world = call i8* @strchr(i8* %hello_p, i32 119)
+; CHECK: getelementptr i8* %hello_p, i64 6
+ %ignore = call i8* @strchr(i8* %null_p, i32 119)
+; CHECK-NOT: call i8* strchr
+ %null = call i8* @strchr(i8* %hello_p, i32 0)
+; CHECK: getelementptr i8* %hello_p, i64 13
+ %result = call i8* @strchr(i8* %hello_p, i32 %index)
+; CHECK: call i8* @memchr(i8* %hello_p, i32 %index, i64 14)
+ ret i32 %index
}
+