Skip to content

Missed optimization in math expression: simplify calls std::exp functions #34942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
zamazan4ik opened this issue Dec 10, 2017 · 5 comments
Closed
Labels
bugzilla Issues migrated from bugzilla

Comments

@zamazan4ik
Copy link

zamazan4ik commented Dec 10, 2017

Bugzilla Link 35594
Resolution FIXED
Resolved on Jan 30, 2019 22:35
Version trunk
OS Linux
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 f(double a, double b)
{
    return std::exp(a) * std::exp(b);
}

generates this assembly:

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

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

f(double, double):
        vaddsd  xmm0, xmm0, xmm1
        jmp     __exp_finite
@hfinkel
Copy link
Collaborator

hfinkel commented Dec 10, 2017

This could also be in InstCombine.

@zamazan4ik
Copy link
Author

@llvmbot
Copy link
Member

llvmbot commented Jan 21, 2019

@llvmbot
Copy link
Member

llvmbot commented Jan 31, 2019

Commits: rL352613, rL352730

@RKSimon
Copy link
Collaborator

RKSimon commented Nov 27, 2021

mentioned in issue #34959

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla
Projects
None yet
Development

No branches or pull requests

4 participants