[LLVMdev] Query on optimization and tail call.
Eli Friedman
eli.friedman at gmail.com
Tue Jun 10 23:29:36 PDT 2008
On Tue, Jun 10, 2008 at 11:07 PM, Mahadevan R <mdevan.foobar at gmail.com> wrote:
> int sum(int n)
> {
> return n + sum(n-1);
> }
>
> it generates this:
>
> define i32 @sum(i32 %n) nounwind {
> entry:
> %tmp2 = add i32 %n, -1 ; <i32> [#uses=1]
> %tmp3 = tail call i32 @sum( i32 %tmp2 ) nounwind ; <i32> [#uses=1]
> %tmp5 = add i32 %tmp3, %n ; <i32> [#uses=1]
> ret i32 %tmp5
> }
>
> Why isn't llvm able to eliminate the tail call in this (simpler) case?
I haven't checked, but this is probably a case that wasn't worth
handling, since it's an infinite loop.
-Eli
More information about the llvm-dev
mailing list