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