public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/21265] New: [4.0,4.1 regression] GCC fails to optimize tail call to memset
@ 2005-04-28 13:03 ghazi at gcc dot gnu dot org
  2005-04-28 13:13 ` [Bug middle-end/21265] [4.0/4.1 " pinskia at gcc dot gnu dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: ghazi at gcc dot gnu dot org @ 2005-04-28 13:03 UTC (permalink / raw)
  To: gcc-bugs

Given the code below, GCC fails to optimize the tail call to memset into a jmp 
on x86_64-unknown-linux-gnu as of 4.0 or 4.1 mainline.  Versions 3.4 and 3.3 
perform the transformation so it is a regression.  All GCC versions on x86_64 
manage to optimize the call to my_memset so it may be related to builtin 
handling.  FYI none of the above versions of gcc optimize either memset or 
my_memset on x86.  So on x86 it's consistently failing, I'm not sure if that's 
intentional or not.  But x86_64 is a regression.

Compile with -O2 -S:

#include <stddef.h>
extern void *memset (void *, int, size_t);
extern void *my_memset (void *, int, size_t);

void
foo (void *to, size_t count)
{
  memset (to, 0, count);
}

void
bar (void *to, size_t count)
{
  my_memset (to, 0, count);
}

-- 
           Summary: [4.0,4.1 regression] GCC fails to optimize tail call to
                    memset
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P2
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ghazi at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: x86_64-unknown-linux-gnu
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu


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


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

* [Bug middle-end/21265] [4.0/4.1 regression] GCC fails to optimize tail call to memset
  2005-04-28 13:03 [Bug middle-end/21265] New: [4.0,4.1 regression] GCC fails to optimize tail call to memset ghazi at gcc dot gnu dot org
@ 2005-04-28 13:13 ` pinskia at gcc dot gnu dot org
  2005-05-02 17:21 ` jakub at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-04-28 13:13 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-04-28 13:13 -------
Confirmed, it also happens on PPC-darwin too.
Note here is a testcase for x86 (32bit):
#include <stddef.h>
extern void *memset (void *, int, size_t);
extern void *my_memset (void *, int, size_t);

void
foo (void *to,int i, size_t count)
{
  memset (to, 0, count);
}

void
bar (void *to, int i, size_t count)
{
  my_memset (to, 0, count);
}

And this has been happening since at least: "3.5.0 20040909"

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
  GCC build triplet|x86_64-unknown-linux-gnu    |
   GCC host triplet|x86_64-unknown-linux-gnu    |
 GCC target triplet|x86_64-unknown-linux-gnu    |
      Known to fail|                            |4.0.0 4.1.0
      Known to work|                            |3.3.3
   Last reconfirmed|0000-00-00 00:00:00         |2005-04-28 13:13:37
               date|                            |
            Summary|[4.0,4.1 regression] GCC    |[4.0/4.1 regression] GCC
                   |fails to optimize tail call |fails to optimize tail call
                   |to memset                   |to memset
   Target Milestone|---                         |4.0.1


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


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

* [Bug middle-end/21265] [4.0/4.1 regression] GCC fails to optimize tail call to memset
  2005-04-28 13:03 [Bug middle-end/21265] New: [4.0,4.1 regression] GCC fails to optimize tail call to memset ghazi at gcc dot gnu dot org
  2005-04-28 13:13 ` [Bug middle-end/21265] [4.0/4.1 " pinskia at gcc dot gnu dot org
@ 2005-05-02 17:21 ` jakub at gcc dot gnu dot org
  2005-05-03 22:22 ` cvs-commit at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu dot org @ 2005-05-02 17:21 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |jakub at gcc dot gnu dot org
                   |dot org                     |
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2005-04-28 13:13:37         |2005-05-02 17:21:17
               date|                            |


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


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

* [Bug middle-end/21265] [4.0/4.1 regression] GCC fails to optimize tail call to memset
  2005-04-28 13:03 [Bug middle-end/21265] New: [4.0,4.1 regression] GCC fails to optimize tail call to memset ghazi at gcc dot gnu dot org
  2005-04-28 13:13 ` [Bug middle-end/21265] [4.0/4.1 " pinskia at gcc dot gnu dot org
  2005-05-02 17:21 ` jakub at gcc dot gnu dot org
@ 2005-05-03 22:22 ` cvs-commit at gcc dot gnu dot org
  2005-05-04  7:36 ` [Bug middle-end/21265] [4.0 " cvs-commit at gcc dot gnu dot org
  2005-05-04  8:14 ` giovannibajo at libero dot it
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2005-05-03 22:22 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2005-05-03 22:22 -------
Subject: Bug 21265

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	jakub@gcc.gnu.org	2005-05-03 22:22:02

Modified files:
	gcc            : ChangeLog expr.h expr.c builtins.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.dg: 20050503-1.c 

Log message:
	PR middle-end/21265
	* expr.h (enum block_op_methods): Add BLOCK_OP_TAILCALL.
	(clear_storage): Add argument.
	* expr.c (emit_block_move_via_libcall, clear_storage_via_libcall):
	Add tailcall argument, set CALL_EXPR_TAILCALL of the CALL_EXPR to
	tailcall.
	(emit_block_move): Handle BLOCK_OP_TAILCALL method.
	(clear_storage): Add method argument, handle BLOCK_OP_TAILCALL.
	(store_expr, store_constructor): Adjust callers.
	* builtins.c (expand_builtin_memcpy): Pass BLOCK_OP_TAILCALL
	to emit_block_move if CALL_EXPR_TAILCALL (exp).
	(expand_builtin_memmove): Add ORIG_EXP argument, copy
	CALL_EXPR_TAILCALL from ORIG_EXP to the new CALL_EXPR.
	(expand_builtin_bcopy): Replace ARGLIST and TYPE arguments
	with EXP.  Pass EXP to expand_builtin_memmove.
	(expand_builtin_memset): Add ORIG_EXP argument, pass
	BLOCK_OP_TAILCALL to clear_storage if CALL_EXPR_TAILCALL (orig_exp).
	(expand_builtin_bzero): Replace ARGLIST argument with EXP.
	Pass EXP to expand_builtin_memset.
	(expand_builtin_strcmp): Copy CALL_EXPR_TAILCALL from EXP to
	the new CALL_EXPR.
	(expand_builtin_strncmp): Likewise.
	(expand_builtin_printf): Replace ARGLIST argument with EXP.
	Copy CALL_EXPR_TAILCALL from EXP to the new CALL_EXPR.
	(expand_builtin_fprintf): Likewise.
	(expand_builtin): Adjust calls to
	expand_builtin_{memmove,bcopy,memset,bzero,{,f}printf}.
	
	* gcc.dg/20050503-1.c: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.8588&r2=2.8589
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/expr.h.diff?cvsroot=gcc&r1=1.187&r2=1.188
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/expr.c.diff?cvsroot=gcc&r1=1.788&r2=1.789
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/builtins.c.diff?cvsroot=gcc&r1=1.460&r2=1.461
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5437&r2=1.5438
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/20050503-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1



-- 


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


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

* [Bug middle-end/21265] [4.0 regression] GCC fails to optimize tail call to memset
  2005-04-28 13:03 [Bug middle-end/21265] New: [4.0,4.1 regression] GCC fails to optimize tail call to memset ghazi at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2005-05-03 22:22 ` cvs-commit at gcc dot gnu dot org
@ 2005-05-04  7:36 ` cvs-commit at gcc dot gnu dot org
  2005-05-04  8:14 ` giovannibajo at libero dot it
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2005-05-04  7:36 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2005-05-04 07:36 -------
Subject: Bug 21265

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	jakub@gcc.gnu.org	2005-05-04 07:35:32

Modified files:
	gcc            : ChangeLog builtins.c expr.h expr.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.dg: 20050503-1.c 

Log message:
	PR middle-end/21265
	* expr.h (enum block_op_methods): Add BLOCK_OP_TAILCALL.
	(clear_storage): Add argument.
	* expr.c (emit_block_move_via_libcall, clear_storage_via_libcall):
	Add tailcall argument, set CALL_EXPR_TAILCALL of the CALL_EXPR to
	tailcall.
	(emit_block_move): Handle BLOCK_OP_TAILCALL method.
	(clear_storage): Add method argument, handle BLOCK_OP_TAILCALL.
	(store_expr, store_constructor): Adjust callers.
	* builtins.c (expand_builtin_memcpy): Pass BLOCK_OP_TAILCALL
	to emit_block_move if CALL_EXPR_TAILCALL (exp).
	(expand_builtin_memmove): Add ORIG_EXP argument, copy
	CALL_EXPR_TAILCALL from ORIG_EXP to the new CALL_EXPR.
	(expand_builtin_bcopy): Replace ARGLIST and TYPE arguments
	with EXP.  Pass EXP to expand_builtin_memmove.
	(expand_builtin_memset): Add ORIG_EXP argument, pass
	BLOCK_OP_TAILCALL to clear_storage if CALL_EXPR_TAILCALL (orig_exp).
	(expand_builtin_bzero): Replace ARGLIST argument with EXP.
	Pass EXP to expand_builtin_memset.
	(expand_builtin_strcmp): Copy CALL_EXPR_TAILCALL from EXP to
	the new CALL_EXPR.
	(expand_builtin_strncmp): Likewise.
	(expand_builtin_printf): Replace ARGLIST argument with EXP.
	Copy CALL_EXPR_TAILCALL from EXP to the new CALL_EXPR.
	(expand_builtin_fprintf): Likewise.
	(expand_builtin): Adjust calls to
	expand_builtin_{memmove,bcopy,memset,bzero,{,f}printf}.
	
	* gcc.dg/20050503-1.c: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=2.7592.2.216&r2=2.7592.2.217
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/builtins.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.426.2.1&r2=1.426.2.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/expr.h.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.186&r2=1.186.8.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/expr.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.778.6.1&r2=1.778.6.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.5084.2.159&r2=1.5084.2.160
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/20050503-1.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1



-- 


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


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

* [Bug middle-end/21265] [4.0 regression] GCC fails to optimize tail call to memset
  2005-04-28 13:03 [Bug middle-end/21265] New: [4.0,4.1 regression] GCC fails to optimize tail call to memset ghazi at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2005-05-04  7:36 ` [Bug middle-end/21265] [4.0 " cvs-commit at gcc dot gnu dot org
@ 2005-05-04  8:14 ` giovannibajo at libero dot it
  4 siblings, 0 replies; 6+ messages in thread
From: giovannibajo at libero dot it @ 2005-05-04  8:14 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From giovannibajo at libero dot it  2005-05-04 08:14 -------
Fixed, thanks Kaveh and Jakub!

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


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


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

end of thread, other threads:[~2005-05-04  8:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-28 13:03 [Bug middle-end/21265] New: [4.0,4.1 regression] GCC fails to optimize tail call to memset ghazi at gcc dot gnu dot org
2005-04-28 13:13 ` [Bug middle-end/21265] [4.0/4.1 " pinskia at gcc dot gnu dot org
2005-05-02 17:21 ` jakub at gcc dot gnu dot org
2005-05-03 22:22 ` cvs-commit at gcc dot gnu dot org
2005-05-04  7:36 ` [Bug middle-end/21265] [4.0 " cvs-commit at gcc dot gnu dot org
2005-05-04  8:14 ` giovannibajo at libero dot it

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