Issue 241336
Summary [AArch64][GlobalISel] arm64_32: IRTranslator asserts on a vector-of-pointers argument
Labels new issue
Assignees
Reporter nodecoda
    ## Description

`-global-isel` on `arm64_32` aborts in IRTranslator for a function that takes a
vector of pointers. This happens during argument/return lowering, before any
legalization runs.

## Reproducer

```llvm
target datalayout = "e-p:32:32-i64:64-i128:128-n32:64-S128"
target triple = "arm64_32-apple-ios7.0"

define <4 x ptr> @g(<4 x ptr> %a) { ret <4 x ptr> %a }
```

```console
$ llc -mtriple=arm64_32-apple-ios7.0 -O0 -global-isel ptr4.ll -o /dev/null
llc: llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp:1395: ...:
     Assertion `DstOps[0].getLLTTy(*getMRI()).getSizeInBits() ==
 SrcOps[0].getLLTTy(*getMRI()).getSizeInBits() && "invalid bitcast"' failed.
```

`aarch64-apple-ios` (LP64) compiles the same IR fine, so this only shows up with
32-bit pointers.

## Analysis

The failure is in `CallLowering::mergeVectorRegsToResultRegs()`
(`llvm/lib/CodeGen/GlobalISel/CallLowering.cpp`). With `LLTy = <4 x p0>`
(4 x 32 = 128 bits) and the split part `PartLLT = <2 x i64>` (128 bits):

```cpp
if (LLTy.getScalarType() != PartLLT.getScalarType())
  for (size_t I = 0, E = SrcRegs.size(); I != E; ++I) {
    auto BitcastDst =
 MRI.getType(SrcRegs[I]).changeElementType(LLTy.getScalarType());
 ConcatRegs[I] = B.buildBitcast(BitcastDst, SrcRegs[I]).getReg(0);
 }
```

`changeElementType(p0)` applied to `<2 x i64>` gives `<2 x p0>`, which is 64 bits
rather than 128, so `buildBitcast` is handed a size-changing bitcast and asserts.

## Related

#233166 is the scalar form of the same gap on arm64_32 (`ret ptr @g`, mismatching
COPY sizes reported by the machine verifier, with silently wrong code in release
builds). It fails at a different point, so it is filed separately here.

Reported with AI assistance (Codex CLI); the reproduction and the analysis above
were verified by the reporter against `upstream/main` at `e291fcb507e1`.

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

Reply via email to