[llvm] [ValueTracking] Fold max/min when incrementing/decrementing by 1 (PR #142466)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 2 21:26:13 PDT 2025


https://github.com/dtcxzyw requested changes to this pull request.

Miscompilation reproducer: https://alive2.llvm.org/ce/z/nxGw_V
```
define i8 @src(i8 %x, i8 %w) {
  %cmp = icmp ugt i8 %x, %w
  %add = add nsw nuw i8 %w, 1
  %r = select i1 %cmp, i8 %x, i8 %add
  ret i8 %r
}

define i8 @tgt(i8 %x, i8 %w) {
  %add = add nsw nuw i8 %w, 1
  %r = call i8 @llvm.umax(i8 %x, i8 %add)
  ret i8 %r
}
```

We need to drop nsw/nuw flags in this case.


https://github.com/llvm/llvm-project/pull/142466


More information about the llvm-commits mailing list