This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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
--


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]