<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/102047>102047</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [AVX512] Prefering 512-bit vectors on recent Intel CPUs
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          zephyr111
      </td>
    </tr>
</table>

<pre>
    Hello,

`-mprefer-vector-width` has been set to 256 on past versions of Clang [apparently due to frequency scaling issues](https://stackoverflow.com/questions/63484266/enabling-avx512-support-on-compilation-significantly-decreases-performance) on Intel CPU when AVX-512 instructions was executed. This was indeed a frequent issue on Intel Skylake-SP CPUs (i.e. server-side Skylake CPUs). This issue has been mitigated on Intel Ice-Lake CPUs and AFAIK nearly fixed on Intel Sapphire-Rapids CPUs. This tends to be [confirmed by benchmarks](https://www.phoronix.com/review/intel-sapphirerapids-avx512/8). To quote the article:

> Across all of the benchmarks run with AVX-512 on/off, when AVX-512 was enabled for the Xeon Platinum 8380 2P "Ice Lake" server and running these AVX-512 heavy workloads it saw a *~175MHz drop on average* to the peak CPU frequency. Now **with Sapphire Rapids this is no longer the case but the peak CPU frequency was similar with/without AVX-512**. As shown previously, AMD EPYC Genoa also doesn't experience the AVX-512 downclocking. With Ice Lake it wasn't too bad to begin with unlike the AVX-512 Skylake days. [...] with the Xeon Platinum 8490H server **the average power consumption was basically the same**.

Note the Xeon Platinum 8380 is an [Ice-Lake CPU with 2 AVX-512 units](https://ark.intel.com/content/www/fr/fr/ark/products/212287/intel-xeon-platinum-8380-processor-60m-cache-2-30-ghz.html) while the Xeon Platinum 8490H is a [Sapphire-Rapids CPU with 2 AVX-512 units](https://ark.intel.com/content/www/fr/fr/ark/products/231747/intel-xeon-platinum-8490h-processor-112-5m-cache-1-90-ghz.html).

`-mprefer-vector-width` is still set to 256 when `-march=sapphirerapids`. See an [OpenMP example on GodBolt](https://godbolt.org/z/KTK5Y4dhn). I think we can safely **set `-mprefer-vector-width` to 512 by default on Intel Sapphire-Rapids CPUs**, as well as for all future Intel CPUs. Whether it worth it for Ice-Lake is arguable.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8Vktz47gR_jXQpYssEhL1OOigsVc7rslsXJnN7uyxCTZFRCDAAUDR8iG_PdUk5UfKu5VTLqLLBTT6ezWAIeiTJdqL4pMo7hfYx8b5_TN1zdXneb4oXXXdfyZjnJB3IrsX2WH-XWdJ23mqyScXUtH5ZNBVbMQ6gwYDlEQWAkWIDmSxBmehwxDhQj5oZwO4Gu4M2hOI4hN2HXqy0Vyh6om31J5-9GTVFYJCo-0JdAg9BVHcC7ltYuyCWB6EPAp5DBHV2V3I18YNqXKtkMcfPYXI5wh5XC9X25Vcr4U8ksWSqyV4eSpymYS-65yPibOJcm2nDfKmhEnRtVbILSUVKU8YKCQd-dr5Fq0iIXeM6cFGMnD3-E8YGrJw-O17UuQStA3R92rsAAYMQE-k-khVCr82evqXthVRBXjDGieIr1W_na8Gz5R8e-QDAgi51SmlEMhfyCdBV3RbMy4QcjeXnwq9yNDqqE8YqXqt_aAo-dttI6Ct4HA8PHwBS-jNFWr99Hb1N-y6RntK_oGdrsK4aT4qkq0CK1YSK6mcrbVvqYLyCiVZ1bTozx_KNgxD2jXOO6ufZtU8XTQNQh41H5uE-Vg_njprJuRxOyF18KN3kSA2BOijVoa4-FuTLn-Cg_IuBEBj2HK89rUt8L2FQcfmRThnhTy6uhby7r2io4jsHqqgdn4s9J2chUf2jO1b2C63GchHEFI-KAJmV0g5qzVS7Htr2cqxoUAvlRvCyxUG58_GYRVARwg4AIKQh3_nm-Lr52eovOtYDryQxxMJeWDKuYeO8Dz67yUxKfziBt4s5GHEdlMPZvXiZBGwDoyzJ5rAKAwEZR__pOpIQNCtNuhHylhBHRvXxxuS6cgUDgFC4wYLHevp-mCuTOfh6z389PjHHfxM1i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