public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/20983] New: [4.0 regression] varargs functions force va_list variable to stack unnecessarily
@ 2005-04-13  2:10 ian at airs dot com
  2005-04-13  3:26 ` [Bug c/20983] " ian at airs dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: ian at airs dot com @ 2005-04-13  2:10 UTC (permalink / raw)
  To: gcc-bugs

varargs functions appear to force the va_list variable to the stack
unnecessarily.  This appears to be a consequence of declaring __builtin_va_start
and __builtin_va_end to take a reference to va_list.  This is a regression from 3.4.

Compile this test case for i686-pc-linux-gnu with -O2:

int
foo (int a, ...)
{
  __builtin_va_list va;
  int c, i;

  __builtin_va_start(va,a);
  c = 0;
  while ((i = __builtin_va_arg(va,int)) != 0)
    c += i;
  __builtin_va_end(va);
  return c;
}

I get this:

foo:
	pushl	%ebp
	xorl	%eax, %eax
	movl	%esp, %ebp
	subl	$16, %esp
	movl	12(%ebp), %edx
	leal	16(%ebp), %ecx
	movl	%ecx, -4(%ebp)
	testl	%edx, %edx
	je	.L4
	.p2align 4,,15
.L5:
	addl	$4, %ecx
	addl	%edx, %eax
	movl	-4(%ecx), %edx
	testl	%edx, %edx
	jne	.L5
	movl	%ecx, -4(%ebp)
.L4:
	leave
	ret

Note the two stores to -4(%ebp).  They are useless.  Note that this causes the
function to unnecessarily have a stack frame.

With gcc 3.4.3 I get

	pushl	%ebp
	movl	%esp, %ebp
	xorl	%ecx, %ecx
	leal	16(%ebp), %edx
	movl	12(%ebp), %eax
	jmp	.L7
	.p2align 2,,3
.L9:
	addl	%eax, %ecx
	movl	%edx, %eax
	movl	(%eax), %eax
	addl	$4, %edx
.L7:
	testl	%eax, %eax
	jne	.L9
	movl	%ecx, %eax
	leave
	ret

This code is better.

-- 
           Summary: [4.0 regression] varargs functions force va_list
                    variable to stack unnecessarily
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ian at airs dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20983


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/20983] [4.0 regression] varargs functions force va_list variable to stack unnecessarily
  2005-04-13  2:10 [Bug c/20983] New: [4.0 regression] varargs functions force va_list variable to stack unnecessarily ian at airs dot com
@ 2005-04-13  3:26 ` ian at airs dot com
  2005-04-13  4:45 ` [Bug middle-end/20983] " pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: ian at airs dot com @ 2005-04-13  3:26 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From ian at airs dot com  2005-04-13 03:26 -------
*** Bug 20984 has been marked as a duplicate of this bug. ***

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20983


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug middle-end/20983] [4.0 regression] varargs functions force va_list variable to stack unnecessarily
  2005-04-13  2:10 [Bug c/20983] New: [4.0 regression] varargs functions force va_list variable to stack unnecessarily ian at airs dot com
  2005-04-13  3:26 ` [Bug c/20983] " ian at airs dot com
@ 2005-04-13  4:45 ` pinskia at gcc dot gnu dot org
  2005-05-05 17:13 ` jakub at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-04-13  4:45 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c                           |middle-end
           Keywords|                            |missed-optimization


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20983


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug middle-end/20983] [4.0 regression] varargs functions force va_list variable to stack unnecessarily
  2005-04-13  2:10 [Bug c/20983] New: [4.0 regression] varargs functions force va_list variable to stack unnecessarily ian at airs dot com
  2005-04-13  3:26 ` [Bug c/20983] " ian at airs dot com
  2005-04-13  4:45 ` [Bug middle-end/20983] " pinskia at gcc dot gnu dot org
@ 2005-05-05 17:13 ` jakub at gcc dot gnu dot org
  2005-09-24 17:18 ` [Bug middle-end/20983] [4.0/4.1regression] " pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu dot org @ 2005-05-05 17:13 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From jakub at gcc dot gnu dot org  2005-05-05 17:11 -------
