[llvm-bugs] [Bug 48479] New: Suboptimal (R)SQRT codegen

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Dec 10 17:24:19 PST 2020


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

            Bug ID: 48479
           Summary: Suboptimal (R)SQRT codegen
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: X86
          Assignee: unassignedbugs at nondot.org
          Reporter: david.bolvansky at gmail.com
                CC: craig.topper at gmail.com, llvm-bugs at lists.llvm.org,
                    llvm-dev at redking.me.uk, pengfei.wang at intel.com,
                    spatel+llvm at rotateright.com

#include <array>
#include <cmath>
#include <numeric>

float Distance(std::array<float, 16> diffs) {
  float dist = std::accumulate(diffs.begin(), diffs.end(), 0.0f);
  dist = std::sqrt(dist);
  return dist;
}



Clant trunk -Ofast  -mavx2

.LCPI0_0:
  .long 0xbf000000 # float -0.5
.LCPI0_1:
  .long 0xc0400000 # float -3
.LCPI0_2:
  .long 0x7fffffff # float NaN
.LCPI0_3:
  .long 0x00800000 # float 1.17549435E-38
Distance(std::array<float, 16ul>): # @Distance(std::array<float, 16ul>)
  vmovups ymm0, ymmword ptr [rsp + 8]
  vaddps ymm0, ymm0, ymmword ptr [rsp + 40]
  vextractf128 xmm1, ymm0, 1
  vaddps xmm0, xmm0, xmm1
  vpermilpd xmm1, xmm0, 1 # xmm1 = xmm0[1,0]
  vaddps xmm0, xmm0, xmm1
  vmovshdup xmm1, xmm0 # xmm1 = xmm0[1,1,3,3]
  vaddss xmm0, xmm0, xmm1
  vrsqrtss xmm1, xmm0, xmm0
  vmulss xmm2, xmm0, xmm1
  vmulss xmm3, xmm2, dword ptr [rip + .LCPI0_0]
  vmulss xmm1, xmm2, xmm1
  vaddss xmm1, xmm1, dword ptr [rip + .LCPI0_1]
  vmulss xmm1, xmm3, xmm1
  vbroadcastss xmm2, dword ptr [rip + .LCPI0_2] # xmm2 = [NaN,NaN,NaN,NaN]
  vandps xmm0, xmm0, xmm2
  vcmpltss xmm0, xmm0, dword ptr [rip + .LCPI0_3]
  vandnps xmm0, xmm0, xmm1
  vzeroupper
  ret



ICC 19 -Ofast  -mavx2

Distance(std::array<float, 16ul>):
        vmovups   ymm0, YMMWORD PTR [8+rsp]                     #141.42
        vaddps    ymm1, ymm0, YMMWORD PTR [40+rsp]              #134.5
        vextractf128 xmm2, ymm1, 1                              #134.5
        vaddps    xmm3, xmm1, xmm2                              #134.5
        vmovhlps  xmm4, xmm3, xmm3                              #134.5
        vaddps    xmm5, xmm3, xmm4                              #134.5
        vshufps   xmm6, xmm5, xmm5, 245                         #134.5
        vaddss    xmm0, xmm5, xmm6                              #134.5
        vsqrtss   xmm0, xmm0, xmm0                              #464.12
        vzeroupper                                              #8.10
        ret                                                     #8.10



rsqrt and vmulss seems problematic here... Block RThroughput is better for ICC.

https://gcc.godbolt.org/z/rb1WMY

-- 
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/20201211/58699445/attachment-0001.html>


More information about the llvm-bugs mailing list