Is it possible to get an intermediate, optimized C file using GCC?

I have C code with a loop:

for(int i=0; i<1000; i+=ceil(sqrt(i)))
{
    do stuff that could benefit from loop unrolling;
}

      

I intend to use a macro to tell GCC to unroll the loops, but I would like to make sure that it is indeed looped out in this case (since the increment is not 1, but it can still be preprocessed and unrolled).

Is it possible to get GCC to output the .C file containing the code after optimizing it? (Hopefully including any optimizations it does with -O

that precedes assembly-level optimizations)?

I know I can confirm this using the build output, but I'd rather see something in C - it's much easier for me to read and understand.

+3


source to share


1 answer


C is a high-level, compiled language. Therefore, this is not a suitable representation of optimized machine code. While you might want to see C code easier to understand, it lacks absolute assembly precision that maps directly to machine code. For this simple example, you might have a pretty good idea what optimization means from a high level language perspective, but in general it is not so with optimization. A look at the assembly language reveals exactly what the compiler has done.

Second, compilers perform optimization on some intermediate representation (IR) , which looks more like machine code than high-level code (C in this case). To output high-level code after performing the optimization, a decompilation step is required. GCC is not a suitable place to add decompilation logic for a rarely used function like this. But if you really want to see optimized C code, you can run the GCC build through a decompiler to return high-level code.



Short answer: GCC won't do what you want, but you can generate C code from assembly using a decompiler.

Here is a thread on choosing a good C decompiler for Linux.

+5


source







All Articles