https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115606
Bug ID: 115606
Summary: return slot opt prevents tail calls
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: andi-gcc at firstfloor dot org
Target Milestone: ---
For the following test case
class Foo {
public:
int a, b;
Foo(int a, int b) : a(a), b(b) {}
};
Foo __attribute__((noinline,noclone,noipa))
callee (int i)
{
return Foo(i, i+1);
}
Foo __attribute__((noinline,noclone,noipa))
caller (int i)
{
return callee (i + 1);
}
x86 can sibling call the callee call, but ARM can't.
The difference seems to be that ARM ends up with
<retval> = callee (_1); [return slot optimization]
while x86_64 just has
D.2926 = callee (_1);
and then in tree-tailcall this test fails with return slot optimization:
tree result_decl = DECL_RESULT (cfun->decl);
if (result_decl
&& may_be_aliased (result_decl)
&& ref_maybe_used_by_stmt_p (call, result_decl, false))
resulting in no sibling call.
This causes a test suite failure in the musttail patchkit, but only on ARM.
Of course the test could be disabled on ARM but I wonder if there is a missing
optimization bug here. With more musttail usage it might be a bigger problem if
not even simple structures are supported.
I'm not sure:
- why return slot opt at the gimple level is target specific?
- can tree tailcall handle this case?