2007-01-16 19:08:22 +01:00
|
|
|
; RUN: llvm-as %s -o - | llvm-dis > %t1.ll
|
|
|
|
; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll
|
|
|
|
; RUN: diff %t1.ll %t2.ll
|
|
|
|
|
|
|
|
|
2007-01-26 09:25:06 +01:00
|
|
|
declare i32 @"atoi"(i8 *)
|
2007-01-16 19:08:22 +01:00
|
|
|
|
2007-01-26 09:25:06 +01:00
|
|
|
define i63 @"fib"(i63 %n)
|
2007-01-16 19:08:22 +01:00
|
|
|
begin
|
2007-03-19 19:27:35 +01:00
|
|
|
icmp ult i63 %n, 2 ; {i1}:1
|
|
|
|
br i1 %1, label %BaseCase, label %RecurseCase
|
2007-01-16 19:08:22 +01:00
|
|
|
|
|
|
|
BaseCase:
|
|
|
|
ret i63 1
|
|
|
|
|
|
|
|
RecurseCase:
|
|
|
|
%n2 = sub i63 %n, 2
|
|
|
|
%n1 = sub i63 %n, 1
|
2007-01-26 09:25:06 +01:00
|
|
|
%f2 = call i63(i63) * @fib(i63 %n2)
|
|
|
|
%f1 = call i63(i63) * @fib(i63 %n1)
|
2007-01-16 19:08:22 +01:00
|
|
|
%result = add i63 %f2, %f1
|
|
|
|
ret i63 %result
|
|
|
|
end
|
|
|
|
|
2007-01-26 09:25:06 +01:00
|
|
|
define i63 @"realmain"(i32 %argc, i8 ** %argv)
|
2007-01-16 19:08:22 +01:00
|
|
|
begin
|
2007-03-19 19:27:35 +01:00
|
|
|
icmp eq i32 %argc, 2 ; {i1}:1
|
|
|
|
br i1 %1, label %HasArg, label %Continue
|
2007-01-16 19:08:22 +01:00
|
|
|
HasArg:
|
|
|
|
; %n1 = atoi(argv[1])
|
|
|
|
%n1 = add i32 1, 1
|
|
|
|
br label %Continue
|
|
|
|
|
|
|
|
Continue:
|
|
|
|
%n = phi i32 [%n1, %HasArg], [1, %0]
|
|
|
|
%N = sext i32 %n to i63
|
2007-01-26 09:25:06 +01:00
|
|
|
%F = call i63(i63) *@fib(i63 %N)
|
2007-01-16 19:08:22 +01:00
|
|
|
ret i63 %F
|
|
|
|
end
|
|
|
|
|
2007-01-26 09:25:06 +01:00
|
|
|
define i63 @"trampoline"(i63 %n, i63(i63)* %fibfunc)
|
2007-01-16 19:08:22 +01:00
|
|
|
begin
|
|
|
|
%F = call i63(i63) *%fibfunc(i63 %n)
|
|
|
|
ret i63 %F
|
|
|
|
end
|
|
|
|
|
2007-01-26 09:25:06 +01:00
|
|
|
define i32 @"main"()
|
2007-01-16 19:08:22 +01:00
|
|
|
begin
|
2007-01-26 09:25:06 +01:00
|
|
|
%Result = call i63 @trampoline(i63 10, i63(i63) *@fib)
|
2007-01-30 17:16:01 +01:00
|
|
|
%Result2 = trunc i63 %Result to i32
|
|
|
|
ret i32 %Result2
|
2007-01-16 19:08:22 +01:00
|
|
|
end
|