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] range attribute should be dropped in foldBitCeil #112076

Closed
dtcxzyw opened this issue Oct 12, 2024 · 0 comments · Fixed by #116641
Closed

[InstCombine] range attribute should be dropped in foldBitCeil #112076

dtcxzyw opened this issue Oct 12, 2024 · 0 comments · Fixed by #116641

Comments

@dtcxzyw
Copy link
Member

dtcxzyw commented Oct 12, 2024

Reproducer: https://alive2.llvm.org/ce/z/NQTmkh (Please use latest alive2 with AliveToolkit/alive2#1097)

define i32 @src(i32 %x) {
  %ctlz = call range(i32 1, 33) i32 @llvm.ctlz.i32(i32 %x, i1 false)
  %sub = sub i32 32, %ctlz
  %shl = shl i32 1, %sub
  %dec = add i32 %x, -1
  %ult = icmp ult i32 %dec, -2
  %sel = select i1 %ult, i32 %shl, i32 1
  ret i32 %sel
}

define i32 @tgt(i32 %x) {
  %ctlz = call range(i32 1, 33) i32 @llvm.ctlz.i32(i32 %x, i1 false)
  %1 = sub nsw i32 0, %ctlz
  %2 = and i32 %1, 31
  %sel = shl nuw i32 1, %2
  ret i32 %sel
}
----------------------------------------
define i32 @src(i32 %x) {
#0:
  %ctlz = ctlz i32 %x, 0
  %#range_0_%ctlz = !range i32 %ctlz, i32 1, i32 33
  %sub = sub i32 32, %#range_0_%ctlz
  %shl = shl i32 1, %sub
  %dec = add i32 %x, 4294967295
  %ult = icmp ult i32 %dec, 4294967294
  %sel = select i1 %ult, i32 %shl, i32 1
  ret i32 %sel
}
=>
define i32 @tgt(i32 %x) {
#0:
  %ctlz = ctlz i32 %x, 0
  %#range_0_%ctlz = !range i32 %ctlz, i32 1, i32 33
  %#1 = sub nsw i32 0, %#range_0_%ctlz
  %#2 = and i32 %#1, 31
  %sel = shl nuw i32 1, %#2
  ret i32 %sel
}
Transformation doesn't verify!

ERROR: Target is more poisonous than source

Example:
i32 %x = #xffffffff (4294967295, -1)

Source:
i32 %ctlz = #x00000000 (0)
i32 %#range_0_%ctlz = poison
i32 %sub = poison
i32 %shl = poison
i32 %dec = #xfffffffe (4294967294, -2)
i1 %ult = #x0 (0)
i32 %sel = #x00000001 (1)

Target:
i32 %ctlz = #x00000000 (0)
i32 %#range_0_%ctlz = poison
i32 %#1 = poison
i32 %#2 = poison
i32 %sel = poison
Source value: #x00000001 (1)
Target value: poison
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