Skip to content

[InstCombine] Missed optimization: Fold (sext(a) & sext(c1)) == c2 to (a & c1) == c2 or 0 #85830

Closed
@XChy

Description

@XChy

Alive2 proof: https://alive2.llvm.org/ce/z/44YNAL (contains generalized pattern)

Motivating example

define i1 @src(i8 %a) {
entry:
  %conv = sext i8 %a to i32
  %0 = and i32 %conv, -2147483647
  %cmp = icmp eq i32 %0, 1
  ret i1 %cmp
}

can be folded to:

define i1 @tgt(i8 %a) {
entry:
  %and = and i8 %a, -127
  %cmp = icmp eq i8 %and, 1
  ret i1 %cmp
}

Real-world motivation

This snippet of IR is derived from abseil-cpp/float_conversion.cc@FloatToBuffer (after O3 pipeline).
The example above is a reduced version. If you're interested in the original suboptimal IR and optimal IR, email me please.

Let me know if you can confirm that it's an optimization opportunity, thanks.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions