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

[InstCombine] GEPNoWrapFlags is propagated incorrectly #121459

Closed
dtcxzyw opened this issue Jan 2, 2025 · 0 comments · Fixed by #121572
Closed

[InstCombine] GEPNoWrapFlags is propagated incorrectly #121459

dtcxzyw opened this issue Jan 2, 2025 · 0 comments · Fixed by #121572

Comments

@dtcxzyw
Copy link
Member

dtcxzyw commented Jan 2, 2025

Alive2: https://alive2.llvm.org/ce/z/3ME7S7

define ptr @src(i1 %c, ptr %p) {
  br i1 %c, label %if, label %else

if:
  %gep1 = getelementptr inbounds i32, ptr %p, i64 1
  br label %join

else:
  %gep2 = getelementptr i64, ptr %p, i64 2
  br label %join

join:
  %phi = phi ptr [ %gep1, %if ], [ %gep2, %else ]
  %gep = getelementptr i32, ptr %phi, i64 1
  ret ptr %gep
}

----------------------------------------
define ptr @src(i1 %c, ptr %p) {
#0:
  br i1 %c, label %if, label %else

else:
  %gep2 = gep ptr %p, 8 x i64 2
  br label %join

if:
  %gep1 = gep inbounds ptr %p, 4 x i64 1
  br label %join

join:
  %phi = phi ptr [ %gep1, %if ], [ %gep2, %else ]
  %gep = gep ptr %phi, 4 x i64 1
  ret ptr %gep
}
=>
define ptr @src(i1 %c, ptr %p) {
#0:
  br i1 %c, label %if, label %else

else:
  br label %join

if:
  br label %join

join:
  %#1 = phi i64 [ 4, %if ], [ 16, %else ]
  %#2 = gep inbounds nuw ptr %p, 1 x i64 %#1
  %gep = gep ptr %#2, 1 x i64 4
  ret ptr %gep
}
Transformation doesn't verify!

ERROR: Target is more poisonous than source

Example:
i1 %c = #x0 (0)
ptr %p = null

Source:
  >> Jump to %else
ptr %gep2 = pointer(non-local, block_id=0, offset=16) / Address=#x0000000000000010
  >> Jump to %join
ptr %phi = pointer(non-local, block_id=0, offset=16) / Address=#x0000000000000010
ptr %gep = pointer(non-local, block_id=0, offset=20) / Address=#x0000000000000014

SOURCE MEMORY STATE
===================
NON-LOCAL BLOCKS:
Block 0 >	size: 0	align: 1	alloc type: 0	alive: false	address: 0
Block 1 >	size: 0	align: 1	alloc type: 0	alive: true	address: 1

Target:
  >> Jump to %else
  >> Jump to %join
i64 %#1 = #x0000000000000010 (16)
ptr %#2 = poison
ptr %gep = poison
Source value: pointer(non-local, block_id=0, offset=20) / Address=#x0000000000000014
Target value: poison

Summary:
  0 correct transformations
  1 incorrect transformations
  0 failed-to-prove transformations
  0 Alive2 errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant