0

I have a project where speed is paramount, so was experimenting with compiler flags to try and get some free performance. I have two builds that are identical except for the additional flag march=native in build 2.

For completeness the flags are:

A) -std=c++14 -g -fno-omit-frame-pointer -O3

B) -std=c++14 -g -fno-omit-frame-pointer -O3 -march-native

Running benchmarks on these builds yields a confusing result:

A) 61s

B) 160s

What can possibly going on here?

user3684792
  • 2,542
  • 2
  • 18
  • 23

2 Answers2

3

Using -march=native optimizes code for your current cpu. Most of the time, it will improve the speed of execution. Sometimes it may not produce the fastest possible code because it enables certain CPU instructions.

echo | clang -E - -march=native -###

will display what clang has enabled through -march=native. The most likely culprit is CMOV, which is enabled by -march=native. You can see an explanation of why that might slow things down in the answer to this question: gcc optimization flag -O3 makes code slower than -O2.

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
0

The parameter -march=native makes clang optimise code for your current CPU. In this case clang uses as much optimisations as possible and using it may break compatibility with other CPUs which, for example, don't have support for some instruction sets like AVX2, SSSE3 etc.

You may run

echo | clang -E - -O3 -###

and

clang -E - -march=native -O3 -###

to get the lists of features activated in the both of your cases.

CaptainRR
  • 421
  • 5
  • 17