<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] shuffle lowering should try harder to match unpack"
   href="https://bugs.llvm.org/show_bug.cgi?id=40434">40434</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[x86] shuffle lowering should try harder to match unpack
          </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>craig.topper@gmail.com, llvm-bugs@lists.llvm.org, llvm-dev@redking.me.uk, spatel+llvm@rotateright.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>define <8 x i32> @shuf_unpack(<8 x i32> %x, <8 x i32> %y) {
  %unpckh = shufflevector <8 x i32> %x, <8 x i32> %y, <8 x i32> <i32 2, i32 14,
i32 3, i32 15, i32 undef, i32 undef, i32 undef, i32 undef>
  ret <8 x i32> %unpckh
}

This translates to what I think is the optimal extract+unpckhps with AVX1:

$ llc -o - unpckh.ll -mattr=avx
        vextractf128    $1, %ymm1, %xmm1
        vunpckhps       %xmm1, %xmm0, %xmm0 ## xmm0 =
xmm0[2],xmm1[2],xmm0[3],xmm1[3]
        retq


But with AVX2, the availability of more shuffle instructions leads to a worse
outcome:

$ llc -o - unpckh.ll -mattr=avx2
        vblendps        $192, %ymm1, %ymm0, %ymm0 ## ymm0 =
ymm0[0,1,2,3,4,5],ymm1[6,7]
        vmovaps LCPI0_0(%rip), %ymm1    ## ymm1 = <2,6,3,7,u,u,u,u>
        vpermps %ymm0, %ymm1, %ymm0
        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>