blob: 4a20bbd2ce81dfdd9df376cf841821ba15eac40c [file] [log] [blame]
Reid Spencer8fe86dd2005-04-26 05:22:38 +00001; Test that the StrCatOptimizer works correctly
Dan Gohmanf2f6ce62009-09-11 18:01:28 +00002; RUN: opt < %s -simplify-libcalls -S | \
Chandler Carruth1de43ed2012-07-02 19:09:46 +00003; RUN: not grep "call.*strlen"
Reid Spencere3ff5ad2007-01-26 08:25:06 +00004
5target datalayout = "e-p:32:32"
Tanya Lattnerceca1942008-03-10 07:21:50 +00006@hello = constant [6 x i8] c"hello\00" ; <[6 x i8]*> [#uses=3]
7@null = constant [1 x i8] zeroinitializer ; <[1 x i8]*> [#uses=3]
8@null_hello = constant [7 x i8] c"\00hello\00" ; <[7 x i8]*> [#uses=1]
Nick Lewycky0cd0fee2011-10-20 00:34:35 +00009@nullstring = constant i8 0
Reid Spencer8fe86dd2005-04-26 05:22:38 +000010
Tanya Lattnerceca1942008-03-10 07:21:50 +000011declare i32 @strlen(i8*)
Reid Spencer8fe86dd2005-04-26 05:22:38 +000012
Tanya Lattnerceca1942008-03-10 07:21:50 +000013define i32 @test1() {
14 %hello_p = getelementptr [6 x i8]* @hello, i32 0, i32 0 ; <i8*> [#uses=1]
15 %hello_l = call i32 @strlen( i8* %hello_p ) ; <i32> [#uses=1]
16 ret i32 %hello_l
Reid Spencer29a5bf52005-05-07 20:21:04 +000017}
18
Tanya Lattnerceca1942008-03-10 07:21:50 +000019define i32 @test2() {
20 %null_p = getelementptr [1 x i8]* @null, i32 0, i32 0 ; <i8*> [#uses=1]
21 %null_l = call i32 @strlen( i8* %null_p ) ; <i32> [#uses=1]
22 ret i32 %null_l
Reid Spencer29a5bf52005-05-07 20:21:04 +000023}
24
Tanya Lattnerceca1942008-03-10 07:21:50 +000025define i32 @test3() {
26 %null_hello_p = getelementptr [7 x i8]* @null_hello, i32 0, i32 0 ; <i8*> [#uses=1]
27 %null_hello_l = call i32 @strlen( i8* %null_hello_p ) ; <i32> [#uses=1]
28 ret i32 %null_hello_l
Reid Spencer29a5bf52005-05-07 20:21:04 +000029}
30
Tanya Lattnerceca1942008-03-10 07:21:50 +000031define i1 @test4() {
32 %hello_p = getelementptr [6 x i8]* @hello, i32 0, i32 0 ; <i8*> [#uses=1]
33 %hello_l = call i32 @strlen( i8* %hello_p ) ; <i32> [#uses=1]
34 %eq_hello = icmp eq i32 %hello_l, 0 ; <i1> [#uses=1]
35 ret i1 %eq_hello
Reid Spencer29a5bf52005-05-07 20:21:04 +000036}
37
Tanya Lattnerceca1942008-03-10 07:21:50 +000038define i1 @test5() {
39 %null_p = getelementptr [1 x i8]* @null, i32 0, i32 0 ; <i8*> [#uses=1]
40 %null_l = call i32 @strlen( i8* %null_p ) ; <i32> [#uses=1]
41 %eq_null = icmp eq i32 %null_l, 0 ; <i1> [#uses=1]
42 ret i1 %eq_null
Reid Spencer29a5bf52005-05-07 20:21:04 +000043}
44
Tanya Lattnerceca1942008-03-10 07:21:50 +000045define i1 @test6() {
46 %hello_p = getelementptr [6 x i8]* @hello, i32 0, i32 0 ; <i8*> [#uses=1]
47 %hello_l = call i32 @strlen( i8* %hello_p ) ; <i32> [#uses=1]
48 %ne_hello = icmp ne i32 %hello_l, 0 ; <i1> [#uses=1]
49 ret i1 %ne_hello
Reid Spencer29a5bf52005-05-07 20:21:04 +000050}
51
Tanya Lattnerceca1942008-03-10 07:21:50 +000052define i1 @test7() {
53 %null_p = getelementptr [1 x i8]* @null, i32 0, i32 0 ; <i8*> [#uses=1]
54 %null_l = call i32 @strlen( i8* %null_p ) ; <i32> [#uses=1]
55 %ne_null = icmp ne i32 %null_l, 0 ; <i1> [#uses=1]
56 ret i1 %ne_null
Reid Spencer8fe86dd2005-04-26 05:22:38 +000057}
Nick Lewycky0cd0fee2011-10-20 00:34:35 +000058
59define i32 @test8() {
60 %len = tail call i32 @strlen(i8* @nullstring) nounwind
61 ret i32 %len
62}