blob: 89ef4ea49a79b75352f650fe2a8e92894e1f48d6 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001; Test that the StrCatOptimizer works correctly
Ed Schouten5b9fc262009-04-06 13:06:48 +00002; PR3661
Tanya Lattner003eae52008-03-10 07:21:50 +00003; RUN: llvm-as < %s | opt -simplify-libcalls | llvm-dis | \
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004; RUN: not grep {call.*strcat}
Ed Schouten5b9fc262009-04-06 13:06:48 +00005; RUN: llvm-as < %s | opt -simplify-libcalls | llvm-dis | \
6; RUN: grep {puts.*%arg1}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007
Tanya Lattner003eae52008-03-10 07:21:50 +00008@hello = constant [6 x i8] c"hello\00" ; <[6 x i8]*> [#uses=1]
9@null = constant [1 x i8] zeroinitializer ; <[1 x i8]*> [#uses=1]
10@null_hello = constant [7 x i8] c"\00hello\00" ; <[7 x i8]*> [#uses=1]
Dan Gohmanf17a25c2007-07-18 16:29:46 +000011
Tanya Lattner003eae52008-03-10 07:21:50 +000012declare i8* @strcat(i8*, i8*)
Dan Gohmanf17a25c2007-07-18 16:29:46 +000013
Tanya Lattner003eae52008-03-10 07:21:50 +000014declare i32 @puts(i8*)
15
16define i32 @main() {
17 %target = alloca [1024 x i8] ; <[1024 x i8]*> [#uses=1]
18 %arg1 = getelementptr [1024 x i8]* %target, i32 0, i32 0 ; <i8*> [#uses=2]
19 store i8 0, i8* %arg1
20 %arg2 = getelementptr [6 x i8]* @hello, i32 0, i32 0 ; <i8*> [#uses=1]
21 %rslt1 = call i8* @strcat( i8* %arg1, i8* %arg2 ) ; <i8*> [#uses=1]
22 %arg3 = getelementptr [1 x i8]* @null, i32 0, i32 0 ; <i8*> [#uses=1]
23 %rslt2 = call i8* @strcat( i8* %rslt1, i8* %arg3 ) ; <i8*> [#uses=1]
24 %arg4 = getelementptr [7 x i8]* @null_hello, i32 0, i32 0 ; <i8*> [#uses=1]
25 %rslt3 = call i8* @strcat( i8* %rslt2, i8* %arg4 ) ; <i8*> [#uses=1]
26 call i32 @puts( i8* %rslt3 ) ; <i32>:1 [#uses=0]
27 ret i32 0
Dan Gohmanf17a25c2007-07-18 16:29:46 +000028}
Tanya Lattner003eae52008-03-10 07:21:50 +000029