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] Missing optimization for div_euclid(2) #73622

Closed
nikic opened this issue Nov 28, 2023 · 0 comments · Fixed by #73706
Closed

[InstCombine] Missing optimization for div_euclid(2) #73622

nikic opened this issue Nov 28, 2023 · 0 comments · Fixed by #73706

Comments

@nikic
Copy link
Contributor

nikic commented Nov 28, 2023

From rust-lang/rust#118392, we're missing this transform: https://alive2.llvm.org/ce/z/8-eUdb

define i8 @src(i8 %a) {
  %q.i = sdiv i8 %a, 2
  %1 = and i8 %a, -127
  %_8.i = icmp eq i8 %1, -127
  %2 = sext i1 %_8.i to i8
  %_0.0.i = add nsw i8 %q.i, %2
  ret i8 %_0.0.i
}

define i8 @tgt(i8 %a) {
  %_0 = ashr i8 %a, 1
  ret i8 %_0
}

Worth noting that this already works for other power of two constants, such as div_euclid(4), so we probably already have a transform for this, but additional canonicalizations for 2 in particular get in the way.

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.

2 participants