llvm / llvm/llvm-project

[TargetLibraryInfo] x86 libmvec table missing glibc-2.35 vector functions (erf, tan, tanh, exp2, log2, …)

Open
#206,273 3 comments 0 reactions 1 assignee Claimed by @anun333 View on GitHub
llvm:analysis
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

## Summary

`TLI_DEFINE_LIBMVEC_X86_VECFUNCS` in `llvm/include/llvm/Analysis/VecFuncs.def` only maps the original glibc-2.22 libmvec set (`exp`, `log`, `sin`, `cos`, `pow`). glibc 2.35 (2022) significantly expanded the x86_64 libmvec with ~19 additional vector math functions, but LLVM's x86 table was never updated. As a result, `clang -fveclib=libmvec` on x86_64 silently falls back to scalar for loops over these functions, even though vectorized implementations are present in the linked `libmvec.so`.

This is also an x86-vs-AArch64 parity gap (the AArch64 libmvec table already maps `erf`/`erfc`) and a clang-vs-gcc gap (gcc already emits these via its own libmvec path).

## Missing functions

Present in glibc ≥ 2.35 x86_64 libmvec, unmapped in LLVM's `LIBMVEC_X86` table (single + double):

`erf, erfc, tan, tanh, sinh, cosh, asin, acos, atan, asinh, acosh, atanh, cbrt, exp2, exp10, expm1, log2, log10, log1p`

## Evidence

`nm -D libmvec.so` (glibc 2.35, x86_64), e.g. for `erf`/`erff` — all `@@GLIBC_2.35`:

```
_ZGVbN2v_erf _ZGVbN4v_erff _ZGVcN4v_erf _ZGVcN8v_erff _ZGVdN4v_erf _ZGVdN8v_erff _ZGVeN16v_erff _ZGVeN8v_erf
```

These follow the exact mangling/width convention of the already-mapped `expf` entries (`_ZGVbN4v_expf`, `_ZGVdN8v_expf`), so the additions are mechanical.

Minimal repro — stays scalar today with `clang -O3 -ffast-math -fno-math-errno -fveclib=libmvec -march=native`:

```c
#include
void f(float *o, const float *x, int n){ for (int i = 0; i < n; i++) o[i] = erff(x[i]); }
```

(`gcc -O3 -ffast-math -march=native` vectorizes the same loop via `_ZGVeN16v_erff`.)

## Proposed fix

Extend `TLI_DEFINE_LIBMVEC_X86_VECFUNCS` in `VecFuncs.def` with the glibc-2.35 entries (mirroring the existing `expf` lines and the AArch64 `erf` entries), plus matching coverage in `llvm/test/Transforms/LoopVectorize/X86/libmvec-calls*.ll`. Happy to put up the PR.

## Environment

glibc 2.35 (Ubuntu), x86_64; symbols verified on AVX-512 (Xeon W-2235) and AVX2 (Zen) hosts.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.