This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
RE: [Patch][AVR]: Support tail calls
- From: "Boyapati, Anitha" <Anitha dot Boyapati at atmel dot com>
- To: "Georg-Johann Lay" <avr at gjlay dot de>, <gcc-patches at gcc dot gnu dot org>
- Cc: "Denis Chertykov" <chertykov at gmail dot com>, "Anatoly Sokolov" <aesok at post dot ru>, "Weddington, Eric" <Eric dot Weddington at atmel dot com>
- Date: Mon, 14 Mar 2011 14:34:29 +0800
- Subject: RE: [Patch][AVR]: Support tail calls
- References: <4D7A2711.4060801@gjlay.de>
Hi Georg,
>This is a patch to test/review/comment on. It adds tail call
>optimization to avr backend.
>
>The implementation uses struct machine_function to pass information
>around, i.e. from avr_function_arg_advance to avr_function_ok_for_sibcall.
>
>Tail call support is more general than avr-ld's replacement of
>call/ret sequences with --relax which are sometimes wrong, see
>http://sourceware.org/PR12494
>
>gcc can, e.g. tail-call bar1 in
>
>void bar0 (void);
>void bar1 (int);
>
>int foo (int x)
>{
> bar0();
> return bar1 (x);
>}
To be on same page, can you explain how gcc optimizes above case? As I understand, in a tail-call optimization, bar1 can return to the caller of foo(). There can be different cases of handling this. But how is this handled in gcc after recognizing that foo() is a candidate for tail call?
Also, I have applied the patch, and used it for a small test case as below:
int bar1(int x) {
x++;
return x;
}
int foo (int x)
{
return bar1 (x);
}
int main() {
volatile int i;
return foo(i);
}
avr-gcc -S -foptimize-sibling-calls tail-call.c
I find no difference in the code generated with and without tail call optimization. (I am assuming -foptimize-sibling-calls should turn on this). Let me know if I am doing something wrong.
Anitha