blob: d586fca821f2e83e884e7fab2d1f723652d55504 [file] [log] [blame]
Reid Spencerc0948362007-01-16 18:08:22 +00001; 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 Spencerc0948362007-01-16 18:08:22 +00005
Reid Spencere3ff5ad2007-01-26 08:25:06 +00006declare i32 @"atoi"(i8 *)
Reid Spencerc0948362007-01-16 18:08:22 +00007
Reid Spencere3ff5ad2007-01-26 08:25:06 +00008define i63 @"fib"(i63 %n)
Reid Spencerc0948362007-01-16 18:08:22 +00009begin
Reid Spencer2318ec62007-03-19 18:27:35 +000010 icmp ult i63 %n, 2 ; {i1}:1
11 br i1 %1, label %BaseCase, label %RecurseCase
Reid Spencerc0948362007-01-16 18:08:22 +000012
13BaseCase:
14 ret i63 1
15
16RecurseCase:
17 %n2 = sub i63 %n, 2
18 %n1 = sub i63 %n, 1
Reid Spencere3ff5ad2007-01-26 08:25:06 +000019 %f2 = call i63(i63) * @fib(i63 %n2)
20 %f1 = call i63(i63) * @fib(i63 %n1)
Reid Spencerc0948362007-01-16 18:08:22 +000021 %result = add i63 %f2, %f1
22 ret i63 %result
23end
24
Reid Spencere3ff5ad2007-01-26 08:25:06 +000025define i63 @"realmain"(i32 %argc, i8 ** %argv)
Reid Spencerc0948362007-01-16 18:08:22 +000026begin
Reid Spencer2318ec62007-03-19 18:27:35 +000027 icmp eq i32 %argc, 2 ; {i1}:1
28 br i1 %1, label %HasArg, label %Continue
Reid Spencerc0948362007-01-16 18:08:22 +000029HasArg:
30 ; %n1 = atoi(argv[1])
31 %n1 = add i32 1, 1
32 br label %Continue
33
34Continue:
35 %n = phi i32 [%n1, %HasArg], [1, %0]
36 %N = sext i32 %n to i63
Reid Spencere3ff5ad2007-01-26 08:25:06 +000037 %F = call i63(i63) *@fib(i63 %N)
Reid Spencerc0948362007-01-16 18:08:22 +000038 ret i63 %F
39end
40
Reid Spencere3ff5ad2007-01-26 08:25:06 +000041define i63 @"trampoline"(i63 %n, i63(i63)* %fibfunc)
Reid Spencerc0948362007-01-16 18:08:22 +000042begin
43 %F = call i63(i63) *%fibfunc(i63 %n)
44 ret i63 %F
45end
46
Reid Spencere3ff5ad2007-01-26 08:25:06 +000047define i32 @"main"()
Reid Spencerc0948362007-01-16 18:08:22 +000048begin
Reid Spencere3ff5ad2007-01-26 08:25:06 +000049 %Result = call i63 @trampoline(i63 10, i63(i63) *@fib)
Reid Spencer90850432007-01-30 16:16:01 +000050 %Result2 = trunc i63 %Result to i32
51 ret i32 %Result2
Reid Spencerc0948362007-01-16 18:08:22 +000052end