C Optimization Tips – Dealing with Aliasing

Though in general it is true that you should simply leave C code optimization to the compiler, it sometimes is useful to provide hints to the compiler. This is because when optimizing the compiler has to make a few basic global assumptions so as to generate correct code in all situations, but these assumptions may not be true in your specific code.

A case in point is providing aliasing hints through the use of the C99 restrict keyword or the GCC extension __restrict__. See this excellent article with an easy example that will help you understand aliasing and how to deal with it.


Leave a Reply

Your email address will not be published. Required fields are marked *