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