[llvm-bugs] [Bug 35592] New: Missed optimization in math expression: squashing sqrt functions

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Dec 10 04:06:33 PST 2017


            Bug ID: 35592
           Summary: Missed optimization in math expression: squashing sqrt
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: zamazan4ik at tut.by
                CC: llvm-bugs at lists.llvm.org

clang(trunk) with '--std=c++17 -O3 -march=native -ffast-math' flags for this

#include <cmath>

double f(double a, double b, double c, double d)
    return sqrt(a)*sqrt(b)*sqrt(c)*sqrt(d);

generates this assembly:

f(double, double, double, double): # @f(double, double, double, double)
  vsqrtsd xmm0, xmm0, xmm0
  vsqrtsd xmm1, xmm1, xmm1
  vmulsd xmm0, xmm1, xmm0
  vsqrtsd xmm1, xmm2, xmm2
  vsqrtsd xmm2, xmm3, xmm3
  vmulsd xmm1, xmm1, xmm2
  vmulsd xmm0, xmm0, xmm1

GCC (trunk) with '--std=c++17 -O3 -march=native -ffast-math' flags generates
more optimal code:

f(double, double, double, double):
        vmulsd  xmm0, xmm0, xmm1
        vmulsd  xmm2, xmm2, xmm3
        vmulsd  xmm2, xmm2, xmm0
        vsqrtsd xmm0, xmm0, xmm2

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/20171210/a3d2304b/attachment.html>

More information about the llvm-bugs mailing list