https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104683
Bug ID: 104683 Summary: -march=haswell generates invalid instructions on Celeron Haswell CPUs Product: gcc Version: 10.3.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: other Assignee: unassigned at gcc dot gnu.org Reporter: pc-gcc22 at crowcastle dot net Target Milestone: --- Many of the -march options enable instruction types like AVX that are not available on Pentium and Celeron processors in that family. I encountered this on a Haswell Celeron system running gcc 10.3.1. I suspect this is the same on many other versions. gcc --version gcc (Gentoo 10.3.1_p20211126 p0) 10.3.1 20211126 diff <(gcc -march=haswell -Q --help=target) <(gcc -march=native -Q --help=target) 12c12 < -mabm [disabled] --- > -mabm [enabled] 26,27c26,27 < -mavx [enabled] < -mavx2 [enabled] --- > -mavx [disabled] > -mavx2 [disabled] 48,49c48,49 < -mbmi [enabled] < -mbmi2 [enabled] --- > -mbmi [disabled] > -mbmi2 [disabled] 65c65 < -mf16c [enabled] --- > -mf16c [disabled] 70c70 < -mfma [enabled] --- > -mfma [disabled] 186c186 < -mxsave [enabled] --- > -mxsave [disabled] 188c188 < -mxsaveopt [enabled] --- > -mxsaveopt [disabled] Fortunately, -march=native is fine, but I encountered a project that detects the processor family and was setting -march=haswell, which failed with illegal instructions. While I would argue that -march=[family] should compile only using instructions available for all processors in [family], I could also see an argument for this being a documentation bug where the definition for -march=[family] should warn that it will enable features only available on some CPUs in that family, which is not what many users would expect. (There might be cause for separate -march definitions for lower-end processors, but I don't have brilliant ideas for syntax, and that might be just adding too much complexity.)