[llvm-bugs] [Bug 31455] New: [X86][SSE] Slow sqrt libcall branch due to dependency on sqrtsd result

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Dec 22 11:49:40 PST 2016


https://llvm.org/bugs/show_bug.cgi?id=31455

            Bug ID: 31455
           Summary: [X86][SSE] Slow sqrt libcall branch due to dependency
                    on sqrtsd result
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: Backend: X86
          Assignee: unassignedbugs at nondot.org
          Reporter: llvm-dev at redking.me.uk
                CC: craig.topper at gmail.com, llvm-bugs at lists.llvm.org,
                    mkuper at google.com, spatel+llvm at rotateright.com
    Classification: Unclassified

#include <math.h>
double sqrt_add(double a, double b) {
  return sqrt(a) + b;
}


define double @sqrt_add(double, double) {
  %3 = tail call double @sqrt(double %0)
  %4 = fadd double %3, %1
  ret double %4
}
declare double @sqrt(double)

Found while looking at c-ray performance (PR22657), llvm tests for an
non-finite result of the (slow) sqrtsd instruction to decide whether to
fallback on the sqrt libcall, while gcc tests the input for a negative or zero
input, giving the branch logic more time to work.

llvm (3.9) output:

sqrt_add(double, double):                          # @sqrt_add(double, double)
        vmovapd %xmm0, %xmm2
        vxorps  %xmm0, %xmm0, %xmm0
        vsqrtsd %xmm2, %xmm0, %xmm0
        vucomisd        %xmm0, %xmm0
        jnp     .LBB0_2
        pushq   %rax
        vmovapd %xmm2, %xmm0
        vmovsd  %xmm1, (%rsp)           # 8-byte Spill
        callq   sqrt
        vmovsd  (%rsp), %xmm1           # 8-byte Reload
        addq    $8, %rsp
.LBB0_2:
        vaddsd  %xmm1, %xmm0, %xmm0
        retq

gcc (7 snapshot) output:

sqrt_add(double, double):
        vsqrtsd %xmm0, %xmm3, %xmm3
        subq    $24, %rsp
        vxorpd  %xmm2, %xmm2, %xmm2
        vucomisd        %xmm0, %xmm2
        vmovsd  %xmm3, (%rsp)
        jbe     .L2
        vmovsd  %xmm1, 8(%rsp)
        call    sqrt
        vmovsd  8(%rsp), %xmm1
.L2:
        vaddsd  (%rsp), %xmm1, %xmm0
        addq    $24, %rsp
        ret

-- 
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/20161222/e3616300/attachment-0001.html>


More information about the llvm-bugs mailing list