* [Bug c/53937] Pack'ing struct causes gcc to not recognize that an field's address is aligned
2012-07-12 10:12 [Bug c/53937] New: Pack'ing struct causes gcc to not recognize that an field's address is aligned don.delfin at gmail dot com
@ 2012-07-12 10:50 ` don.delfin at gmail dot com
2012-07-12 11:21 ` rguenth at gcc dot gnu.org
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: don.delfin at gmail dot com @ 2012-07-12 10:50 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53937
--- Comment #1 from Krzysztof Gongolewski <don.delfin at gmail dot com> 2012-07-12 10:49:57 UTC ---
Created attachment 27780
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27780
Compiled example code
Assembler
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c/53937] Pack'ing struct causes gcc to not recognize that an field's address is aligned
2012-07-12 10:12 [Bug c/53937] New: Pack'ing struct causes gcc to not recognize that an field's address is aligned don.delfin at gmail dot com
2012-07-12 10:50 ` [Bug c/53937] " don.delfin at gmail dot com
@ 2012-07-12 11:21 ` rguenth at gcc dot gnu.org
2012-07-12 12:24 ` don.delfin at gmail dot com
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-07-12 11:21 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53937
Richard Guenther <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
--- Comment #2 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-07-12 11:21:23 UTC ---
Works as designed. The packed attribute tells GCC that the start of the
struct and all members might not be naturally aligned.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c/53937] Pack'ing struct causes gcc to not recognize that an field's address is aligned
2012-07-12 10:12 [Bug c/53937] New: Pack'ing struct causes gcc to not recognize that an field's address is aligned don.delfin at gmail dot com
2012-07-12 10:50 ` [Bug c/53937] " don.delfin at gmail dot com
2012-07-12 11:21 ` rguenth at gcc dot gnu.org
@ 2012-07-12 12:24 ` don.delfin at gmail dot com
2012-07-12 12:30 ` rguenth at gcc dot gnu.org
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: don.delfin at gmail dot com @ 2012-07-12 12:24 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53937
--- Comment #3 from Krzysztof Gongolewski <don.delfin at gmail dot com> 2012-07-12 12:24:42 UTC ---
But the compiler knows address of the struct at compilation time, it's
hard-coded. So gcc knows that both struct and member are perfectly aligned.
If you access only the struct, You can see that compiler uses knowledge that he
knows the exact address, and fact that the structure is aligned and reads
32-bits in one instruction.
To prove it, I compiled two additional functions:
extern BasicStructPacked aa;
void test_3()
{
*((int*)&STRUCT_REGULAR) = 0;
}
void test_4()
{
*((int*)&aa) = 0;
}
And compiler optimized the first function (test_3) as he knew the address and
knew it is aligned. The second function (test_4) was not optimized as compiler
didn't know address at compilation time.
Output of compiler:
(...)
test_3:
li 0,0
li 9,4096
stw 0,0(9)
blr
(...)
test_4:
lis 11,aa@ha
li 0,0
la 9,aa@l(11)
stb 0,aa@l(11)
stb 0,1(9)
stb 0,2(9)
stb 0,3(9)
blr
(...)
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c/53937] Pack'ing struct causes gcc to not recognize that an field's address is aligned
2012-07-12 10:12 [Bug c/53937] New: Pack'ing struct causes gcc to not recognize that an field's address is aligned don.delfin at gmail dot com
` (2 preceding siblings ...)
2012-07-12 12:24 ` don.delfin at gmail dot com
@ 2012-07-12 12:30 ` rguenth at gcc dot gnu.org
2012-07-12 12:46 ` don.delfin at gmail dot com
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-07-12 12:30 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53937
Richard Guenther <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |missed-optimization
Status|RESOLVED |ASSIGNED
Last reconfirmed| |2012-07-12
Resolution|INVALID |
AssignedTo|unassigned at gcc dot |rguenth at gcc dot gnu.org
|gnu.org |
Ever Confirmed|0 |1
--- Comment #4 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-07-12 12:30:17 UTC ---
Ok, let me investigate on current trunk. It might be that seeing 'packed'
makes us needlessly conservative here.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c/53937] Pack'ing struct causes gcc to not recognize that an field's address is aligned
2012-07-12 10:12 [Bug c/53937] New: Pack'ing struct causes gcc to not recognize that an field's address is aligned don.delfin at gmail dot com
` (3 preceding siblings ...)
2012-07-12 12:30 ` rguenth at gcc dot gnu.org
@ 2012-07-12 12:46 ` don.delfin at gmail dot com
2012-07-12 12:50 ` don.delfin at gmail dot com
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: don.delfin at gmail dot com @ 2012-07-12 12:46 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53937
Krzysztof Gongolewski <don.delfin at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords|missed-optimization |
Status|ASSIGNED |RESOLVED
Resolution| |INVALID
--- Comment #5 from Krzysztof Gongolewski <don.delfin at gmail dot com> 2012-07-12 12:46:31 UTC ---
I added __attribute__((aligned(4))) to my packed structure, and this convinced
gcc compiler that my struct and also the member IS aligned. All mentioned
functions was optimized.
For me it is enough workaround, but I think it is bug in gcc, because
hard-coded address convince compiler that the struct is aligned but doesn't
convince that the member is aligned. And using align attribute convince
compiler that both the structure and the member are aligned.
In my opinion both options (hard-coding address and adding align attribute)
should convince that both struct and member are aligned and result in the same
optimized outputs.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c/53937] Pack'ing struct causes gcc to not recognize that an field's address is aligned
2012-07-12 10:12 [Bug c/53937] New: Pack'ing struct causes gcc to not recognize that an field's address is aligned don.delfin at gmail dot com
` (4 preceding siblings ...)
2012-07-12 12:46 ` don.delfin at gmail dot com
@ 2012-07-12 12:50 ` don.delfin at gmail dot com
2012-07-12 12:53 ` don.delfin at gmail dot com
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: don.delfin at gmail dot com @ 2012-07-12 12:50 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53937
Krzysztof Gongolewski <don.delfin at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |ASSIGNED
Resolution|INVALID |
--- Comment #6 from Krzysztof Gongolewski <don.delfin at gmail dot com> 2012-07-12 12:50:01 UTC ---
Restore of status which I destroyed my last comment.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c/53937] Pack'ing struct causes gcc to not recognize that an field's address is aligned
2012-07-12 10:12 [Bug c/53937] New: Pack'ing struct causes gcc to not recognize that an field's address is aligned don.delfin at gmail dot com
` (5 preceding siblings ...)
2012-07-12 12:50 ` don.delfin at gmail dot com
@ 2012-07-12 12:53 ` don.delfin at gmail dot com
2012-07-13 9:45 ` rguenth at gcc dot gnu.org
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: don.delfin at gmail dot com @ 2012-07-12 12:53 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53937
Krzysztof Gongolewski <don.delfin at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |missed-optimization
--- Comment #7 from Krzysztof Gongolewski <don.delfin at gmail dot com> 2012-07-12 12:53:33 UTC ---
Restore of destroyed status.
Sorry, It is my first submition :)
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c/53937] Pack'ing struct causes gcc to not recognize that an field's address is aligned
2012-07-12 10:12 [Bug c/53937] New: Pack'ing struct causes gcc to not recognize that an field's address is aligned don.delfin at gmail dot com
` (6 preceding siblings ...)
2012-07-12 12:53 ` don.delfin at gmail dot com
@ 2012-07-13 9:45 ` rguenth at gcc dot gnu.org
2012-07-13 9:46 ` rguenth at gcc dot gnu.org
2012-07-13 10:09 ` rguenth at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-07-13 9:45 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53937
--- Comment #8 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-07-13 09:45:06 UTC ---
Author: rguenth
Date: Fri Jul 13 09:45:00 2012
New Revision: 189458
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=189458
Log:
2012-07-13 Richard Guenther <rguenther@suse.de>
PR middle-end/53937
* builtins.c (get_pointer_alignment_1): Handle constant
pointers.
Modified:
trunk/gcc/ChangeLog
trunk/gcc/builtins.c
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c/53937] Pack'ing struct causes gcc to not recognize that an field's address is aligned
2012-07-12 10:12 [Bug c/53937] New: Pack'ing struct causes gcc to not recognize that an field's address is aligned don.delfin at gmail dot com
` (7 preceding siblings ...)
2012-07-13 9:45 ` rguenth at gcc dot gnu.org
@ 2012-07-13 9:46 ` rguenth at gcc dot gnu.org
2012-07-13 10:09 ` rguenth at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-07-13 9:46 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53937
Richard Guenther <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |4.8.0
--- Comment #9 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-07-13 09:46:22 UTC ---
Fixed for 4.8.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c/53937] Pack'ing struct causes gcc to not recognize that an field's address is aligned
2012-07-12 10:12 [Bug c/53937] New: Pack'ing struct causes gcc to not recognize that an field's address is aligned don.delfin at gmail dot com
` (8 preceding siblings ...)
2012-07-13 9:46 ` rguenth at gcc dot gnu.org
@ 2012-07-13 10:09 ` rguenth at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-07-13 10:09 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53937
Richard Guenther <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
--- Comment #10 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-07-13 10:09:12 UTC ---
Fixed I said.
^ permalink raw reply [flat|nested] 11+ messages in thread