[llvm] [InstCombine] Canonicalize more saturated-add variants (PR #100008)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 29 13:56:57 PDT 2024


topperc wrote:

Your alive proof has

```
define dso_local i8 @src3(i8 %x, i8  %c) {
entry:
  %noZero = icmp ne i8 %c, 0
  call void @llvm.assume(i1 %noZero)
  %add = add nuw i8 %x, %c
  %c.not = xor i8 %c, -1
  %d = add i8 %c.not, 1
  %cmp.not = icmp ugt i8 %x, %d
  %cond = select i1 %cmp.not, i8 -1, i8 %add
  ret i8 %cond
}
```

The `nuw` flag there says that the add never overflows and thus never saturates. The transform fails without the nuw. There's no check for the nuw in your transform.

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


More information about the llvm-commits mailing list