How to know what optimizations are enabled by clang and gcc for each mcpu and march option?

For gcc, try

gcc -mcpu=native -Q --help=target

The first line it prints:

gcc: warning: ‘-mcpu=’ is deprecated; use ‘-mtune=’ or ‘-march=’ instead

followed by

The following options are target specific:
  -m128bit-long-double                  [disabled]
  -m32                                  [disabled]
  -m3dnow                               [disabled]
  -m3dnowa                              [disabled]
  -m64                                  [enabled]
  -m80387                               [enabled]
  -m8bit-idiv                           [disabled]
   [...]

That answers the part for gcc.


Unfortunately, I am not familiar with clang. The best I could figure out so far is:

clang --target=i386 -### myfile.c.

where the -### makes the options to be shown. Different things are shown for arm. I am not sure if it is sufficient for you.

The file that sets the options seems to be Targets.cpp, although it is not much help as it a 5.8k line long file.

After looking at the llvm code generation, I have the impression that clang/LLVM doesn't have so many target specific options as gcc. See for example the target-specific feature matrix or the exposed (documented) options of llc.

And one more thing: clang exposes far less options of the compiler optimizations on purpose. For example there is no -finline-limit analogue exposed in clang.

Maybe -### prints everything exposed after all.