Whenever I try to compile any C++ program with march=native
on a Macbook with a M1 chip, I get the following error when using clang:
clang: error: the clang compiler does not support '-march=native'
However, it used to work on an older Macbook with an Intel CPU. Does clang not support this architecture (yet)?
clang --version
gives:
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: arm64-apple-darwin20.2.0
cesare
January 17, 2022, 2:35pm
2
I see the same behaviour, and I see that this works with apple clang 13 on x64, so they must have made a decision to not support this (for some reason).
keith
January 29, 2022, 3:56am
3
I’m not familiar with the code, or specifics about this, but it looks to me like this special case of native
just isn’t implemented for arm64 like it is for x86_64. Here’s the x86_64 handling
// If -march=native, autodetect the feature list.
if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_march_EQ)) {
if (StringRef(A->getValue()) == "native") {
llvm::StringMap<bool> HostFeatures;
if (llvm::sys::getHostCPUFeatures(HostFeatures))
for (auto &F : HostFeatures)
Features.push_back(
Args.MakeArgString((F.second ? "+" : "-") + F.first()));
}
}
And the relevant arm64 handling happens here llvm-project/AArch64.cpp at 4465c299069f3ff5b93ba648edf699faf7f39e79 · llvm/llvm-project · GitHub
Which ends up checking what you pass against this switch llvm-project/AArch64TargetParser.cpp at 4465c299069f3ff5b93ba648edf699faf7f39e79 · llvm/llvm-project · GitHub
You could probably submit a change handling native
if you have a good use case and I imagine some more folks might see it
keith
February 14, 2022, 11:16pm
4
But what about M2? Also what about latencies sheduler vs M1? Also, what about support for GitHub - corsix/amx: Apple AMX Instruction Set ?
My machine.h has a new entry:
#define CPUFAMILY_ARM_BLIZZARD_AVALANCHE 0xda33d83d
That is probably an A15 or the M2.
LLVM has no machine models for modern Apple CPUs. It does not know the number of ports or latencies of the instructions. The difference between M1 and M2 will be that the M2 supports more instructions. ARMv8.5-A vs ARMv8.6-A.
Thanks for M2 support ⚙ D134351 AArch64: add definitions for recent Apple CPUs .
No, M2 is ARMv8.6-A, it just does not have SM4 instruction set, that it should.