[Bug middle-end/99339] Poor codegen with simple varargs

rguenth at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Mar 2 12:44:29 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99339

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
           Keywords|                            |missed-optimization
             Target|                            |x86_64-*-*
          Component|c                           |middle-end
                 CC|                            |matz at gcc dot gnu.org,
                   |                            |rguenth at gcc dot gnu.org
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2021-03-02

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
The stack space is not eliminated because we lower __builtin_va_start only
after RTL expansion and that reserves stack space necessary for accessing
some of the meta (including the passed value itself) as memory.

So it's unavoidable up to somebody designing sth smarter around varargs
and GIMPLE.

Arguably the not lowered variant would be easier to expand optimally:

int test_va (int x)
{
  struct  va[1];
  int i;
  int _7;

  <bb 2> [local count: 1073741824]:
  __builtin_va_start (&va, 0);
  i_4 = .VA_ARG (&va, 0B, 0B);
  __builtin_va_end (&va);
  _7 = i_4 + x_6(D);
  va ={v} {CLOBBER};
  return _7;

I'm not fully sure why we lower at all.  Part of the lowering determines
whether there's any FP arguments referenced and optimizes based on that,
but IIRC that's all.


More information about the Gcc-bugs mailing list