This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
sibcall vs sign extension
- From: Fergus Henderson <fjh at cs dot mu dot oz dot au>
- To: gcc at gcc dot gnu dot org
- Date: Mon, 16 Sep 2002 00:55:49 +1000
- Subject: sibcall vs sign extension
Sibcall optimization works fine (on x86) for this test case:
extern int foo_int();
int bar_int() { return foo_int(); }
But if you change `int' to `char', like so,
extern char foo_char();
char bar_char() { return foo_char(); }
then it does not get optimized. The reason is that for the `char'
version, GCC generates a unnecessary sign extension instruction.
This instruction comes after the call to foo_char(), so GCC thinks this
call is not a tail call.
The extra sign extension instruction is generated because the
return type gets promoted to `int'. Unfortunate GCC apparently
does not realize that the value returned from the callee is
already promoted, and insists on re-promoting it.
Any ideas about how this could be rectified?
My first thought is that perhaps sibcall.c could skip over
sign extensions, in the same way that it skips over the code
to copy the return value. However, I'm not sure if there is
enough type information still around at this point to
distinguish the cases where the sign extension is unnecessary.
And it seems like the wrong place to do it, since removing
unnecessary sign extensions would be useful even for
ordinary calls, not just for sibling calls.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.