[LLVMbugs] [Bug 21507] New: [x86] unnecessary shuffling/moves with unary AVX/SSE scalar math ops

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Nov 6 14:20:31 PST 2014


http://llvm.org/bugs/show_bug.cgi?id=21507

            Bug ID: 21507
           Summary: [x86] unnecessary shuffling/moves with unary AVX/SSE
                    scalar math ops
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: spatel+llvm at rotateright.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

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

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20141106/248dba98/attachment.html>


More information about the llvm-bugs mailing list