blob: eaabeb2feb8f99058c4f2fb171778851cf66a67d [file] [log] [blame]
Reid Spencer34efdf82005-05-03 06:22:41 +00001; Test that the StrChrOptimizer works correctly
Benjamin Kramere2609902010-09-29 22:29:12 +00002; RUN: opt < %s -simplify-libcalls -S | FileCheck %s
Reid Spencer34efdf82005-05-03 06:22:41 +00003
Dan Gohman600d52c2009-08-19 23:18:49 +00004; This transformation requires the pointer size, as it assumes that size_t is
5; the size of a pointer.
6target datalayout = "-p:64:64:64"
7
Benjamin Kramere2609902010-09-29 22:29:12 +00008@hello = constant [14 x i8] c"hello world\5Cn\00"
9@null = constant [1 x i8] zeroinitializer
Reid Spencer34efdf82005-05-03 06:22:41 +000010
Tanya Lattnerceca1942008-03-10 07:21:50 +000011declare i8* @strchr(i8*, i32)
Reid Spencer34efdf82005-05-03 06:22:41 +000012
Benjamin Kramere2609902010-09-29 22:29:12 +000013define 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)
Tanya Lattnerceca1942008-03-10 07:21:50 +000024 ret i32 %index
Reid Spencer34efdf82005-05-03 06:22:41 +000025}
Tanya Lattnerceca1942008-03-10 07:21:50 +000026