[VectorCombine] miscompilation introduces poisonous return
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Vector-combine incorrectly transforms the following code snippet
```llvm
define i32 @foo(i32 %0) {
%2 = add i32 %0, 1
%4 = insertelement <2 x i32> zeroinitializer, i32 %2, i64 0
%5 = add nuw <2 x i32> %4, zeroinitializer
ret i32 %2
}
define i32 @main() {
%1 = call i32 @foo(i32 -1)
ret i32 %1
}
```
if ran through `opt -passes=vector-combine` it produces the following code
```llvm
define i32 @foo(i32 %0) {
%.scalar = add nuw i32 %0, 1
ret i32 %.scalar
}
define i32 @main() {
%1 = call i32 @foo(i32 -1)
ret i32 %1
}
```
Which now returns a poison value created by the `add nuw` instruction where it previously did not.
Alive: https://alive2.llvm.org/ce/z/5_CwJp
Most recent tested commit: [10536d4](https://github.com/llvm/llvm-project/commit/10536d48b700e82101d9c8f4a0a87c999b6f9251)
Git bisected the first bad commit as: [777d6b5](https://github.com/llvm/llvm-project/commit/777d6b5de90b7e0d1ceaa1424c6da4590539c007)
Edit: Note this has been found by a Fuzzer.
Contributor guide
Assessment
This issue has not been assessed yet.