This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug rtl-optimization/55360] New: [TileGX] Passing structure by value on stack needlessly writes to and reads from memory
- From: "colanderman at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 16 Nov 2012 20:53:52 +0000
- Subject: [Bug rtl-optimization/55360] New: [TileGX] Passing structure by value on stack needlessly writes to and reads from memory
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55360
Bug #: 55360
Summary: [TileGX] Passing structure by value on stack
needlessly writes to and reads from memory
Classification: Unclassified
Product: gcc
Version: 4.7.2
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: rtl-optimization
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: colanderman@gmail.com
#include <stdint.h>
struct bar { uint8_t a, b, c, d; };
struct bla { unsigned long a:8, b:8, c:8, d:8; };
uint64_t bar(struct bar);
uint64_t bla(struct bla);
uint64_t foo(uint8_t a, uint8_t b, uint8_t c, uint8_t d)
{ return bar((struct bar) { a, b, c, d }); }
uint64_t baz(uint8_t a, uint8_t b, uint8_t c, uint8_t d)
{ return bla((struct bla) { a, b, c, d }); }
when compiled with "gcc -Wall -std=gnu99 -O3 -S pbv.c" produces:
.file "pbv.c"
.text
.align 8
.global foo
.type foo, @function
foo:
.LFB0:
.cfi_startproc
{
st sp, lr
.cfi_offset 55, 0
move r29, sp
addi r28, sp, -16
}
addi sp, sp, -24
.cfi_def_cfa_offset 24
{
st r28, r29
addi r11, sp, 21
addi r10, sp, 20
}
{
st1 r11, r1
addi r11, sp, 22
}
{
st1 r11, r2
addi r11, sp, 23
}
{
st1 r10, r0
movei r0, 0
}
st1 r11, r3
ld4u r10, r10
{
bfins r0, r10, 0, 0+32-1
jal bar
}
addi r29, sp, 24
ld lr, r29
{
addi sp, sp, 24
.cfi_restore 54
.cfi_restore 55
.cfi_def_cfa_offset 0
jrp lr
}
.cfi_endproc
.LFE0:
.size foo, .-foo
.align 8
.global baz
.type baz, @function
baz:
.LFB1:
.cfi_startproc
{
movei r10, 0
st sp, lr
.cfi_offset 55, 0
move r29, sp
}
{
bfins r10, r0, 0, 7
addi r28, sp, -8
}
{
bfins r10, r1, 8, 8+8-1
addi sp, sp, -16
}
.cfi_def_cfa_offset 16
{
bfins r10, r2, 16, 16+8-1
st r28, r29
}
bfins r10, r3, 24, 24+8-1
{
move r0, r10
jal bla
}
addi r29, sp, 16
ld lr, r29
{
addi sp, sp, 16
.cfi_restore 54
.cfi_restore 55
.cfi_def_cfa_offset 0
jrp lr
}
.cfi_endproc
.LFE1:
.size baz, .-baz
.ident "GCC: (GNU) 4.7.2"
.section .note.GNU-stack,"",@progbits
My expectation is that the foo and baz should compile identically, and should
use the bfins bit-arithmetic functions like baz does, rather than redundant
stores and loads to stack like foo does.
This is with a vanilla GCC 4.7.2 build on a Tilempower system (roughly CentOS
5.7).
The problem does not occur on Debian x86-64 with either GCC 4.4.6 or GCC 4.7.2.
Possibly related to http://gcc.gnu.org/bugzilla/show_bug.cgi?id=7061 (however
that case seems to be fixed in 4.7.2).