Issue 235314
Summary [GlobalISel] IRTranslator returns the destination when inserting a one-element vector into a one-element vector
Labels miscompilation, llvm:globalisel, generated by fuzzer
Assignees
Reporter ChoKyuWon
    ### reproducer
godbolt: https://godbolt.org/z/fdndcMnP6

```llvm
declare <1 x i32> @llvm.vector.insert.v1i32.v1i32(<1 x i32>, <1 x i32>, i64)

define <1 x i32> @insert(<1 x i32> %dst, <1 x i32> %src) {
  %result = call <1 x i32> @llvm.vector.insert.v1i32.v1i32(<1 x i32> %dst, <1 x i32> %src, i64 0)
  ret <1 x i32> %result
}

define i32 @main() {
  %result = call <1 x i32> @insert(<1 x i32> <i32 7>, <1 x i32> <i32 42>)
  %value = extractelement <1 x i32> %result, i64 0
  ret i32 %value
}
```

```console
# Local LLVM: 24.0.0git-40fd2805ed49, assertions enabled.
# Compiler Explorer trunk checked 2026-10-24: LLVM 24.0.0git, assertions enabled.
# CE irclang revision: 962b62d7a14e07660d26cf1f35630b2776d8e4f3 (clang-assertions-trunk-20261023).

$ opt -passes=verify -disable-output repro.ll
$ llubi repro.ll; echo $?
42

$ llc -O0 -mtriple=x86_64-unknown-linux-gnu -global-isel=0 repro.ll -o dag.s
$ clang dag.s -o dag
$ ./dag; echo $?
42

$ llc -O0 -mtriple=x86_64-unknown-linux-gnu -global-isel=1 repro.ll -o gisel.s
$ clang gisel.s -o gisel
$ ./gisel; echo $?
7

$ llc -O0 -mtriple=aarch64-unknown-linux-gnu repro.ll -o -
...
insert: // @insert
  .cfi_startproc
// %bb.0:
 ret
...
```

### suggested fix
`IRTranslatorImpl::translateInsertVector` in `llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp` uses `translateCopy(U, Vec, MIRBuilder)` when both vectors have one element.
Insertion at index 0 replaces the entire destination with operand 1, so this path should use `translateCopy(U, Elt, MIRBuilder)` instead.
Update the existing one-element insertion CHECKs in `llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-subvector.ll`, which currently copy operand 0, and add a test with distinct input values.

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

Reply via email to