Issue 71226
Summary Not all Skylake CPUs support AVX
Labels new issue
Assignees
Reporter clausecker
    @blastwave reported `clang -march=native` (on clang 14.0.5 as shipped with FreeBSD) generating binaries that wouldn't work on the host they were compiled on.  The CPU reports itself as (in FreeBSD's dmesg output):

```
CPU: Intel(R) Pentium(R) CPU G4500 @ 3.50GHz (3500.00-MHz K8-class CPU)
  Origin="GenuineIntel"  Id=0x506e3 Family=0x6  Model=0x5e  Stepping=3
 Features=0xbfebfbff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CLFLUSH,DTS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE>
 Features2=0x4ffaebbf<SSE3,PCLMULQDQ,DTES64,MON,DS_CPL,VMX,EST,TM2,SSSE3,SDBG,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,MOVBE,POPCNT,TSCDLT,AESNI,XSAVE,OSXSAVE,RDRAND>
 AMD Features=0x2c100800<SYSCALL,NX,Page1GB,RDTSCP,LM>
  AMD Features2=0x121<LAHF,ABM,Prefetch>
  Structured Extended Features=0x2942607<FSGSBASE,TSCADJ,SGX,ERMS,INVPCID,NFPUSG,RDSEED,SMAP,CLFLUSHOPT,PROCTRACE>
 Structured Extended Features3=0xc000000<IBPB,STIBP>
  XSAVE Features=0xf<XSAVEOPT,XSAVEC,XINUSE,XSAVES>
  VT-x: PAT,HLT,MTF,PAUSE,EPT,UG,VPID
  TSC: P-state invariant, performance statistics
```

This is a Skylake CPU without AVX support.  Clang [detects](https://github.com/llvm/llvm-project/blob/284c6990c133ed88f32de111accacc9f55a7a51d/llvm/lib/TargetParser/Host.cpp#L767) it as type `skylake` and thus enables AVX, but that is not supported.

The following code, when compiled with `-march=native` triggers the bug:

```
#include <stdio.h>

int main()
{
 printf("%f\n", 1.0);
}
```

Please fix the `-march=native` logic to take this possibility into account.

## Additional details

```
esther$ uname -apKU 
FreeBSD esther 13.2-RELEASE-p4 FreeBSD 13.2-RELEASE-p4 GENERIC amd64 amd64 1302001 1302001
esther$ freebsd-version -kru 
13.2-RELEASE-p4
13.2-RELEASE-p4
13.2-RELEASE-p4
esther$ sysctl hw.model 
hw.model: Intel(R) Pentium(R) CPU G4500 @ 3.50GHz
esther$ cat foo.c 
#include <stdio.h>
int main() {
 printf("%f\n", 1.0);
 return 0;
 }
esther$ cc -std=iso9899:1999 -m64 -O3 -ffast-math -ffp-contract=on -march=native -mtune=native -mfma -S -o foo.s foo.c
esther$ cat foo.s 
        .text
        .file   "foo.c"
 .section        .rodata.cst8,"aM",@progbits,8
        .p2align 3                               # -- Begin function main
.LCPI0_0:
 .quad   0x3ff0000000000000              # double 1
 .text
        .globl  main
        .p2align        4, 0x90
 .type   main,@function
main:                                   # @main
 .cfi_startproc
# %bb.0:
        pushq   %rbp
 .cfi_def_cfa_offset 16
        .cfi_offset %rbp, -16
        movq %rsp, %rbp
        .cfi_def_cfa_register %rbp
        vmovsd .LCPI0_0(%rip), %xmm0           # xmm0 = mem[0],zero
        movl $.L.str, %edi
        movb    $1, %al
        callq   printf
 xorl    %eax, %eax
        popq    %rbp
        .cfi_def_cfa %rsp, 8
        retq
.Lfunc_end0:
        .size   main, .Lfunc_end0-main
        .cfi_endproc
 # -- End function
        .type   .L.str,@object                  # @.str
        .section .rodata.str1.1,"aMS",@progbits,1
.L.str:
        .asciz "%f\n"
        .size   .L.str, 4

        .ident  "FreeBSD clang version 14.0.5 (https://github.com/llvm/llvm-project.git llvmorg-14.0.5-0-gc12386ae247c)"
        .section ".note.GNU-stack","",@progbits
        .addrsig
esther$ cc -o foo foo.s
esther$ ./foo
Illegal instruction (core dumped)
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to