[llvm-bugs] [Bug 35597] New: Missed optimization in math expression: missing cube of the sum formula

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Dec 10 05:01:40 PST 2017


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

            Bug ID: 35597
           Summary: Missed optimization in math expression: missing cube
                    of the sum formula
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Common Code Generator Code
          Assignee: unassignedbugs 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
code:

double test(double a, double b)
{
    return a*a*a + 3.0*a*a*b + 3.0*a*b*b + b*b*b;
}


generates this assembly:

.LCPI0_0:
  .quad 4613937818241073152 # double 3
test(double, double): # @test(double, double)
  vmulsd xmm2, xmm0, qword ptr [rip + .LCPI0_0]
  vmulsd xmm3, xmm0, xmm0
  vmulsd xmm4, xmm1, xmm1
  vaddsd xmm5, xmm2, xmm1
  vmulsd xmm4, xmm4, xmm5
  vfmadd231sd xmm3, xmm2, xmm1
  vfmadd213sd xmm0, xmm3, xmm4
  ret


But there is formula: a*a*a + 3.0*a*a*b + 3.0*a*b*b + b*b*b == (a + b)^3. And
it can be compiled in faster way.

-- 
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/703b5ec7/attachment.html>


More information about the llvm-bugs mailing list