[all-commits] [llvm/llvm-project] 4103c4: [InstCombine] Fold comparisons of llvm.usub.sat re...

Haram Jeong via All-commits all-commits at lists.llvm.org
Wed Sep 30 08:15:14 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 4103c42711877449d20e10766b1976f753a719d7
      https://github.com/llvm/llvm-project/commit/4103c42711877449d20e10766b1976f753a719d7
  Author: Haram Jeong <91401364+haramj at users.noreply.github.com>
  Date:   2026-09-30 (Wed, 30 Sep 2026)

  Changed paths:
    M llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
    M llvm/test/Transforms/InstCombine/icmp-usub-sat.ll

  Log Message:
  -----------
  [InstCombine] Fold comparisons of llvm.usub.sat result with its LHS (#214108)

Fold comparisons between the result of `llvm.usub.sat(X, C)` and the
original
left-hand side when `C` is a nonzero constant.

For `C != 0`:

```llvm
    %sat = call iN @llvm.usub.sat.iN(iN %x, iN C)
    %cmp = icmp eq iN %sat, %x
```

can be folded to:

```llvm
    %cmp = icmp eq iN %x, 0
```

Similarly:

```llvm
    %sat = call iN @llvm.usub.sat.iN(iN %x, iN C)
    %cmp = icmp ult iN %sat, %x
```

can be folded to:

```llvm
    %cmp = icmp ne iN %x, 0
```

This also handles the commuted equality form:

```llvm
    icmp eq iN %x, %sat
```

The fold does not require the intrinsic to have one use, so if the
`usub.sat`
result is used elsewhere, only the comparison is canonicalized and the
intrinsic remains live.

Proofs: https://alive2.llvm.org/ce/z/ZmAzBE

Fixes #213832



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list