This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [tree-ssa] Tail recursion optimisation
- From: Roger Sayle <roger at eyesopen dot com>
- To: Richard Henderson <rth at redhat dot com>
- Cc: Jason Merrill <jason at redhat dot com>, Zdenek Dvorak <rakver at atrey dot karlin dot mff dot cuni dot cz>, <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 17 Oct 2003 06:54:16 -0600 (MDT)
- Subject: Re: [tree-ssa] Tail recursion optimisation
Richard Henderson wrote:
> At the rtl level we'd get to drop call_placeholder, and not have
> to expand the call and its arguments twice and all the problems
> that that entails.
I think it would be great if we could completely replace call_placeholder
with the equivalent functionality in tree-ssa. Indeed following the
tree SSA passes, the final decision could be made at RTL expansion.
A relevant testcase that has been annoying me is (on x86 at -O2):
void foo(int x)
{
if (x == 1) foo1();
if (x == 2) foo2();
if (x == 3) foo3();
}
void bar(int x)
{
if (x == 1) foo1();
else if (x == 2) foo2();
else if (x == 3) foo3();
}
GCC's jump bypassing optimizations manage to optimize the function
foo so that it has identical control flow to bar. But unfortunately
we generate different code for these two functions; all of the calls
in "bar" are sibling calls, whereas only the foo3 call in foo is
sibcalled. Basically, we don't recognize the sibling call until
its too late.
Given that we should now be able to do the equivalent transformations
much earlier, tree-ssa should be able to generate sibcalls for all
three calls in foo.
Roger
--