[Bug middle-end/87268] New: Missed optimization for a tailcall
glisse at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Sep 10 07:23:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87268
Bug ID: 87268
Summary: Missed optimization for a tailcall
Product: gcc
Version: 8.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: noone@turm-lahnstein.de
Target Milestone: ---
Component: middle-end
For a simple code like this:
extern int shared;
void doit(int *);
int call_doit(){
doit(&shared);
}
when compiled with -O3 the resulting assembler is without tailcall
optimization:
call_doit:
subq $8, %rsp
movl $shared, %edi
call doit
addq $8, %rsp
ret
There are two thing that are probably not needed:
1. The whole "subq $8, %rsp / addq $8, %rsp" is not really necessary,
isn't it?
2. call instead of simple jmp, which would be possible due to tailcall
optimization. Possibly it was not performed, because subq/addq are still
hanging around.
If I'm not mistaken, something like:
call_doit:
movl $global, %edi
jmp doit
should be possible as output.
--- Comment #1 from Marc Glisse <glisse at gcc dot gnu.org> ---
warning: control reaches end of non-void function
If call_doit is changed to return void, we get a tail call.
Is doit meant to be noreturn? (surprisingly, the noreturn attribute is not
sufficient to get a tail call)
More information about the Gcc-bugs
mailing list