<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 - Missed optimisation in shuffle operation on avx"
   href="https://bugs.llvm.org/show_bug.cgi?id=39161">39161</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Missed optimisation in shuffle operation on avx
          </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>Linux
          </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>hello@dsprenkels.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I have the following C snippet:

```
__m256d example(__m256d x)
{
    __m256d ret = {};
    ret[0] = x[2];
    ret[1] = x[2];
    ret[2] = x[3];
    ret[3] = x[3];
    return ret;
}
```

which can be implemented using:

```
example:
  vperm2f128 ymm0, ymm0, ymm0, 0b00010001     ; [aa, bb, aa, bb]
  vpermilpd ymm0, ymm0, 0b1100                ; [aa, aa, bb, bb]
  ret
```

But LLVM compiles the code to:

```
example: # @example
  vextractf128 xmm0, ymm0, 1
  vmovddup xmm1, xmm0 # xmm1 = xmm0[0,0]
  vpermilpd xmm0, xmm0, 3 # xmm0 = xmm0[1,1]
  vinsertf128 ymm0, ymm1, xmm0, 1
  ret
```

Here's a link to the same snippet in godbolt: <a href="https://godbolt.org/z/NPYv_z">https://godbolt.org/z/NPYv_z</a>

I would like to take a shot at fixing this myself, if this is not too hard to
implement. At least, if it's possible and desired by you guys.


At the moment of compilation, godbolt reported the following version
information:
```
clang version 8.0.0 (trunk 343649)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/compiler-explorer/clang-trunk/bin
Compiler returned: 0
```</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>