This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: malloc attributes and realloc


Zack Weinberg wrote:

 if (*p != 'a')
   *p = 'a';

can be safely optimized into
 *p = 'a';

... that is *not* an optimization; the cache behavior of the latter is
likely to be worse than the former.

On many architectures it will be a win, especially if it avoids a midpredicted branch. Of *course* you only do this transformation if it improves things.

Of course you are quite right to remind us that quite often things
that seem like obvious optimizations (like inlining!) are in fact
pessimizations. One has to be very careful on modern architectures!



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]