Skip to content

[InstCombine] a ? (a < 0) : 1 --> (a <= 0) #68227

@k-arrows

Description

@k-arrows
define i32 @src(i32 %0) {
%1:
  %2 = icmp eq i32 %0, 0
  %3 = lshr i32 %0, 31
  %4 = select i1 %2, i32 1, i32 %3
  ret i32 %4
}
=>
define i32 @tgt(i32 %0) {
%1:
  %2 = icmp slt i32 %0, 1
  %3 = zext i1 %2 to i32
  ret i32 %3
}
Transformation seems to be correct!

https://godbolt.org/z/evaE94d7o
https://alive2.llvm.org/ce/z/6ra3nj

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions