[cfe-dev] struct copy

Chris Lattner clattner at apple.com
Sat Sep 27 23:08:25 PDT 2008

On Sep 26, 2008, at 1:51 PM, Mattias EngdegÄrd wrote:

> Chris Lattner <clattner at apple.com> writes:
>> In practice, using memcpy for small structs is bad, which is why  
>> llvm-
>> gcc lowers it.  The badness stems from two reasons: 1) current
>> deficiencies in the optimizer, and 2) not being able to model the  
>> fact
>> that a memcpy doesn't need to copy the "holes" in a struct.
> How would not copying the holes improve anything? They are there for
> alignment, but moving entire machine words is no slower than
> individual bytes.

This is true on the micro-level, but is false in the macro level.  For  
example, if the caller of a function does a one byte store into a  
struct field, and the callee does a memcpy (ending up with a 32-bit  
read), you get a store forwarding speculation failure on most out of  
order processors.


More information about the cfe-dev mailing list