Home | History | Annotate | Download | only in SimplifyLibCalls
      1 ; Test that the StrCatOptimizer works correctly
      2 ; RUN: opt < %s -simplify-libcalls -S | \
      3 ; RUN:    not grep "call.*strlen"
      4 
      5 target datalayout = "e-p:32:32"
      6 @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]
      9 @nullstring = constant i8 0
     10 
     11 declare i32 @strlen(i8*)
     12 
     13 define 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
     17 }
     18 
     19 define 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
     23 }
     24 
     25 define 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
     29 }
     30 
     31 define 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
     36 }
     37 
     38 define 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
     43 }
     44 
     45 define 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
     50 }
     51 
     52 define 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
     57 }
     58 
     59 define i32 @test8() {
     60 	%len = tail call i32 @strlen(i8* @nullstring) nounwind
     61 	ret i32 %len
     62 }
     63