Reid Spencer | c094836 | 2007-01-16 18:08:22 +0000 | [diff] [blame] | 1 | ; RUN: llvm-as %s -o - | llvm-dis > %t1.ll |
| 2 | ; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll |
| 3 | ; RUN: diff %t1.ll %t2.ll |
| 4 | |
Reid Spencer | c094836 | 2007-01-16 18:08:22 +0000 | [diff] [blame] | 5 | |
Reid Spencer | e3ff5ad | 2007-01-26 08:25:06 +0000 | [diff] [blame] | 6 | declare i32 @"atoi"(i8 *) |
Reid Spencer | c094836 | 2007-01-16 18:08:22 +0000 | [diff] [blame] | 7 | |
Reid Spencer | e3ff5ad | 2007-01-26 08:25:06 +0000 | [diff] [blame] | 8 | define i63 @"fib"(i63 %n) |
Reid Spencer | c094836 | 2007-01-16 18:08:22 +0000 | [diff] [blame] | 9 | begin |
Reid Spencer | 2318ec6 | 2007-03-19 18:27:35 +0000 | [diff] [blame] | 10 | icmp ult i63 %n, 2 ; {i1}:1 |
| 11 | br i1 %1, label %BaseCase, label %RecurseCase |
Reid Spencer | c094836 | 2007-01-16 18:08:22 +0000 | [diff] [blame] | 12 | |
| 13 | BaseCase: |
| 14 | ret i63 1 |
| 15 | |
| 16 | RecurseCase: |
| 17 | %n2 = sub i63 %n, 2 |
| 18 | %n1 = sub i63 %n, 1 |
Reid Spencer | e3ff5ad | 2007-01-26 08:25:06 +0000 | [diff] [blame] | 19 | %f2 = call i63(i63) * @fib(i63 %n2) |
| 20 | %f1 = call i63(i63) * @fib(i63 %n1) |
Reid Spencer | c094836 | 2007-01-16 18:08:22 +0000 | [diff] [blame] | 21 | %result = add i63 %f2, %f1 |
| 22 | ret i63 %result |
| 23 | end |
| 24 | |
Reid Spencer | e3ff5ad | 2007-01-26 08:25:06 +0000 | [diff] [blame] | 25 | define i63 @"realmain"(i32 %argc, i8 ** %argv) |
Reid Spencer | c094836 | 2007-01-16 18:08:22 +0000 | [diff] [blame] | 26 | begin |
Reid Spencer | 2318ec6 | 2007-03-19 18:27:35 +0000 | [diff] [blame] | 27 | icmp eq i32 %argc, 2 ; {i1}:1 |
| 28 | br i1 %1, label %HasArg, label %Continue |
Reid Spencer | c094836 | 2007-01-16 18:08:22 +0000 | [diff] [blame] | 29 | HasArg: |
| 30 | ; %n1 = atoi(argv[1]) |
| 31 | %n1 = add i32 1, 1 |
| 32 | br label %Continue |
| 33 | |
| 34 | Continue: |
| 35 | %n = phi i32 [%n1, %HasArg], [1, %0] |
| 36 | %N = sext i32 %n to i63 |
Reid Spencer | e3ff5ad | 2007-01-26 08:25:06 +0000 | [diff] [blame] | 37 | %F = call i63(i63) *@fib(i63 %N) |
Reid Spencer | c094836 | 2007-01-16 18:08:22 +0000 | [diff] [blame] | 38 | ret i63 %F |
| 39 | end |
| 40 | |
Reid Spencer | e3ff5ad | 2007-01-26 08:25:06 +0000 | [diff] [blame] | 41 | define i63 @"trampoline"(i63 %n, i63(i63)* %fibfunc) |
Reid Spencer | c094836 | 2007-01-16 18:08:22 +0000 | [diff] [blame] | 42 | begin |
| 43 | %F = call i63(i63) *%fibfunc(i63 %n) |
| 44 | ret i63 %F |
| 45 | end |
| 46 | |
Reid Spencer | e3ff5ad | 2007-01-26 08:25:06 +0000 | [diff] [blame] | 47 | define i32 @"main"() |
Reid Spencer | c094836 | 2007-01-16 18:08:22 +0000 | [diff] [blame] | 48 | begin |
Reid Spencer | e3ff5ad | 2007-01-26 08:25:06 +0000 | [diff] [blame] | 49 | %Result = call i63 @trampoline(i63 10, i63(i63) *@fib) |
Reid Spencer | 9085043 | 2007-01-30 16:16:01 +0000 | [diff] [blame] | 50 | %Result2 = trunc i63 %Result to i32 |
| 51 | ret i32 %Result2 |
Reid Spencer | c094836 | 2007-01-16 18:08:22 +0000 | [diff] [blame] | 52 | end |