[llvm] [ValueTracking] Fold max/min when incrementing/decrementing by 1 (PR #142466)
Alex MacLean via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 3 07:56:59 PDT 2025
AlexMaclean wrote:
> 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.
Thanks! I've fixed this case by ensuring that we now drop the no-wrap flag which doesn't correspond to the sign of the min/max. I've added tests to confirm as well.
https://github.com/llvm/llvm-project/pull/142466
More information about the llvm-commits
mailing list