Issue 235694
Summary [RISCV][veclib] -fveclib=SLEEF maps ilogbf/ldexpf loops to Sleef_ilogbfx_rvvm2 / Sleef_ldexpfx_rvvm2, which SLEEF never generates for any ISA
Labels new issue
Assignees
Reporter leidian977
    With `-vector-library=sleefgnuabi` on riscv64, LLVM maps the scalar libm
functions `ilogbf` and `ldexpf` to `Sleef_ilogbfx_rvvm2` and
`Sleef_ldexpfx_rvvm2`. These symbols do not exist: SLEEF only ever generates
the f64 forms `Sleef_ilogbdx_rvvm2` / `Sleef_ldexpdx_rvvm2` for the RVVM2
vector extension. Any vectorized loop containing `ilogbf` / `ldexpf` fails to
link.

Unlike the wrong-name entries already reported in #227119
(`Sleef_fmindx_u10rvvm2` etc., fixed by #231739 by renaming or removing the
row), these two rows have no possible rename — the f32 variants are not merely
misspelled, SLEEF does not provide f32 `ilogb`/`ldexp` vector functions at
all. PR #231739 keeps both rows unchanged and its updated test even CHECKs
`@Sleef_ilogbfx_rvvm2` / `@Sleef_ldexpfx_rvvm2`, so the bug will survive that
fix.

### Why the symbols don't exist

SLEEF's symbol headers are generated by `mkrename.c` from
`src/libm/funcproto.h`. `ldexp` (funcType 3) and `ilogb` (funcType 4) are
listed there, but in the single-precision (vfloat) generation loop the cases
for funcType 3/4 are commented out in the block starting with

```c
      /*
        case 3:
          printf("SLEEF_IMPORT SLEEF_CONST %s Sleef_%sf%d_%s(%s, vint2_%s);\n",
          ...
        case 4:
          printf("SLEEF_IMPORT SLEEF_CONST vint2_%s Sleef_%sf%d_%s(%s);\n",
          ...
      */
```

so no f32 `ilogb*`/`ldexp*` symbol is emitted for *any* ISA (SLEEF 3.9.0 and
current master). Running the real RVVM2 configuration from SLEEF's
`CMakeLists.txt`

```
mkrename finz_ x x vfloat64m2_t vfloat32m2_t vint32m1_t vint32m2_t __riscv_v rvvm2
```

produces `Sleef_ilogbdx_rvvm2` and `Sleef_ldexpdx_rvvm2`, but no
`Sleef_ilogbfx_rvvm2` / `Sleef_ldexpfx_rvvm2` (and no other f32 spelling
either).

The affected rows are in `llvm/include/llvm/Analysis/VecFuncs.def`:

```cpp
TLI_DEFINE_VECFUNC("ilogbf", "Sleef_ilogbfx_rvvm2", SCALABLE(4), NOMASK, "_ZGVrNxv")
TLI_DEFINE_VECFUNC("ldexpf", "Sleef_ldexpfx_rvvm2", SCALABLE(4), NOMASK, "_ZGVrNxvv")
```

and the corresponding `Sleef_ilogbfx_rvvm2` / `Sleef_ldexpfx_rvvm2` entries in
`SLEEFGNUABI_SCALABLE_VECFUNCS_RISCV` in `llvm/include/llvm/IR/RuntimeLibcalls.td`.

### Reproduction

```llvm
; ilogbf_loop.ll
define void @ilogbf_loop(ptr noalias %out, ptr noalias %in, i64 %n) {
entry:
  br label %loop
loop:
  %i = phi i64 [ 0, %entry ], [ %i.next, %loop ]
  %p = getelementptr float, ptr %in, i64 %i
  %v = load float, ptr %p
  %r = call i32 @ilogbf(float %v)
  %q = getelementptr i32, ptr %out, i64 %i
  store i32 %r, ptr %q
  %i.next = add i64 %i, 1
  %c = icmp ne i64 %i.next, %n
  br i1 %c, label %loop, label %exit
exit:
  ret void
}
declare i32 @ilogbf(float)
```

```
$ opt -passes='inject-tli-mappings,loop-vectorize' -vector-library=sleefgnuabi \
      -mtriple=riscv64 -mattr=+v ilogbf_loop.ll -S | grep Sleef
  %3 = call <vscale x 4 x i32> @Sleef_ilogbfx_rvvm2(<vscale x 4 x float> %wide.load)
```

Same for an `ldexpf` loop, which produces
`call <vscale x 4 x float> @Sleef_ldexpfx_rvvm2(...)`.

>From C this is reached with plain
`clang --target=riscv64-linux-gnu -march=rv64gcv -O3 -fveclib=SLEEF` on any
loop calling `ilogbf()` or `ldexpf()`, producing an undefined-symbol error at
link time.

### Suggested fix

Since no correct f32 symbol exists, the two `VecFuncs.def` rows and the two
`RuntimeLibcalls.td` entries should simply be removed, the same way #231739
removes the unfixable `sincos`/`sincospi`/`modf` rows. The f64 rows
(`Sleef_ilogbdx_rvvm2`, `Sleef_ldexpdx_rvvm2`) are fine and should stay. The
CHECK lines for `Sleef_ilogbfx_rvvm2`/`Sleef_ldexpfx_rvvm2` in
`llvm/test/Transforms/LoopVectorize/RISCV/veclib-function-calls.ll` (updated
by #231739) need to drop those symbols as well.

Tested on trunk (`cc2acc33a5b2`), verified against SLEEF 3.9.0 release source
and current master of `src/libm/mkrename.c`. Found and written up with AI
assistance (Claude).
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to