[all-commits] [llvm/llvm-project] 2de38b: [InstCombine] Fold comparisons of urem with divide...

Hadong Lee via All-commits all-commits at lists.llvm.org
Wed Sep 9 08:48:51 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 2de38b4861ed4a7be7ddd42fc803e91d1fe81b14
      https://github.com/llvm/llvm-project/commit/2de38b4861ed4a7be7ddd42fc803e91d1fe81b14
  Author: Hadong Lee <hdchris765 at snu.ac.kr>
  Date:   2026-09-09 (Wed, 09 Sep 2026)

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

  Log Message:
  -----------
  [InstCombine] Fold comparisons of urem with dividend (#214933)

This folds equality comparisons of `X urem Y` with `X`

- `(X urem Y) == X` to `X ult Y`
- `(X urem Y) != X` to `X uge Y`

For a defined `urem`, let `Q = X udiv Y` and `R = X urem Y`. Unsigned
division gives `X = Q * Y + R`, so:
```
R == X  
<=> Q * Y == 0
<=> Q == 0 (since Y != 0)
<=> X < Y
```

Division by zero is undefined behavior, so no separate handling for `Y
== 0` is required.

This handles commuted compare operands, scalar and vector types, and
remainders with additional uses

Alive2: https://alive2.llvm.org/ce/z/3ryQaE
simplified proof with both folds: https://alive2.llvm.org/ce/z/v39F4d


Fixes #214480



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