On 03/06/2015 06:30, Richard Henderson wrote: > On 05/21/2015 06:19 AM, Paolo Bonzini wrote: >> memcpy is faster than struct assignment, which copies each bitfield >> individually. Arguably a compiler bug, but memcpy is super-special >> cased anyway so what could go wrong? > > The compiler has the option of doing the copy either way. Any way to > actually show that the small memcpy is faster? That's one of those > things where I'm sure there's a cost calculation that said per member > was better.
Because the struct size is 32 bits, it's a no brainer that full copy is faster. However, SRA gets in the way, and causes the struct assignment to be compiled as two separate bitfield assignment. Later GCC passes don't have the means to merge them again. I filed https://gcc.gnu.org/PR66391 about this and CCed Martin Jambor. Paolo