| Issue |
234556
|
| Summary |
[InstCombine] Store of an aggregate built from a vector with non-byte-sized elements is rewritten as a bit-packed vector store
|
| Labels |
miscompilation,
llvm:instcombine,
generated by fuzzer
|
| Assignees |
|
| Reporter |
ChoKyuWon
|
### reproducer
godbolt: https://godbolt.org/z/oK7MMqPYo
alive: https://alive2.llvm.org/ce/z/u4xbfX
```llvm
define i32 @f(<2 x i31> %v) {
%e0 = extractelement <2 x i31> %v, i64 0
%e1 = extractelement <2 x i31> %v, i64 1
%a0 = insertvalue [2 x i31] poison, i31 %e0, 0
%a1 = insertvalue [2 x i31] %a0, i31 %e1, 1
%p = alloca [2 x i31], align 8
store [2 x i31] %a1, ptr %p, align 8
%q = getelementptr i8, ptr %p, i64 4
%r = load i31, ptr %q, align 4
%z = zext i31 %r to i32
ret i32 %z
}
define i32 @main() {
%r = call i32 @f(<2 x i31> <i31 3, i31 3>)
ret i32 %r
}
```
```console
$ opt -S -passes=instcombine repro.ll
define i32 @f(<2 x i31> %v) {
%p = alloca [2 x i31], align 8
store <2 x i31> %v, ptr %p, align 8
%q = getelementptr inbounds nuw i8, ptr %p, i64 4
%r = load i31, ptr %q, align 4
%z = zext i31 %r to i32
ret i32 %z
}
...
$ llubi repro.ll; echo $?
3
$ opt -S -passes=instcombine repro.ll | llubi -; echo $?
1
$ alive-tv --disable-undef-input --disable-poison-input -passes=instcombine repro.ll
...
Transformation doesn't verify!
ERROR: Target is more poisonous than source
Example:
<2 x i31> %v = < #x00000003 (3), #x00000003 (3) >
...
Source value: #x00000003 (3)
Target value: poison
```
### suggested fix
`combineStoreToValueType` stores `U` directly when `likeBitCastFromVector` matches an `insertvalue` chain of `extractelement U, k`, but the only layout check there is equal `getTypeStoreSizeInBits`.
`[2 x i31]` puts element 1 at byte 4 (alloc-size stride) while `<2 x i31>` is bit-packed (lane 1 at bit 31), and both have a store size of 8 bytes.
Also require the element type to have no padding (`DL.getTypeSizeInBits(EltTy) == DL.getTypeAllocSizeInBits(EltTy)`), so the lane stride matches the element stride.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs