blob: c1cf39f337466d3f7ed1ed9a3d6a5c85d8a43b76 [file] [log] [blame]
Tanya Lattnerfc887452008-03-01 07:38:40 +00001; RUN: llvm-as < %s | llvm-dis > %t1.ll
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll
3; RUN: diff %t1.ll %t2.ll
4
Tanya Lattnerfc887452008-03-01 07:38:40 +00005declare i32 @atoi(i8*)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006
Tanya Lattnerfc887452008-03-01 07:38:40 +00007define i64 @fib(i64 %n) {
8 icmp ult i64 %n, 2 ; <i1>:1 [#uses=1]
9 br i1 %1, label %BaseCase, label %RecurseCase
Dan Gohmanf17a25c2007-07-18 16:29:46 +000010
Tanya Lattnerfc887452008-03-01 07:38:40 +000011BaseCase: ; preds = %0
12 ret i64 1
Dan Gohmanf17a25c2007-07-18 16:29:46 +000013
Tanya Lattnerfc887452008-03-01 07:38:40 +000014RecurseCase: ; preds = %0
15 %n2 = sub i64 %n, 2 ; <i64> [#uses=1]
16 %n1 = sub i64 %n, 1 ; <i64> [#uses=1]
17 %f2 = call i64 @fib( i64 %n2 ) ; <i64> [#uses=1]
18 %f1 = call i64 @fib( i64 %n1 ) ; <i64> [#uses=1]
19 %result = add i64 %f2, %f1 ; <i64> [#uses=1]
20 ret i64 %result
21}
Dan Gohmanf17a25c2007-07-18 16:29:46 +000022
Tanya Lattnerfc887452008-03-01 07:38:40 +000023define i64 @realmain(i32 %argc, i8** %argv) {
24; <label>:0
25 icmp eq i32 %argc, 2 ; <i1>:1 [#uses=1]
26 br i1 %1, label %HasArg, label %Continue
Dan Gohmanf17a25c2007-07-18 16:29:46 +000027
Tanya Lattnerfc887452008-03-01 07:38:40 +000028HasArg: ; preds = %0
29 %n1 = add i32 1, 1 ; <i32> [#uses=1]
30 br label %Continue
Dan Gohmanf17a25c2007-07-18 16:29:46 +000031
Tanya Lattnerfc887452008-03-01 07:38:40 +000032Continue: ; preds = %HasArg, %0
33 %n = phi i32 [ %n1, %HasArg ], [ 1, %0 ] ; <i32> [#uses=1]
34 %N = sext i32 %n to i64 ; <i64> [#uses=1]
35 %F = call i64 @fib( i64 %N ) ; <i64> [#uses=1]
36 ret i64 %F
37}
Dan Gohmanf17a25c2007-07-18 16:29:46 +000038
Tanya Lattnerfc887452008-03-01 07:38:40 +000039define i64 @trampoline(i64 %n, i64 (i64)* %fibfunc) {
40 %F = call i64 %fibfunc( i64 %n ) ; <i64> [#uses=1]
41 ret i64 %F
42}
Dan Gohmanf17a25c2007-07-18 16:29:46 +000043
Tanya Lattnerfc887452008-03-01 07:38:40 +000044define i32 @main() {
45 %Result = call i64 @trampoline( i64 10, i64 (i64)* @fib ) ; <i64> [#uses=1]
46 %Result.upgrd.1 = trunc i64 %Result to i32 ; <i32> [#uses=1]
47 ret i32 %Result.upgrd.1
48}
Dan Gohmanf17a25c2007-07-18 16:29:46 +000049