llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Calls to sin() don't get converted to sinf, leading to inefficient use of vector variants with -fveclib=ArmPL

Open willlovett-arm opened this issue 1 year ago • 4 comments

https://godbolt.org/z/fE16nGPxP

#include <math.h>

void foo(float *p)
{
for (int x=0; x<999; ++x) {
    p[x] = sin(p[x]);
  }
}

generates calls to armpl_vsinq_f64 instead of armpl_vsinq_f32.

If we replace that code with sinf it works fine:

#include <math.h>

void foo(float *p)
{
for (int x=0; x<999; ++x) {
    p[x] = sinf(p[x]);
  }
}

I'm reasonably sure it's legitimate to implicitly switch to sinf(), and this would lead to double the vector throughput.

willlovett-arm avatar May 08 '25 08:05 willlovett-arm

@llvm/issue-subscribers-backend-aarch64

Author: Will Lovett (willlovett-arm)

https://godbolt.org/z/fE16nGPxP
#include &lt;math.h&gt;

void foo(float *p)
{
for (int x=0; x&lt;999; ++x) {
    p[x] = sin(p[x]);
  }
}

generates calls to armpl_vsinq_f64 instead of armpl_vsinq_f32.

If we replace that code with sinf it works fine:

#include &lt;math.h&gt;

void foo(float *p)
{
for (int x=0; x&lt;999; ++x) {
    p[x] = sinf(p[x]);
  }
}

I'm reasonably sure it's legitimate to implicitly switch to sinf(), and this would lead to double the vector throughput.

llvmbot avatar May 08 '25 08:05 llvmbot

We do this if the function is a @sin, but not for @llvm.sin intrinsics. https://godbolt.org/z/MTKefx5Yr

davemgreen avatar May 08 '25 09:05 davemgreen

Should be fixed by https://github.com/llvm/llvm-project/pull/139082

fhahn avatar May 09 '25 09:05 fhahn

Amazing turnaround! Thanks @guy-david , all 🙏

willlovett-arm avatar May 09 '25 15:05 willlovett-arm