llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.37k stars 11.72k forks source link

optimize `exp(exp(x)) / exp(x)` with fast-math #65608

Open k-arrows opened 1 year ago

k-arrows commented 1 year ago

Consider the following two functions:

#include <cmath>

double f1(double x)
{
    return exp(exp(x)) / exp(x);
}

double f2(double x)
{
    return exp(exp(x) - x);
}

When these functions are compiled with -Ofast, Clang emits code for f1 that performs floating-point division. GCC does not emit code that performs floating-point division for either function.

zjaffal commented 1 year ago

taking a look