blob: a8ad3699e2ab76416fea5c790efcce59e2911022 [file] [log] [blame]
Reid Spencer82be9852005-05-03 17:08:45 +00001; Test that the SPrintFOptimizer works correctly
Reid Spencer43b40032007-04-16 15:31:49 +00002; RUN: llvm-upgrade < %s | llvm-as | opt -simplify-libcalls | llvm-dis | \
3; RUN: not grep {call.*sprintf}
Reid Spencer82be9852005-05-03 17:08:45 +00004
5declare int %sprintf(sbyte*,sbyte*,...)
6declare int %puts(sbyte*)
7%hello = constant [6 x sbyte] c"hello\00"
8%null = constant [1 x sbyte] c"\00"
9%null_hello = constant [7 x sbyte] c"\00hello\00"
10%fmt1 = constant [3 x sbyte] c"%s\00"
11%fmt2 = constant [3 x sbyte] c"%c\00"
12
13implementation ; Functions:
14
Chris Lattner397fa212005-09-24 22:16:04 +000015int %foo (sbyte* %p) {
Reid Spencer82be9852005-05-03 17:08:45 +000016 %target = alloca [1024 x sbyte]
17 %target_p = getelementptr [1024 x sbyte]* %target, int 0, int 0
18 %hello_p = getelementptr [6 x sbyte]* %hello, int 0, int 0
19 %null_p = getelementptr [1 x sbyte]* %null, int 0, int 0
20 %nh_p = getelementptr [7 x sbyte]* %null_hello, int 0, int 0
21 %fmt1_p = getelementptr [3 x sbyte]* %fmt1, int 0, int 0
22 %fmt2_p = getelementptr [3 x sbyte]* %fmt2, int 0, int 0
23 store sbyte 0, sbyte* %target_p
24 %r1 = call int (sbyte*,sbyte*,...)* %sprintf(sbyte* %target_p, sbyte* %hello_p)
25 %r2 = call int (sbyte*,sbyte*,...)* %sprintf(sbyte* %target_p, sbyte* %null_p)
26 %r3 = call int (sbyte*,sbyte*,...)* %sprintf(sbyte* %target_p, sbyte* %nh_p)
27 %r4 = call int (sbyte*,sbyte*,...)* %sprintf(sbyte* %target_p, sbyte* %fmt1_p, sbyte* %hello_p)
Chris Lattner397fa212005-09-24 22:16:04 +000028 %r4.1 = call int (sbyte*,sbyte*,...)* %sprintf(sbyte* %target_p, sbyte* %fmt1_p, sbyte* %p)
Reid Spencer82be9852005-05-03 17:08:45 +000029 %r5 = call int (sbyte*,sbyte*,...)* %sprintf(sbyte* %target_p, sbyte* %fmt2_p, int 82)
30 %r6 = add int %r1, %r2
31 %r7 = add int %r3, %r6
32 %r8 = add int %r5, %r7
Chris Lattner397fa212005-09-24 22:16:04 +000033 %r9 = add int %r8, %r4
34 %r10 = add int %r9, %r4.1
35 ret int %r10
Reid Spencer82be9852005-05-03 17:08:45 +000036}