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

    <tr>
        <th>Summary</th>
        <td>
            [X86] LLVM cannot reuse same vector constants
        </td>
    </tr>

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

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

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

<pre>
    Here is my code: https://gcc.godbolt.org/z/Ma9r6Whz7
LLVM generate the table twice while gcc can reuse the shuffle table in function `f`, because the low part of the shuffle table is same. The same goes for the table `vone` below. Additionally, gcc can use `vpbroadcastb` to generate the table `vone` instead of putting the table in memory and using `vmovdqa64` to load it. This can reduce the size of the code and it doesn't slow the code.
So I hope llvm can generate `vpbroadcast` when the table has repeating elements and reuse the vector constants if possible.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxsU81u3CAQfhp8GcXC-HcPPmwbWa2UnFq1vWIYbCoMLuBdbZ6-wtlttlFOHL6Z72eY4SHoySL2pP5E6seMb3F2vmesK-uWFV2djU5e-i_oEXSA5QLCSSTlEeYY10DKI2EDYcMkRD45OToTc-cnwoYXwoZnfvDNz_mlJfSR0OPT049nmNCi5xEhzgiRjwYhnrVAOM_aIExCgOAWPG7htSbMm1LmVqstqM2KqJ0F0lBFGkrYZxhR8FuDcWdYuY_g1EcEAQJfMIfvCeILwuQwgHL-zhFp6MlZJA2FEY0753CUUidRbswlCd58JtFUvY7ecSl4iGPqiu6joHe02oaIXCaP6xajttNdnbaw4OL8BbiVsIWEpt7FneQf3lRXBeO4BB1TFB2uU5ObuI5Nv-BtAunPdiodQToMlrA2QkiDusH56xd9c_AVZrciGHNads5_Of6PmTycZ7R3tmcewOOKfI-DBhe0MezCb995QhGdB-FsiDzBWsHqQtCjwTyTfSkP5YFn2Bctrbq6Lroqm_vu0GDBR4qqOFQKZYOqUVVBlSqwbdkh0z2jrKJFQSmrS1rlSnXF2HZtW2KBQkpSUVy4NnkKlnY00yFs2LdtXXWZ4SOasF8BYxbPsIOEsXQUvk89D-M2BVJRo0MMbyxRR7Ofz6-uIfUj7EsuuLUuXlPvS_Y-drZ507-7IR3nbcyFWwgbEv_1eVi9-40iEjbsrgJhw-76bwAAAP__WXE_ug">