<html>
    <head>
      <base href="http://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 --- - [x86] unnecessary shuffling/moves with unary AVX/SSE scalar math ops"
   href="http://llvm.org/bugs/show_bug.cgi?id=21507">21507</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[x86] unnecessary shuffling/moves with unary AVX/SSE scalar math ops
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </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>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>new bugs
          </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>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Each of these functions should produce a single math instruction; no shuffling
or moves are needed:

$ cat unary_sse.c
#include <xmmintrin.h>

__m128 recip(__m128 x) {
        return _mm_rcp_ss(x);
}

__m128 square_root(__m128 x) {
        return _mm_sqrt_ss(x);
}

__m128 recip_square_root(__m128 x) {
        return _mm_rsqrt_ss(x);
}

------------------------------------------------------------------------------

With an AVX subtarget, we always get a bonus shuffle:

$ ./clang unary_sse.c -O1 -fomit-frame-pointer -march=btver2 -S -o -
...
_recip:                                 ## @recip
    .cfi_startproc
## BB#0:                                ## %entry
    vrcpss    %xmm0, %xmm0, %xmm1
    vblendps    $1, %xmm1, %xmm0, %xmm0 ## xmm0 = xmm1[0],xmm0[1,2,3]
    retq
    .cfi_endproc

    .globl    _square_root
    .align    4, 0x90
_square_root:                           ## @square_root
    .cfi_startproc
## BB#0:                                ## %entry
    vsqrtss    %xmm0, %xmm0, %xmm1
    vblendps    $1, %xmm1, %xmm0, %xmm0 ## xmm0 = xmm1[0],xmm0[1,2,3]
    retq
    .cfi_endproc

    .globl    _recip_square_root
    .align    4, 0x90
_recip_square_root:                     ## @recip_square_root
    .cfi_startproc
## BB#0:                                ## %entry
    vrsqrtss    %xmm0, %xmm0, %xmm1
    vblendps    $1, %xmm1, %xmm0, %xmm0 ## xmm0 = xmm1[0],xmm0[1,2,3]
    retq


With an SSE-only subtarget, we get bonus moves:

$ ./clang unary_sse.c -O1 -fomit-frame-pointer -march=core2 -S -o -
...
_recip:                                 ## @recip
    .cfi_startproc
## BB#0:                                ## %entry
    movaps    %xmm0, %xmm1
    rcpss    %xmm1, %xmm1
    movss    %xmm1, %xmm0
    retq
    .cfi_endproc

    .globl    _square_root
    .align    4, 0x90
_square_root:                           ## @square_root
    .cfi_startproc
## BB#0:                                ## %entry
    sqrtss    %xmm0, %xmm1
    movss    %xmm1, %xmm0
    retq
    .cfi_endproc

    .globl    _recip_square_root
    .align    4, 0x90
_recip_square_root:                     ## @recip_square_root
    .cfi_startproc
## BB#0:                                ## %entry
    movaps    %xmm0, %xmm1
    rsqrtss    %xmm1, %xmm1
    movss    %xmm1, %xmm0
    retq

-----------------------------------------------------------------------------

$ ./clang -v
clang version 3.6.0 (221350)
Target: x86_64-apple-darwin13.4.0
Thread model: posix</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>