<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - [x86] failed to select vblendv with casted vector ops"
   href="https://bugs.llvm.org/show_bug.cgi?id=32866">32866</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[x86] failed to select vblendv with casted vector ops
          </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>All
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>enhancement
          </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>spatel+llvm@rotateright.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Forking this off from <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Poor AVX code generation on 8xi1 masks"
   href="show_bug.cgi?id=14657">bug 14657</a>.

This test exists in test/CodeGen/X86/cast-vsel.ll:

define <8 x i16> @trunc(<8 x i16> %a, <8 x i16> %b, <8 x i32> %c, <8 x i32> %d)
{
  %cmp = icmp eq <8 x i16> %a, %b
  %sel = select <8 x i1> %cmp, <8 x i32> %c, <8 x i32> %d
  %tr = trunc <8 x i32> %sel to <8 x i16>
  ret <8 x i16> %tr
}

After <a href="https://reviews.llvm.org/rL301781">https://reviews.llvm.org/rL301781</a> , this is effectively:

define <8 x i16> @trunc_first(<8 x i16> %a, <8 x i16> %b, <8 x i32> %c, <8 x
i32> %d) {
  %cmp = icmp eq <8 x i16> %a, %b
  %ctr = trunc <8 x i32> %c to <8 x i16>
  %dtr = trunc <8 x i32> %d to <8 x i16>
  %sel = select <8 x i1> %cmp, <8 x i16> %ctr, <8 x i16> %dtr
  ret <8 x i16> %sel
}

For both AVX1 and AVX2, we fail to use vblendv in either case (avx2 shown
here):

_trunc_first:                           ## @trunc_first
        .cfi_startproc
## BB#0:
        vpcmpeqw        %xmm1, %xmm0, %xmm0
        vmovdqa LCPI1_0(%rip), %ymm1    ## ymm1 =
[0,1,4,5,8,9,12,13,8,9,12,13,12,13,14,15,16,17,20,21,24,25,28,29,24,25,28,29,28,29,30,31]
        vpshufb %ymm1, %ymm2, %ymm2
        vpermq  $232, %ymm2, %ymm2      ## ymm2 = ymm2[0,2,2,3]
        vpshufb %ymm1, %ymm3, %ymm1
        vpermq  $232, %ymm1, %ymm1      ## ymm1 = ymm1[0,2,2,3]
        vpandn  %xmm1, %xmm0, %xmm1
        vpand   %xmm0, %xmm2, %xmm0
        vpor    %xmm1, %xmm0, %xmm0
        vzeroupper</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>