1 ; Test that the StrChrOptimizer works correctly 2 ; RUN: opt < %s -simplify-libcalls -S | FileCheck %s 3 4 ; This transformation requires the pointer size, as it assumes that size_t is 5 ; the size of a pointer. 6 target datalayout = "-p:64:64:64" 7 8 @hello = constant [14 x i8] c"hello world\5Cn\00" 9 @null = constant [1 x i8] zeroinitializer 10 11 declare i8* @strchr(i8*, i32) 12 13 define i32 @foo(i32 %index) { 14 %hello_p = getelementptr [14 x i8]* @hello, i32 0, i32 0 15 %null_p = getelementptr [1 x i8]* @null, i32 0, i32 0 16 %world = call i8* @strchr(i8* %hello_p, i32 119) 17 ; CHECK: getelementptr i8* %hello_p, i64 6 18 %ignore = call i8* @strchr(i8* %null_p, i32 119) 19 ; CHECK-NOT: call i8* strchr 20 %null = call i8* @strchr(i8* %hello_p, i32 0) 21 ; CHECK: getelementptr i8* %hello_p, i64 13 22 %result = call i8* @strchr(i8* %hello_p, i32 %index) 23 ; CHECK: call i8* @memchr(i8* %hello_p, i32 %index, i64 14) 24 ret i32 %index 25 } 26 27