Skip to content

[InstCombine] Missed fold: umax(x *nuw 2, x + 1) => x == 0 ? 1 : x *nuw 2 #122388

@Kmeakin

Description

@Kmeakin

https://godbolt.org/z/TEzxx8vbj

#[inline(never)]
pub unsafe fn src(x: usize) -> usize {
    std::cmp::max(x.unchecked_mul(2), x + 1)
}

#[inline(never)]
pub unsafe fn tgt(x: usize) -> usize {
    match x {
        0 => 1,
        _ => x.unchecked_mul(2),
    }
}

https://alive2.llvm.org/ce/z/ijq6ZJ

define noundef i64 @src(i64 noundef %x) {
  %x2 = shl nuw i64 %x, 1
  %x1 = add i64 %x, 1
  %max = tail call noundef i64 @llvm.umax.i64(i64 %x2, i64 %x1)
  ret i64 %max
}

define noundef range(i64 1, 0) i64 @tgt(i64 noundef %x) {
  %eq = icmp eq i64 %x, 0
  %x2 = shl nuw i64 %x, 1
  %max = select i1 %eq, i64 1, i64 %x2
  ret i64 %max
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions