Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to list loads due to potential aliasing violations?

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.

like image 444
camelccc Avatar asked Oct 13 '14 11:10

camelccc


People also ask

What is the strict aliasing rule and why do we care?

"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.)"

What is aliasing in C++?

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.

What is pointer aliasing?

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.

What is aliasing in programming?

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.


1 Answers

GCC Debug options

Try out -ftree-dump-alias (search for alias in above link).

like image 122
Surt Avatar answered Sep 25 '22 13:09

Surt