[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:


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

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


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

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


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)

  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.


More information about the cfe-dev mailing list