This could be fixed by expanding __builtin_va_start, __builtin_va_copy
and __builtin_va_end in or soon after pass_stdarg.
Then SRA etc. can also optimize va_list handling.
On the other side, tree-stdarg.c needs to see those builtins, otherwise it
won't be able to figure out anything.  Perhaps we can move that pass a little
bit earlier if needed, but it should certainly happen after at least DCE.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rth at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20983


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug middle-end/20983] [4.0/4.1regression] varargs functions force va_list variable to stack unnecessarily
  2005-04-13  2:10 [Bug c/20983] New: [4.0 regression] varargs functions force va_list variable to stack unnecessarily ian at airs dot com
                   ` (2 preceding siblings ...)
  2005-05-05 17:13 ` jakub at gcc dot gnu dot org
@ 2005-09-24 17:18 ` pinskia at gcc dot gnu dot org
  2005-09-27 16:08 ` mmitchel at gcc dot gnu dot org
  2005-09-29  3:37 ` [Bug middle-end/20983] [4.0/4.1 Regression] " pinskia at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-09-24 17:18 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-09-24 17:18 -------
Confirmed.  I somehow missed this.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
   Last reconfirmed|0000-00-00 00:00:00         |2005-09-24 17:18:29
               date|                            |
            Summary|[4.0 regression] varargs    |[4.0/4.1regression] varargs
                   |functions force va_list     |functions force va_list
                   |variable to stack           |variable to stack
                   |unnecessarily               |unnecessarily
   Target Milestone|---                         |4.0.2


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20983


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug middle-end/20983] [4.0/4.1regression] varargs functions force va_list variable to stack unnecessarily
  2005-04-13  2:10 [Bug c/20983] New: [4.0 regression] varargs functions force va_list variable to stack unnecessarily ian at airs dot com
                   ` (3 preceding siblings ...)
  2005-09-24 17:18 ` [Bug middle-end/20983] [4.0/4.1regression] " pinskia at gcc dot gnu dot org
@ 2005-09-27 16:08 ` mmitchel at gcc dot gnu dot org
  2005-09-29  3:37 ` [Bug middle-end/20983] [4.0/4.1 Regression] " pinskia at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2005-09-27 16:08 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.0.2                       |4.0.3


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20983


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug middle-end/20983] [4.0/4.1 Regression] varargs functions force va_list variable to stack unnecessarily
  2005-04-13  2:10 [Bug c/20983] New: [4.0 regression] varargs functions force va_list variable to stack unnecessarily ian at airs dot com
                   ` (4 preceding siblings ...)
  2005-09-27 16:08 ` mmitchel at gcc dot gnu dot org
@ 2005-09-29  3:37 ` pinskia at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-09-29  3:37 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-09-29 03:37 -------
Hmm, I think the same problem is on powerpc.
There is an extra store to -40(r1).

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
  GCC build triplet|i686-pc-linux-gnu           |
   GCC host triplet|i686-pc-linux-gnu           |
 GCC target triplet|i686-pc-linux-gnu           |i686-*-*
            Summary|[4.0/4.1regression] varargs |[4.0/4.1 Regression] varargs
                   |functions force va_list     |functions force va_list
                   |variable to stack           |variable to stack
                   |unnecessarily               |unnecessarily


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20983


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2005-09-29  3:37 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-13  2:10 [Bug c/20983] New: [4.0 regression] varargs functions force va_list variable to stack unnecessarily ian at airs dot com
2005-04-13  3:26 ` [Bug c/20983] " ian at airs dot com
2005-04-13  4:45 ` [Bug middle-end/20983] " pinskia at gcc dot gnu dot org
2005-05-05 17:13 ` jakub at gcc dot gnu dot org
2005-09-24 17:18 ` [Bug middle-end/20983] [4.0/4.1regression] " pinskia at gcc dot gnu dot org
2005-09-27 16:08 ` mmitchel at gcc dot gnu dot org
2005-09-29  3:37 ` [Bug middle-end/20983] [4.0/4.1 Regression] " pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).