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

    <tr>
        <th>Summary</th>
        <td>
            [X86] Vector "shifted mask" immediate materialization
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            backend:X86
      </td>
    </tr>

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

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

<pre>
    Currently, we only special-case all-zeros and all-ones constants,
because both of them can be materialized by a single dep-breaking instruction,
and all-zeros may even be a zero-cycle instruction.

But for the other constants, we e.g. fallback to broadcast load from constant pool.
Is that always optimal? For example, to materialize a "shifted mask" constant
(https://github.com/llvm/llvm-project/blob/c2a8a104ec320c8bed39c3632eae2fb37f53487b/llvm/include/llvm/Support/MathExtras.h#L477-L481) by materializing all-ones constant + one or two shifts:
https://godbolt.org/z/beWjqrq6f
Wouldn't that be better?

(inverse shifted mask would also require an `not`, but not sure if that will be profitable anymore.)

CC @RKSimon @topperc @spatel-gh 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVU01zmzAQ_TX4smMGBMZw4NAkzUyn6aWdaXtdicUoEYhIIq7z67vCTeJ-XDrjAS1437739iFtd2qvF-doCuaUiGs4EtjJnMDPpDSarUJPgMZsn8lZDzh1a2Un8qDs5ANOwXNjkt0k2TtJChdukDYMYHsIA42gcAJJMGIgx5D6mTqQJ0DwejoYgo7mrXSED1yCZki3qKDt9Ir6MvRMYcQT0BOtmAjx2VadFONctKbnxvP1agnQWxfJAPMi9xvxqJjSQwo9j5CoHiBYkM5ix9IDGD5A7-z42gSztebXgA-eUTEwuyOePNg56BFNUtzCLQ-kHzjOhuIQxrzQz7wTIfyg-8BejOgfuHwd8Iu7qIcQZp8UfLzl30GHYZGpsiMXxjy93Lazs_ekApfSWMk3JbDGPCtJFSJTtaSuaFRRFYKQRC-Lfb8rynov33D0pMzS0duDL8s8WxcxP2EY3v8IDn06JKK4K_f77V1Z54lo4hbfVMXt_RUN1nnFgWLj2f-jhVXzqmkV-YdC20lrQmrdgavnKIi-3T-6x6o___2bXUzHudiHs-2cAEmBCbDjlxtn7_T0RI6TeGkyHGM_k_QWHD0u2vEmJkiqbLKBr3FRksPCFfiFX-r-POeojYnD2OleB5Qm9p1G6yhlGy4nX19DUmafP37Ro53iMdh5Jqfi0c_sldkeBth0bdE1RYOboIOhNtldfa-rZHcDX3mRbNU_0qHHkTrNCBeWY8z6ZnGm_e-oaO8X4vzf7sp9WWyGVmEli1Lkoq77Ks_yMlONEkJlO9E0OVYbg5KMj1yZTvxQaOp4YiQuBHPf6FZkQmRlVub7nHFSUTVNUVOFtEPKq4Y9oBG1SSOXuOWNa1dacjl4fmm0D_7tJXqvDxOt9kR8XMJgXXtHHGh6-vxhs2poVwE_Ae8bklA">