Skip to content

Missed Optimization: fold (arg1 + 4095 + arg0) u< 4096 (with nuw/nsw + same-sign) into a zero-sum test icmp ult (arg0 + arg1), 1 #166890

@Leo0506

Description

@Leo0506
define i1 @src(i64 %arg0, i64 %arg1) {
  %v0 = add nuw nsw i64 %arg1, 4095
  %v1 = add nuw nsw i64 %v0, %arg0
  %v2 = icmp samesign ult i64 %v1, 4096
  ret i1 %v2
}

define i1 @tgt(i64 %arg0, i64 %arg1) {
  %v0 = add nuw nsw i64 %arg0, %arg1
  %v1 = icmp ult i64 %v0, 1
  ret i1 %v1
}

alive2: https://alive2.llvm.org/ce/z/PNCxyX
godbolt: https://godbolt.org/z/eWvbejrG5
Pattern found in: https://github.com/dtcxzyw/llvm-opt-benchmark/blob/main/bench/linux/optimized/iov_iter.ll

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions