blob: 45b349d6840db72331b3d0e0565c3536992c0867 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001; Test that the StrCatOptimizer works correctly
Dan Gohman3c7d3082009-09-11 18:01:28 +00002; RUN: opt < %s -simplify-libcalls -S | \
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003; RUN: not grep {call.*strlen}
4
5target datalayout = "e-p:32:32"
Tanya Lattner003eae52008-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]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00009
Tanya Lattner003eae52008-03-10 07:21:50 +000010declare i32 @strlen(i8*)
Dan Gohmanf17a25c2007-07-18 16:29:46 +000011
Tanya Lattner003eae52008-03-10 07:21:50 +000012define i32 @test1() {
13 %hello_p = getelementptr [6 x i8]* @hello, i32 0, i32 0 ; <i8*> [#uses=1]
14 %hello_l = call i32 @strlen( i8* %hello_p ) ; <i32> [#uses=1]
15 ret i32 %hello_l
Dan Gohmanf17a25c2007-07-18 16:29:46 +000016}
17
Tanya Lattner003eae52008-03-10 07:21:50 +000018define i32 @test2() {
19 %null_p = getelementptr [1 x i8]* @null, i32 0, i32 0 ; <i8*> [#uses=1]
20 %null_l = call i32 @strlen( i8* %null_p ) ; <i32> [#uses=1]
21 ret i32 %null_l
Dan Gohmanf17a25c2007-07-18 16:29:46 +000022}
23
Tanya Lattner003eae52008-03-10 07:21:50 +000024define i32 @test3() {
25 %null_hello_p = getelementptr [7 x i8]* @null_hello, i32 0, i32 0 ; <i8*> [#uses=1]
26 %null_hello_l = call i32 @strlen( i8* %null_hello_p ) ; <i32> [#uses=1]
27 ret i32 %null_hello_l
Dan Gohmanf17a25c2007-07-18 16:29:46 +000028}
29
Tanya Lattner003eae52008-03-10 07:21:50 +000030define i1 @test4() {
31 %hello_p = getelementptr [6 x i8]* @hello, i32 0, i32 0 ; <i8*> [#uses=1]
32 %hello_l = call i32 @strlen( i8* %hello_p ) ; <i32> [#uses=1]
33 %eq_hello = icmp eq i32 %hello_l, 0 ; <i1> [#uses=1]
34 ret i1 %eq_hello
Dan Gohmanf17a25c2007-07-18 16:29:46 +000035}
36
Tanya Lattner003eae52008-03-10 07:21:50 +000037define i1 @test5() {
38 %null_p = getelementptr [1 x i8]* @null, i32 0, i32 0 ; <i8*> [#uses=1]
39 %null_l = call i32 @strlen( i8* %null_p ) ; <i32> [#uses=1]
40 %eq_null = icmp eq i32 %null_l, 0 ; <i1> [#uses=1]
41 ret i1 %eq_null
Dan Gohmanf17a25c2007-07-18 16:29:46 +000042}
43
Tanya Lattner003eae52008-03-10 07:21:50 +000044define i1 @test6() {
45 %hello_p = getelementptr [6 x i8]* @hello, i32 0, i32 0 ; <i8*> [#uses=1]
46 %hello_l = call i32 @strlen( i8* %hello_p ) ; <i32> [#uses=1]
47 %ne_hello = icmp ne i32 %hello_l, 0 ; <i1> [#uses=1]
48 ret i1 %ne_hello
Dan Gohmanf17a25c2007-07-18 16:29:46 +000049}
50
Tanya Lattner003eae52008-03-10 07:21:50 +000051define i1 @test7() {
52 %null_p = getelementptr [1 x i8]* @null, i32 0, i32 0 ; <i8*> [#uses=1]
53 %null_l = call i32 @strlen( i8* %null_p ) ; <i32> [#uses=1]
54 %ne_null = icmp ne i32 %null_l, 0 ; <i1> [#uses=1]
55 ret i1 %ne_null
Dan Gohmanf17a25c2007-07-18 16:29:46 +000056}