[llvm] [llvm] [InstCombine] fold "icmp eq (X + (V - 1)) & -V, X" to "icmp eq (and X, V - 1), 0" (PR #152851)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 13 13:00:25 PDT 2025


================
@@ -1320,6 +1320,35 @@ Instruction *InstCombinerImpl::foldICmpWithZero(ICmpInst &Cmp) {
   return nullptr;
 }
 
+/// Fold icmp eq (num + (val - 1)) & -val, num
+///      to
+///      icmp eq (and num, val - 1), 0
+/// For val being power of two
----------------
nikic wrote:

```suggestion
/// Fold icmp eq (num + mask) & ~mask, num
///      to
///      icmp eq (and num, mask), 0
/// Where mask is a low bit mask.
```
I think it would be clearer to match the implementation here.

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


More information about the llvm-commits mailing list