Issue 168998
Summary [Clang] [AArch64] Runtime CPU feature checks ignored or unused with -march=native or -mcpu=native
Labels clang
Assignees
Reporter StDymphna
    After #160410 fixes host feature detection, LLVM itself correctly avoids illegal instructions on affected hardware during a program's runtime. However, for the compilation phase, Clang still uses static feature sets from AArch64Features.td based solely on CPU name detection.

The issue is presumed to be getAArch64ArchFeaturesFromMcpu() in clang/lib/Driver/ToolChains/Arch/AArch64.cpp either doesn't call or ignores getHostCPUFeatures() results, and only uses static feature sets in AArch64Features.td that are based solely on CPU name/ID. This affects mostly Qualcomm CPUs, as they rebrand ARM Cortex CPUs models that should have SVE, and via firmware, fusing, or some other mechanism, they disable SVE; it also potentially affects OSs configured without SVE support (e.g. Linux kernel with CONFIG_ARM64_SVE=N).


Reproduction:
```c
#include <stdio.h>

int main(void) {
  int n = 4096;
  float a[n];
  float b[n];
  int indices[n];

  for (int i = 0; i < n; i++) {
    a[i] = (float)i;
 b[i] = 0.0f;
    indices[i] = (n - 1) - i;
  }

  for (int i = 0; i < n; i++) {
    b[i] = a[indices[i]] * 2.0f;
  }

  printf("b[0] = %f, b[%d] = %f\n", b[0], n - 1, b[n - 1]);

  return 0;
}
```


```bash
clang -o example example.c -mcpu=native -O3 -ffp-model=fast
./example  # SIGILL on affected systems
```

Related: #130509, #149370
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to