[cfe-dev] Option -mtune

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


Arthur O'Dwyer via cfe-dev <cfe-dev at lists.llvm.org> writes:
> My naïve opinions FWIW:
> - Personally I have never understood the difference between -target,
> -march, -mcpu, and -mtune (particularly -march and -mtune). There are a lot
> of blog posts out there (e.g.
> https://lemire.me/blog/2018/07/25/it-is-more-complicated-than-i-thought-mtune-march-in-gcc/
>  http://sdf.org/~riley/blog/2014/10/30/march-mtune/ ) indicating that I'm
> not alone.  (Anyone got a really good resource on this topic?)

It's confusing because it differs by target.  I just sent a message
about how *I* think it should work, based on how it works for gcc on
X86:

-march specifies an instruction set to use (for example
-march=skylake-avx512 would enable AVX512F extensions, among others).

-mtune specifies tuning for a particular microarchitecture (for example
-mtune=broadwell would optimize for that chip's microarchitecture).

Note that "nonsensical" combinations like -march=skylake-avx512
-mtune=broadwell should be permitted.  This would mean generate code for
AVX512F and other extensions but, for example, schedule based on the
broadwell microarchitecture.  More often this would be used to generate
backward-compatible code but tuned for a newer microarchitecture (for
example -march=haswell -mtune=icelake).

Currently gcc defined -mcpu as an alias for -mtune on x86.  I would
propose that clang's -mcpu imply -target, -march and -mtune for all
targets, as outlined in my other message.

> - It sounds like -mtune's behavior is not "falsifiable"; it can never
> produce "wrong" code; it's purely an optimization option, like -O2. So
> there is no practical difference, but there may be a psychological
> difference, between saying "Clang permanently treats -mtune as a no-op"
> versus "Clang has a remarkably low *quality of implementation* for -mtune,
> and has no immediate plans to either improve or regress it."

-mtune is very important to our customers and I suspect others'
customers as well.  Having it behave as a no-op is not ideal and having
it do so without at least a warning is very nearly considered broken.

> - I don't think Clang should do anything actively to break
> scripts/Makefiles that invoke both GCC and Clang as "$(CXX) -mtune=...".
> That would be a downside with no upside.

It depends on what "break" means.  As I wrote in my other message, the
behavior of -march/-mtune also depends on -target which to me is very
non-intuitive.  gcc has no -target option so we have already broken new
ground.  I agree that using -march/-mtune should not abort the compiler
but I think it's fair game to have them behave differently from gcc,
especially given gcc's (and currently clang's because clang follows gcc
in this area) non-uniform behavior across targets.

                     -David


More information about the cfe-dev mailing list