Issue 52950
Summary LoadStoreVectorizer assumes non-willreturn calls return
Labels new issue
Assignees
Reporter nunoplopes
    Test: Transforms/LoadStoreVectorizer/int_sideeffect.ll

The transformation below is incorrect if `%p` points to just 12-bytes of dereferenceable memory and `@foo` exits.

```
define void @test_inaccessiblememonly(* %p) {
  %p0 = gep * %p, 4 x i64 0
  %p1 = gep * %p, 4 x i64 1
  %p2 = gep * %p, 4 x i64 2
  %p3 = gep * %p, 4 x i64 3
  %l0 = load float, * %p0, align 16
  %l1 = load float, * %p1, align 4
  %l2 = load float, * %p2, align 4
  call void @foo() inaccessiblememonly
  %l3 = load float, * %p3, align 4
  store float %l0, * %p0, align 16
  call void @foo() inaccessiblememonly
  store float %l1, * %p1, align 4
  store float %l2, * %p2, align 4
  store float %l3, * %p3, align 4
  ret void
}
=>
define void @test_inaccessiblememonly(* %p) {
  %p0 = gep * %p, 4 x i64 0
  %1 = bitcast * %p0 to *
  %2 = load <4 x float>, * %1, align 16
  %l01 = extractelement <4 x float> %2, i32 0
  %l12 = extractelement <4 x float> %2, i32 1
  %l23 = extractelement <4 x float> %2, i32 2
  %l34 = extractelement <4 x float> %2, i32 3
  call void @foo() inaccessiblememonly
  call void @foo() inaccessiblememonly
  %3 = insertelement <4 x float> poison, float %l01, i32 0
  %4 = insertelement <4 x float> %3, float %l12, i32 1
  %5 = insertelement <4 x float> %4, float %l23, i32 2
  %6 = insertelement <4 x float> %5, float %l34, i32 3
  %7 = bitcast * %p0 to *
  store <4 x float> %6, * %7, align 16
  ret void
}
Transformation doesn't verify!
ERROR: Source is more defined than target

Example:
* %p = pointer(non-local, block_id=1, offset=0)

Source:
* %p0 = pointer(non-local, block_id=1, offset=0)
* %p1 = pointer(non-local, block_id=1, offset=4)
* %p2 = pointer(non-local, block_id=1, offset=8)
* %p3 = pointer(non-local, block_id=1, offset=12)
float %l0 = poison
float %l1 = poison
float %l2 = poison
void = UB triggered!

SOURCE MEMORY STATE
===================
NON-LOCAL BLOCKS:
Block 0 >       size: 0 align: 1        alloc type: 0
Block 1 >       size: 12        align: 32   alloc type: 0
Block 2 >       align: 4        alloc type: 0

Target:
* %p0 = pointer(non-local, block_id=1, offset=0)
* %1 = pointer(non-local, block_id=1, offset=0)
<4 x float> %2 = UB triggered!
```

cc @nikic
https://github.com/llvm/llvm-project/commit/9d720dcb89e8da4d12aa1832d74614adc6aa2c82
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to