public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/15419] New: memcpy pessimization
@ 2004-05-14 1:27 falk at debian dot org
2004-05-14 2:00 ` [Bug tree-optimization/15419] " pinskia at gcc dot gnu dot org
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: falk at debian dot org @ 2004-05-14 1:27 UTC (permalink / raw)
To: gcc-bugs
gcc (GCC) 3.5.0 20040513 (experimental)
% cat test.c
typedef unsigned uint32_t;
uint32_t get_uint32(const void *p) {
uint32_t w;
memcpy(&w, p, sizeof (uint32_t));
return w;
}
uint32_t get_uint32a(const void *p) {
const struct { uint32_t w; } __attribute__((packed)) *wp = p;
return wp->w;
}
% gcc -c -O3 test.c && objdump -d test.o
0000000000000000 <get_uint32>:
0: 03 00 90 28 ldbu t3,3(a0)
4: 00 00 30 28 ldbu t0,0(a0)
8: f0 ff de 23 lda sp,-16(sp)
c: 01 00 50 28 ldbu t1,1(a0)
10: 02 00 70 28 ldbu t2,2(a0)
14: 00 00 3e 38 stb t0,0(sp)
18: 03 00 9e 38 stb t3,3(sp)
1c: 01 00 5e 38 stb t1,1(sp)
20: 02 00 7e 38 stb t2,2(sp)
24: 00 00 1e a0 ldl v0,0(sp)
28: 10 00 de 23 lda sp,16(sp)
2c: 01 80 fa 6b ret
0000000000000030 <get_uint32a>:
30: 00 00 50 2c ldq_u t1,0(a0)
34: 03 00 30 2c ldq_u t0,3(a0)
38: c2 04 50 48 extll t1,a0,t1
3c: 41 0d 30 48 extlh t0,a0,t0
40: 00 04 41 44 or t1,t0,v0
44: 00 00 e0 43 sextl v0,v0
48: 01 80 fa 6b ret
The code for get_uint32 is really bad compared to get_uint32a, but it is
an important portable idiom to achieve the same.
--
Summary: memcpy pessimization
Product: gcc
Version: 3.5.0
Status: UNCONFIRMED
Keywords: pessimizes-code
Severity: enhancement
Priority: P2
Component: tree-optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: falk at debian dot org
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: alphaev68-unknown-linux-gnu
GCC host triplet: alphaev68-unknown-linux-gnu
GCC target triplet: alphaev68-unknown-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15419
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/15419] memcpy pessimization
2004-05-14 1:27 [Bug tree-optimization/15419] New: memcpy pessimization falk at debian dot org
@ 2004-05-14 2:00 ` pinskia at gcc dot gnu dot org
2005-05-18 7:37 ` rth at gcc dot gnu dot org
` (2 subsequent siblings)
3 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-05-14 2:00 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-05-13 14:10 -------
Confirmed, I think RTH was going to something with memcpy.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed| |1
Last reconfirmed|0000-00-00 00:00:00 |2004-05-13 14:10:55
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15419
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/15419] memcpy pessimization
2004-05-14 1:27 [Bug tree-optimization/15419] New: memcpy pessimization falk at debian dot org
2004-05-14 2:00 ` [Bug tree-optimization/15419] " pinskia at gcc dot gnu dot org
@ 2005-05-18 7:37 ` rth at gcc dot gnu dot org
2005-05-18 8:21 ` rth at gcc dot gnu dot org
2005-08-05 20:40 ` rth at gcc dot gnu dot org
3 siblings, 0 replies; 9+ messages in thread
From: rth at gcc dot gnu dot org @ 2005-05-18 7:37 UTC (permalink / raw)
To: gcc-bugs
--
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|unassigned at gcc dot gnu |rth at gcc dot gnu dot org
|dot org |
Status|NEW |ASSIGNED
Last reconfirmed|2005-02-10 04:23:15 |2005-05-18 07:36:30
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15419
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/15419] memcpy pessimization
2004-05-14 1:27 [Bug tree-optimization/15419] New: memcpy pessimization falk at debian dot org
2004-05-14 2:00 ` [Bug tree-optimization/15419] " pinskia at gcc dot gnu dot org
2005-05-18 7:37 ` rth at gcc dot gnu dot org
@ 2005-05-18 8:21 ` rth at gcc dot gnu dot org
2005-08-05 20:40 ` rth at gcc dot gnu dot org
3 siblings, 0 replies; 9+ messages in thread
From: rth at gcc dot gnu dot org @ 2005-05-18 8:21 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From rth at gcc dot gnu dot org 2005-05-18 08:21 -------
Not alpha specific. The tunings we have in the alpha memcpy expansion are
correct for real copies between memory. We want to prefer
ldbu $1,3($17)
ldbu $2,0($17)
ldbu $3,1($17)
ldbu $4,2($17)
stb $1,3($16)
stb $2,0($16)
stb $3,1($16)
stb $4,2($16)
over
ldq_u $5,0($17)
ldq_u $2,3($17)
ldq_u $3,3($16)
ldq_u $4,0($16)
extlh $2,$17,$2
extll $5,$17,$5
msklh $3,$16,$3
mskll $4,$16,$4
bis $5,$2,$1
inslh $1,$16,$6
insll $1,$16,$1
bis $3,$6,$3
bis $4,$1,$4
stq_u $3,3($16)
stq_u $4,0($16)
The trick is that we want to notice at the tree level that the memcpy is
really a killing store of a local variable, and rewrite it into the
assignment form. I'll give it some thought.
--
What |Removed |Added
----------------------------------------------------------------------------
GCC target triplet|alphaev68-*-linux-gnu |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15419
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/15419] memcpy pessimization
2004-05-14 1:27 [Bug tree-optimization/15419] New: memcpy pessimization falk at debian dot org
` (2 preceding siblings ...)
2005-05-18 8:21 ` rth at gcc dot gnu dot org
@ 2005-08-05 20:40 ` rth at gcc dot gnu dot org
3 siblings, 0 replies; 9+ messages in thread
From: rth at gcc dot gnu dot org @ 2005-08-05 20:40 UTC (permalink / raw)
To: gcc-bugs
--
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|rth at gcc dot gnu dot org |unassigned at gcc dot gnu
| |dot org
Status|ASSIGNED |NEW
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15419
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/15419] memcpy pessimization
[not found] <bug-15419-4@http.gcc.gnu.org/bugzilla/>
` (2 preceding siblings ...)
2011-05-23 12:30 ` rguenth at gcc dot gnu.org
@ 2011-05-23 13:13 ` rguenth at gcc dot gnu.org
3 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-05-23 13:13 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15419
Richard Guenther <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
Target Milestone|--- |4.7.0
--- Comment #6 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-05-23 12:09:36 UTC ---
Fixed for 4.7.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/15419] memcpy pessimization
[not found] <bug-15419-4@http.gcc.gnu.org/bugzilla/>
2011-05-22 15:38 ` steven at gcc dot gnu.org
2011-05-22 21:02 ` rguenth at gcc dot gnu.org
@ 2011-05-23 12:30 ` rguenth at gcc dot gnu.org
2011-05-23 13:13 ` rguenth at gcc dot gnu.org
3 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-05-23 12:30 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15419
--- Comment #5 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-05-23 12:03:21 UTC ---
Author: rguenth
Date: Mon May 23 12:03:19 2011
New Revision: 174065
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=174065
Log:
2011-05-23 Richard Guenther <rguenther@suse.de>
PR middle-end/15419
* builtins.c (fold_builtin_memory_op): Be less restrictive about
what pointer types we accept for folding.
* gcc.dg/memcpy-3.c: New testcase.
Added:
trunk/gcc/testsuite/gcc.dg/memcpy-3.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/builtins.c
trunk/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/15419] memcpy pessimization
[not found] <bug-15419-4@http.gcc.gnu.org/bugzilla/>
2011-05-22 15:38 ` steven at gcc dot gnu.org
@ 2011-05-22 21:02 ` rguenth at gcc dot gnu.org
2011-05-23 12:30 ` rguenth at gcc dot gnu.org
2011-05-23 13:13 ` rguenth at gcc dot gnu.org
3 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-05-22 21:02 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15419
Richard Guenther <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
AssignedTo|unassigned at gcc dot |rguenth at gcc dot gnu.org
|gnu.org |
--- Comment #4 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-05-22 20:44:50 UTC ---
For this case we're confused about srctype being void_type_node. Eh.
Index: builtins.c
===================================================================
--- builtins.c (revision 174027)
+++ builtins.c (working copy)
@@ -8525,6 +8525,8 @@ fold_builtin_memory_op (location_t loc,
dest = build1 (NOP_EXPR, TREE_TYPE (tem), dest);
}
srctype = TREE_TYPE (TREE_TYPE (src));
+ if (VOID_TYPE_P (srctype))
+ srctype = char_type_node;
if (srctype
&& TREE_CODE (srctype) == ARRAY_TYPE
&& !tree_int_cst_equal (TYPE_SIZE_UNIT (srctype), len))
@@ -8534,6 +8536,8 @@ fold_builtin_memory_op (location_t loc,
src = build1 (NOP_EXPR, build_pointer_type (srctype), src);
}
desttype = TREE_TYPE (TREE_TYPE (dest));
+ if (VOID_TYPE_P (srctype))
+ srctype = char_type_node;
if (desttype
&& TREE_CODE (desttype) == ARRAY_TYPE
&& !tree_int_cst_equal (TYPE_SIZE_UNIT (desttype), len))
fixes it.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/15419] memcpy pessimization
[not found] <bug-15419-4@http.gcc.gnu.org/bugzilla/>
@ 2011-05-22 15:38 ` steven at gcc dot gnu.org
2011-05-22 21:02 ` rguenth at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 9+ messages in thread
From: steven at gcc dot gnu.org @ 2011-05-22 15:38 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15419
Steven Bosscher <steven at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed|2009-04-22 23:01:37 |2011-05-22 17:12:37
--- Comment #3 from Steven Bosscher <steven at gcc dot gnu.org> 2011-05-22 15:13:52 UTC ---
$ cat t.c
typedef long size_t;
extern void *memcpy (void *__restrict __dest,
__const void *__restrict __src, size_t __n)
__attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));
typedef unsigned uint32_t;
uint32_t get_uint32(const void *p) {
uint32_t w;
memcpy(&w, p, sizeof (uint32_t));
return w;
}
uint32_t get_uint32a(const void *p) {
const struct { uint32_t w; } __attribute__((packed)) *wp = p;
return wp->w;
}
$ ./cc1 -quiet -m32 -O2 t.c -fdump-tree-optimized
$ cat t.s
.file "t.c"
.text
.p2align 4,,15
.globl get_uint32
.type get_uint32, @function
get_uint32:
.LFB0:
.cfi_startproc
subl $16, %esp
.cfi_def_cfa_offset 20
movl 20(%esp), %eax
movl (%eax), %eax
addl $16, %esp
.cfi_def_cfa_offset 4
ret
.cfi_endproc
.LFE0:
.size get_uint32, .-get_uint32
.p2align 4,,15
.globl get_uint32a
.type get_uint32a, @function
get_uint32a:
.LFB1:
.cfi_startproc
movl 4(%esp), %eax
movl (%eax), %eax
ret
.cfi_endproc
.LFE1:
.size get_uint32a, .-get_uint32a
.ident "GCC: (GNU) 4.6.0 20110312 (experimental) [trunk revision
170907]"
.section .note.GNU-stack,"",@progbits
$ cat t.c.143t.optimized
;; Function get_uint32 (get_uint32)
get_uint32 (const void * p)
{
uint32_t w;
uint32_t D.1997;
<bb 2>:
memcpy (&w, p_2(D), 4);
D.1997_3 = w;
return D.1997_3;
}
;; Function get_uint32a (get_uint32a)
get_uint32a (const void * p)
{
uint32_t D.1994;
<bb 2>:
D.1994_3 = MEM[(const struct *)p_1(D)].w;
return D.1994_3;
}
Isn't it possible to fold memcpy for selected small lengths to explicit memory
stores?
The code for x86_64 is identical for both functions.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2011-05-23 13:07 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-14 1:27 [Bug tree-optimization/15419] New: memcpy pessimization falk at debian dot org
2004-05-14 2:00 ` [Bug tree-optimization/15419] " pinskia at gcc dot gnu dot org
2005-05-18 7:37 ` rth at gcc dot gnu dot org
2005-05-18 8:21 ` rth at gcc dot gnu dot org
2005-08-05 20:40 ` rth at gcc dot gnu dot org
[not found] <bug-15419-4@http.gcc.gnu.org/bugzilla/>
2011-05-22 15:38 ` steven at gcc dot gnu.org
2011-05-22 21:02 ` rguenth at gcc dot gnu.org
2011-05-23 12:30 ` rguenth at gcc dot gnu.org
2011-05-23 13:13 ` rguenth at gcc dot gnu.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).