[LLVMdev] llvm hangs: fibonacci numbers, recursive
Elmar Stellnberger
elmstel at gmail.com
Wed Mar 3 09:51:51 PST 2010
Having tried out llvm I had to notice that the fibonacci example
program hangs after short:
> ./run fib
1
1
2
3
5
8
^C
For the next number it would be supposed to last twice as long as for 8.
However it hangs forever instead.
using llvm-2.5-0.pm.1.1.x86_64
Does not matter whether I compile it with gcc or interprete it with lli.
--------------------------------------------------------------------------
pasted attachement of sources:
@str = internal constant [4 x i8] c"%d\0A\00"
define void @main() nounwind {
init:
br label %loop
loop:
%i = phi i32 [0, %init], [%i.next, %loop]
%fib = call i32 @fib(i32 %i)
call i32 @printf( i8* getelementptr ([4 x i8]* @str, i32 0,i32 0), i32
%fib)
%i.next = add i32 %i, 1
%cond = icmp ult i32 %i.next, 7
br i1 %cond, label %loop, label %exit
exit:
ret void
}
define i32 @fib(i32 %n) nounwind {
%cond = icmp ult i32 %n, 2
br i1 %cond, label %c1, label %c2
c1:
ret i32 1
c2:
%n1 = sub i32 %n, 1
%n2 = sub i32 %n, 2
%fib1 = call i32 @fib(i32 %n1)
%fib2 = call i32 @fib(i32 %n2)
%r = add i32 %fib1, %fib2
ret i32 %r
}
declare i32 @printf(i8*, ...) nounwind
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fib.bc
Type: application/octet-stream
Size: 496 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100303/41321f5c/attachment.obj>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: fib.ll
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100303/41321f5c/attachment.ksh>
More information about the llvm-dev
mailing list