[cfe-dev] Behavior of -mcpu

David Greene via cfe-dev cfe-dev at lists.llvm.org
Thu Feb 28 12:42:16 PST 2019


Stefan Teleman <stefan.teleman at gmail.com> writes:

> On Thu, Feb 28, 2019 at 2:09 PM David Greene via cfe-dev
> <cfe-dev at lists.llvm.org> wrote:
>>
>> Interesting.  I am observing different behavior between -mcpu= and
>> -march= -mtune= with aarch64-unknown-linux-gnu:
>
> We never supported -mtune=thunderx2t99.
>
> -mcpu=thunderx2t99
> -march=armv8.1-a+lse

This is problematic for users.  If clang interprets command-line flags
differently based on subtarget, how are users to know what to pass to
clang to get, say, the best performance, or best code size, or whatever?

Users don't expect to have to set up their build systems to pass
different -mcpu/-march/-mtune flags based on what they are targeting.
They want to do something like this and be done with it:

TARGET=$(call get_triple)
ARCH=$(call get_arch)
TUNE=$(call get_tune)

CFLAGS += --target ${TARGET} -march=${ARCH) -mtune=${TUNE}

They could, but probably won't be happy to, do:

ifeq (TARGET,aarch64-unknown-linux-gnu)
  ifeq (TUNE,thunderx2t99)
    # -mtune unsupported
    CFLAGS += -mcpu=${TUNE}
  else ifeq (TUNE,anothertarget)
    # -mcpu unsupported
    CFLAGS += -march=${ARCH} -mtune=${TUNE}
  else ifeq (TUNE,thirdtarget)
    CFLAGS += -mtune=${TUNE}
  endif
else ifeq(TARGET,x86_64-unknown-linux-gnu)
  ifeq (TUNE,skylake-avx512)
    # -mtune unsupported
    CFLAGS += -mcpu=${TUNE}
  else ifeq (TUNE,broadwell)
    # -mcpu unsupported
    CFLAGS += -march=${ARCH} -mtune=${TUNE}
  endif
else ifeq(TARGET,third-target-triple)
  # -mcpu and -mtune unsupported
  CFLAGS += -march=${ARCH}
endif

It's hard enough for users to support building for multiple subtargets
without having to deal with basic compiler behavior differences per
subtarget.

Perhaps there is some capability of clang I'm not understanding.  What's
the expected/canonical way to tune compilation for a subtarget?

                         -David



More information about the cfe-dev mailing list