<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Incorrect code generated for llvm.masked.store <2 x i1> with a variable mask"
   href="https://llvm.org/bugs/show_bug.cgi?id=31305">31305</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Incorrect code generated for llvm.masked.store <2 x i1> with a variable mask
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Backend: X86
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>zvi.rackover@intel.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>define void @unmasked(<2 x i1> %x, <2 x i1>* %ptr) nounwind {
   store <2 x i1> %x, <2 x i1>* %ptr
   ret void
 }

 define void @masked_const(<2 x i1> %x, <2 x i1>* %ptr) nounwind {
   call void @llvm.masked.store.v2i1.p0v2i1(<2 x i1> %x, <2 x i1>* %ptr, i32 0,
<2 x i1> <i1 1, i1 1>)
   ret void
 }


For both functions above we generate:
llc -mcpu=skx

  vpsllq  $63, %xmm0, %xmm0
  vptestmq        %xmm0, %xmm0, %k0
  kmovb   %k0, (%rdi)
  retq

But in the case of a variable mask:

 define void @masked_var(<2 x i1> %x, <2 x i1>* %ptr) nounwind {
   call void @llvm.masked.store.v2i1.p0v2i1(<2 x i1> %x, <2 x i1>* %ptr, i32 0,
<2 x i1> %x)
   ret void
 }

the generated code stores each vector element in a distinct byte:
        vpsllq  $63, %xmm0, %xmm0
        vptestmq        %xmm0, %xmm0, %k0
        kshiftlw        $15, %k0, %k1
        kshiftrw        $15, %k1, %k1
        kmovw   %k1, %eax
        andl    $1, %eax
        testb   %al, %al
        je      .LBB2_2
# BB#1:                                 # %cond.store
        kmovb   %k1, (%rdi)
.LBB2_2:                                # %else
        kshiftlw        $14, %k0, %k0
        kshiftrw        $15, %k0, %k0
        kmovw   %k0, %eax
        andl    $1, %eax
        testb   %al, %al
        je      .LBB2_4
# BB#3:                                 # %cond.store1
        kmovb   %k0, 1(%rdi)
.LBB2_4:                                # %else2
        retq</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>