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 and of icmp fold #63749

Closed
nikic opened this issue Jul 7, 2023 · 0 comments
Closed

[InstCombine] Missing and of icmp fold #63749

nikic opened this issue Jul 7, 2023 · 0 comments

Comments

@nikic
Copy link
Contributor

nikic commented Jul 7, 2023

Missing this fold: https://alive2.llvm.org/ce/z/5Hlb2C

define i1 @src(i8 %x, i8 %y) {
  %add = add i8 %x, 1
  %c1 = icmp ne i8 %x, -1
  %c2 = icmp ule i8 %add, %y
  %and = and i1 %c1, %c2
  ret i1 %and
}

define i1 @tgt(i8 %x, i8 %y) {
  %c = icmp ult i8 %x, %y
  ret i1 %c
}

This can also be seen as a two-step fold with the intermediate step:

define i1 @tgt(i8 %x, i8 %y) {
  %add = add i8 %x, 1
  %c1 = icmp ne i8 %x, -1
  %c2 = icmp ult i8 %x, %y
  %and = and i1 %c1, %c2
  ret i1 %and
}

Where we can replace x + 1 <= y with x < y because we know x != -1 from the first and condition.

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