Re: [RFC PATCH 1/2] Replace memset(0) with static initialization where possible

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 9 Oct 2008, Brandon Casey wrote:

> "Possible" benefits:
> 
>   1) more concise, so it improves readability in most cases
>   2) gives compiler more flexibility when optimizing

Beware beware.  At some point this wasn't a gain at all with some gcc 
versions as it was stupid enough to construct a temporary object on the 
stack corresponding to "{ 0, }" and afterward do the assignment by 
*copying* this object to a different stack slot corresponding to the 
actual variable instead of constructing the initial value in place.

Also note that, on the other hand, gcc is smart enough to optimize a 
memset() using a constant size and value already by doing appropriate 
code replacement inline.  I've also seen cases where gcc did the 
opposite and replaced an explicit assignment like your patch does with 
an actual call to memset() when optimizing for size.

So when claiming flexibility for the compiler to better optimize things, 
please make sure this is really what is happening through assembly dump 
inspection.


Nicolas
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux