Skip to content

Missed optimization in math expression: tan(a) * cos(a) == sin(a) #34950

@zamazan4ik

Description

@zamazan4ik
Bugzilla Link 35602
Version trunk
OS All
Blocks #34959
CC @hfinkel,@rotateright

Extended Description

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

#include <cmath>

double test(double a)
{
    return tan(a) * cos(a);
}

generates this assembly:

test(double): # @test(double)
  sub rsp, 24
  vmovsd qword ptr [rsp + 8], xmm0 # 8-byte Spill
  call tan
  vmovsd qword ptr [rsp + 16], xmm0 # 8-byte Spill
  vmovsd xmm0, qword ptr [rsp + 8] # 8-byte Reload
  call cos
  vmulsd xmm0, xmm0, qword ptr [rsp + 16] # 8-byte Folded Reload
  add rsp, 24
  ret

gcc(trunk) with '--std=c++17 -O3 -march=native -ffast-math' flags generates this:

test(double):
        jmp     sin

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions