[cfe-dev] Option -mtune

David Greene via cfe-dev cfe-dev at lists.llvm.org
Wed Apr 22 10:12:40 PDT 2020


Sjoerd Meijer via cfe-dev <cfe-dev at lists.llvm.org> writes:

> This is addressing the hard problem of setting optimal compiler
> options with -target, -march, -mcpu, and -mtune.  In this equation
> -mtune is just a minor annoyance, but if we could get rid of this part
> of the confusion then that would be a good change to me and avoid the
> regular question we get what the -mtune options should be.

Honestly, the whole system needs an overhaul:

http://clang-developers.42468.n3.nabble.com/Behavior-of-mcpu-td4064178.html

I noticed this odd difference in behavior based on target.  In the end
the answer was, "We want to behave like gcc," but that is not a very
compelling argument to me.  Yes "-m" options are machine-specific, but
giving the same option with the same name different behaviors is
non-intuitive.

It doesn't help that these options aren't very well documented:

https://clang.llvm.org/docs/UsersManual.html#target-specific-features-and-limitations

-target is barely mentioned for CPUs and there is certainly no
indication that one needs -target to make -mcpu/-mtune do something
useful.

Contrast that with gcc's extensive documentation of tuning parameters:

https://gcc.gnu.org/onlinedocs/gcc-9.3.0/gcc/Submodel-Options.html#Submodel-Options

Given the way -target works, we're already incompatible with gcc (gcc
with happily cross-compile/tune with -mcpu), so why not just do the
Right Thing and make these options behave uniformly across targets?  In
my mind it should be something like this:

* -mcpu implies -target (based on host machine), -march and -mtune

  Example: -mcpu=skylake-avx512 sets
    -target=x86_64-unknown-linux-gnu (when run on a Debian system)
    -march=skylake-avx512
    -mtune=skylake-avx512

  Note that if the host system is, say, an AArch64 Debian machine,
  -target would still be implied as x86_64-unknown-linux-gnu (i.e. we
  are cross-compiling).
  
* -mtune implies -triple (based on host machine as with -mcpu)

* -march implies -triple (based on host machine as with -mcpu)

Of course one could always pass -triple (or other options) explicitly to
suppress the implied behaviors.  We still want -mtune and -march to
operate independently of each other (i.e. neither implies the other) so
that one can generate backward-compatible binaries while still tuning
for recent microarchitectures.

                     -David


More information about the cfe-dev mailing list