I have been working on a sizeable performance critical code base, where compiling with the latest versions of gcc give numerous warnings about type punning, leading me to compile with -fno-strict-aliasing
. I don't believe there is any performance loss here that can be avoided anyway. I do however believe that there may be rather more significant issues with aliasing pointers of the same type.
Is there any way to get gcc, or any other tool to list all places in a code base where additional loads / stores are taking place due to potential aliasing violations that gcc can't detect, whether pointers are of the same type or not? That way, I could go compare with a code profiler and see if the situation can be improved in places where it actually matters by the use of restrict
, local variables, refactoring etc. Trying to guess what the compiler is thinking through looking at generated assembler is both time consuming and error prone, particularly for this. I'm interested in answers for both C and C++ if they are different.
"Strict aliasing is an assumption, made by the C (or C++) compiler, that dereferencing pointers to objects of different types will never refer to the same memory location (i.e. alias each other.)"
In C, C++, and some other programming languages, the term aliasing refers to a situation where two different expressions or symbols refer to the same object.
Pointer aliasing is a hidden kind of data dependency that can occur in C, C++, or any other language that uses pointers for array addresses in arithmetic operations. Array data identified by pointers in C can overlap, because the C language puts very few restrictions on pointers.
An alias occurs when different variables point directly or indirectly to a single area of storage. Aliasing refers to assumptions made during optimization about which variables can point to or occupy the same storage area.
GCC Debug options
Try out -ftree-dump-alias (search for alias in above link).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With