Verifying compiler optimizations in gcc/g++ by analyzing assembly listings

前端 未结 8 1943
闹比i
闹比i 2021-02-04 09:00

I just asked a question related to how the compiler optimizes certain C++ code, and I was looking around SO for any questions about how to verify that the compiler has performed

8条回答
  •  轮回少年
    2021-02-04 09:31

    In order to output the optimizations applied you can use:

    -fopt-info-optimized

    To see those that have not been applied

    -fopt-info-missed

    Beware that the output is sent to standard error stream so to see it you actually have to redirect that : ( hint 2>&1 )

    Here is nice example of :

    g++ -O3 -std=c++11 -march=native -mtune=native 
            -fopt-info-optimized h2d.cpp -o h2d 2>&1
    
    h2d.cpp:225:3: note: loop vectorized
    h2d.cpp:213:3: note: loop vectorized
    h2d.cpp:198:3: note: loop vectorized
    h2d.cpp:186:3: note: loop vectorized
    

    You can check the interleaved output, when having applied -g with objdump -dS|c++filt , but that will not get you that far.Enjoy!

提交回复
热议问题