| Issue |
235695
|
| Summary |
[CodeGen] llc crashes "Cannot unroll scalable vector!" on llvm.ldexp / llvm.frexp with scalable vector operands
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
leidian977
|
`llc` aborts with `LLVM ERROR: Cannot unroll scalable vector!` when lowering
`llvm.ldexp` or `llvm.frexp` on scalable vector types, unless the function
carries a `vscale_range` attribute. This is independent of any vector library
(the crash reproduces with and without `--vector-library`) and is not
RISCV-specific in origin.
PR #218634 added a scalarization fallback in `PreISelIntrinsicLowering` for
multi-result scalable intrinsics (`sincos`, `sincospi`, `modf`) and stated
"support for `frexp` which returns a multi-type struct will follow separately"
— that follow-up never landed, and `llvm.ldexp` (single-result, but similarly
only expandable through unrolling) was never covered either.
### Reproduction
```llvm
; ldexp_scalable_crash.ll
declare <vscale x 4 x float> @llvm.ldexp.nxv4f32.v4i32(<vscale x 4 x float>, <vscale x 4 x i32>)
define <vscale x 4 x float> @f(<vscale x 4 x float> %x, <vscale x 4 x i32> %n) {
%r = call <vscale x 4 x float> @llvm.ldexp.nxv4f32.v4i32(<vscale x 4 x float> %x, <vscale x 4 x i32> %n)
ret <vscale x 4 x float> %r
}
```
```
$ llc -mtriple=riscv64 -mattr=+v ldexp_scalable_crash.ll
LLVM ERROR: Cannot unroll scalable vector!
```
```llvm
; frexp_scalable_crash.ll
declare { <vscale x 2 x double>, <vscale x 2 x i32> } @llvm.frexp.nxv2f64(<vscale x 2 x double>)
define { <vscale x 2 x double>, <vscale x 2 x i32> } @f(<vscale x 2 x double> %x) {
%r = call { <vscale x 2 x double>, <vscale x 2 x i32> } @llvm.frexp.nxv2f64(<vscale x 2 x double> %x)
ret { <vscale x 2 x double>, <vscale x 2 x i32> } %r
}
```
```
$ llc -mtriple=riscv64 -mattr=+v frexp_scalable_crash.ll
LLVM ERROR: Cannot unroll scalable vector!
```
Both crash identically with and without `--vector-library=sleefgnuabi`.
With a `vscale_range` attribute (e.g. `vscale_range(4,16)`) the same inputs
compile, but degrade to per-element scalar `ldexpf`/`frexp` calls — so this is
a code-quality cliff, not just a crash: the fallback used for other scalable
math intrinsics (`PreISelIntrinsicLowering` → `lowerUnaryVectorIntrinsicAsLoop`
/ the #218634 scalarizer) is missing for these two.
### Additional observation (same area)
Even where a correct SLEEF symbol exists, the vector-libcall dispatch in
`LegalizeVectorOps.cpp` (`tryExpandVecMathCall` and the `FSINCOS`/`FSINCOSPI`/
`FMODF` cases) has no cases for `ISD::FLDEXP`/`ISD::FFREXP`, so a properly
named entry like `Sleef_ldexpdx_rvvm2` is never selected by SelectionDAG; the
veclib mapping for ldexp is only reachable through the loop vectorizer, and
the intrinsic path cannot use it at all.
### Related but distinct
- #218634 — added the fallback for sincos/sincospi/modf; explicitly deferred
frexp.
- #216985 — implemented unrolling of scalable vectors under `vscale_range`;
orthogonal (explains why the crash disappears with the attribute).
- #231800 / #230893 — X86 requests to optimize vector ldexp/frexp instead of
scalarizing; neither reports this crash.
Tested on trunk (`cc2acc33a5b2`). Found and written up with AI assistance
(Claude).
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs