Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LoadStoreVectorizer assumes non-willreturn calls return #52950

Closed
nunoplopes opened this issue Jan 1, 2022 · 0 comments
Closed

LoadStoreVectorizer assumes non-willreturn calls return #52950

nunoplopes opened this issue Jan 1, 2022 · 0 comments

Comments

@nunoplopes
Copy link
Member

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
9d720dc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants