1 ; Test that the StrChrOptimizer works correctly
2 ; RUN: opt < %s -simplify-libcalls -S | \
3 ; RUN: not grep {call.*@strchr}
5 ; This transformation requires the pointer size, as it assumes that size_t is
6 ; the size of a pointer.
7 target datalayout = "-p:64:64:64"
9 @hello = constant [14 x i8] c"hello world\5Cn\00" ; <[14 x i8]*> [#uses=1]
10 @null = constant [1 x i8] zeroinitializer ; <[1 x i8]*> [#uses=1]
12 declare i8* @strchr(i8*, i32)
14 declare i32 @puts(i8*)
17 %hello_p = getelementptr [14 x i8]* @hello, i32 0, i32 0 ; <i8*> [#uses=2]
18 %null_p = getelementptr [1 x i8]* @null, i32 0, i32 0 ; <i8*> [#uses=1]
19 %world = call i8* @strchr( i8* %hello_p, i32 119 ) ; <i8*> [#uses=1]
20 %ignore = call i8* @strchr( i8* %null_p, i32 119 ) ; <i8*> [#uses=0]
21 %len = call i32 @puts( i8* %world ) ; <i32> [#uses=1]
22 %index = add i32 %len, 112 ; <i32> [#uses=2]
23 %result = call i8* @strchr( i8* %hello_p, i32 %index ) ; <i8*> [#uses=0]