This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/53937] Pack'ing struct causes gcc to not recognize that an field's address is aligned
- From: "don.delfin at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 12 Jul 2012 12:24:42 +0000
- Subject: [Bug c/53937] Pack'ing struct causes gcc to not recognize that an field's address is aligned
- Auto-submitted: auto-generated
- References: <bug-53937-4@http.gcc.gnu.org/bugzilla/>
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
(...)