Issue 239213
Summary [SelectionDAG] `llvm.frexp` with `<4 x i64>` exponent vector asserts in `SetSplitVector` during type legalization
Labels new issue
Assignees
Reporter lin334141-cell
    # [SelectionDAG] `llvm.frexp` with `<4 x i64>` exponent vector asserts in `SetSplitVector` during type legalization

## Summary

During SelectionDAG type legalization on AArch64 (where `<4 x i64>` is an illegal vector type that requires splitting), lowering `llvm.frexp.v4f32.v4i64` crashes with an assertion failure in `DAGTypeLegalizer::SetSplitVector`:

```text
Assertion failed: (Lo.getValueType().getVectorElementType() == Op.getValueType().getVectorElementType() && Lo.getValueType().getVectorElementCount() * 2 == Op.getValueType().getVectorElementCount() && Hi.getValueType() == Lo.getValueType() && "Invalid type for split vector"), function SetSplitVector, file LegalizeTypes.cpp, line 835.
```

The crash occurs in `DAGTypeLegalizer::SplitVecRes_UnaryOpWithTwoResults` (`llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp`). Because `ISD::FFREXP` produces heterogeneous result types (floating-point fraction and integer exponent), the second result's split registration violates the type invariants expected by `SetSplitVector`.

## Minimal Reproducer

```llvm
; v4.ll
target triple = "arm64-apple-macos"

declare { <4 x float>, <4 x i64> } @llvm.frexp.v4f32.v4i64(<4 x float>)

define <4 x i64> @test_split_frexp(<4 x float> %x) {
  %r = call { <4 x float>, <4 x i64> } @llvm.frexp.v4f32.v4i64(<4 x float> %x)
  %e = extractvalue { <4 x float>, <4 x i64> } %r, 1
  ret <4 x i64> %e
}
```

Run instruction selection directly:
```bash
llc -O2 v4.ll -o /dev/null
```

### Actual Behavior (`llc` aborts with exit code 134)

```text
Assertion failed: (Lo.getValueType().getVectorElementType() == Op.getValueType().getVectorElementType() && Lo.getValueType().getVectorElementCount() * 2 == Op.getValueType().getVectorElementCount() && Hi.getValueType() == Lo.getValueType() && "Invalid type for split vector"), function SetSplitVector, file LegalizeTypes.cpp, line 835.
PLEASE submit a bug report to [https://github.com/llvm/llvm-project/issues/](https://github.com/llvm/llvm-project/issues/) and include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0.  Program arguments: llc -O2 v4.ll -o /dev/null
1.  Running pass 'Function Pass Manager' on module 'v4.ll'
2.  Running pass 'AArch64 Instruction Selection' on function '@test_split_frexp'
```

### Expected Behavior
`llc` should succeed and legalize `<4 x i64>` by splitting it into two `<2 x i64>` vectors (which are legal on AArch64) alongside the `<4 x float>` fraction results.

## Root Cause

In `DAGTypeLegalizer::SplitVecRes_UnaryOpWithTwoResults` (`LegalizeVectorTypes.cpp`):
When splitting a node with two vector results, the legalizer splits the target result and registers the other result via `SetSplitVector`. For `FFREXP`, the two results have different element types (`float` vs. `i64`). When registering the partner result, the element types do not match, causing `Lo.getValueType().getVectorElementType() == Op.getValueType().getVectorElementType()` to fail.

Recent patches (#224127 / PR #225886 and PR #224173) touched the **widen** path (`WidenVectorResult`/`unrollExpandedOp`) for `i32` exponents, but the **split** path for heterogeneous multi-result ops like `FFREXP` with `i64` exponents remains unhandled.

## Suggested Fix Direction

In `SplitVecRes_UnaryOpWithTwoResults`:
Ensure the split derivation accounts for `ResNo` properly when querying types, so that `Lo` and `Hi` for each result are constructed using that result's own `EVT` rather than assuming homogeneous element types across both results.

## Tested Versions
- LLVM `main` at commit `ca566d552f7a9e507388cdba9539dd6e36c94bef` (`LegalizeVectorTypes.cpp:3014`)
- LLVM `24.0.0git` (`67005b724c917e1bdca50c82ecaa1b21a69244ed`, macOS arm64)

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to