blob: 89e846f3bf8cce740fee37f2666d1db5ee0d10c0 [file] [log] [blame]
Reid Spencer34efdf82005-05-03 06:22:41 +00001; Test that the StrChrOptimizer works correctly
Tanya Lattnerceca1942008-03-10 07:21:50 +00002; RUN: llvm-as < %s | opt -simplify-libcalls | llvm-dis | \
Dan Gohmanfddaa312008-05-01 23:50:07 +00003; RUN: not grep {call.*@strchr}
Reid Spencer34efdf82005-05-03 06:22:41 +00004
Dan Gohman600d52c2009-08-19 23:18:49 +00005; This transformation requires the pointer size, as it assumes that size_t is
6; the size of a pointer.
7target datalayout = "-p:64:64:64"
8
Tanya Lattnerceca1942008-03-10 07:21:50 +00009@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]
Reid Spencer34efdf82005-05-03 06:22:41 +000011
Tanya Lattnerceca1942008-03-10 07:21:50 +000012declare i8* @strchr(i8*, i32)
Reid Spencer34efdf82005-05-03 06:22:41 +000013
Tanya Lattnerceca1942008-03-10 07:21:50 +000014declare i32 @puts(i8*)
Reid Spencer34efdf82005-05-03 06:22:41 +000015
Tanya Lattnerceca1942008-03-10 07:21:50 +000016define i32 @main() {
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]
24 ret i32 %index
Reid Spencer34efdf82005-05-03 06:22:41 +000025}
Tanya Lattnerceca1942008-03-10 07:21:50 +000026