Skip to content

[InstCombine] Missing and of icmp fold #63749

Closed
@nikic

Description

@nikic

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions