blob: 50ca0a6edbf88c87d8017f5e53822bf2a12a0e42 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001; Test that the StrChrOptimizer works correctly
Dan Gohman3c7d3082009-09-11 18:01:28 +00002; RUN: opt < %s -simplify-libcalls -S | \
Dan Gohman3c250772008-05-01 23:50:07 +00003; RUN: not grep {call.*@strchr}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004
Dan Gohman132fc1c2009-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 Lattner003eae52008-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]
Dan Gohmanf17a25c2007-07-18 16:29:46 +000011
Tanya Lattner003eae52008-03-10 07:21:50 +000012declare i8* @strchr(i8*, i32)
Dan Gohmanf17a25c2007-07-18 16:29:46 +000013
Tanya Lattner003eae52008-03-10 07:21:50 +000014declare i32 @puts(i8*)
Dan Gohmanf17a25c2007-07-18 16:29:46 +000015
Tanya Lattner003eae52008-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
Dan Gohmanf17a25c2007-07-18 16:29:46 +000025}
Tanya Lattner003eae52008-03-10 07:21:50 +000026