[LLVMdev] Query on optimization and tail call.
Mahadevan R
mdevan.foobar at gmail.com
Wed Jun 11 01:13:59 PDT 2008
Thanks for the clarifications (and unnecessary interruptions on your
time!). But one more query please!
This one generates optimized (computes the value) code:
unsigned sum(unsigned n)
{
if (n == 0)
return 0;
else
return n + sum(n-1);
}
where as this one generates a loop that adds up numbers:
int sum(int n)
{
if (n <= 0)
return 0;
else
return n + sum(n-1);
}
I'm guessing this is probably because the values will be different in
the overflow case -- is it?. Although changing the if condition to "if
(n <= 0 || n > 10)" also generates the loop.
Thanks for your patience!
-Mahadevan.
More information about the llvm-dev
mailing list