[clang] [llvm] [InstCombine] Combine llvm.sin/llvm.cos libcall pairs into llvm.sincos (PR #184760)

Kito Cheng via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 27 19:47:34 PDT 2026


kito-cheng wrote:

@Andarwinux 

> Will this affect vector sin+cos? Currently sincos vectorization almost doesn't work, and I'm concerned if InstCombine combined sin and cos before vectorization, the workaround of using sin+cos won't work either.

Yes, it will affect vector sin+cos, I tried to AArch64 w/ sleef, it can vectorize with sincos, the following step is what I tried:


sincos.c
```
#include <math.h>

void foo(float *restrict s, float *restrict c, float *restrict x, int n) {
  for (int i = 0; i < n; ++i) {
    s[i] = sinf(x[i]);
    c[i] = cosf(x[i]);
  }
}

```

```
# Neon
$ clang --target=aarch64-linux-gnu -O3 -fno-math-errno -fveclib=SLEEF -mcpu=cortex-a76 -S -o -  /tmp/sincos-vec/loop-sincos-aa.c
...
        bl      _ZGVnN4vl4l4_sincosf
        ldr     q0, [sp]                        // 16-byte Reload
        mov     x0, x20
        mov     x1, x19
        bl      _ZGVnN4vl4l4_sincosf
...
# SVE
$ clang --target=aarch64-linux-gnu -O3 -fno-math-errno -fveclib=SLEEF -march=armv9-a+sve2 -S -o -  /tmp/sincos-vec/loop-sincos-aa.c
...
        bl      _ZGVsNxvl4l4_sincosf
        incb    x22
        incb    x23
        mov     z0.d, z16.d
        mov     x0, x22
        mov     x1, x23
        bl      _ZGVsNxvl4l4_sincosf
...
```

https://github.com/llvm/llvm-project/pull/184760


More information about the cfe-commits mailing list