[llvm-bugs] [Bug 35598] New: Missed optimization in math expression: sin^2(a) + cos^2(a) == 1

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Dec 10 05:46:14 PST 2017


            Bug ID: 35598
           Summary: Missed optimization in math expression: sin^2(a) +
                    cos^2(a) == 1
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            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

#include <cmath>

double test(double a)
    return cos(a) * cos(a) + sin(a) * sin(a);

generates this assembly:

test(double): # @test(double)
  sub rsp, 24
  lea rdi, [rsp + 16]
  lea rsi, [rsp + 8]
  call sincos
  vmovsd xmm1, qword ptr [rsp + 8] # xmm1 = mem[0],zero
  vmovsd xmm0, qword ptr [rsp + 16] # xmm0 = mem[0],zero
  vmulsd xmm0, xmm0, xmm0
  vfmadd231sd xmm0, xmm1, xmm1
  add rsp, 24

But there is formula: sin^2(a) + cos^2(a) == 1. 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/1ac52d85/attachment.html>

More information about the llvm-bugs mailing list