[llvm] [InstCombine] Fold comparisons of x & -x with 0 and 1 (PR #213709)

via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 4 00:16:11 PDT 2026


ParkHanbum wrote:

I found that this issue has more real-world occurrences. I downloaded the [[llvm-opt-benchmark-nightly](https://github.com/dtcxzyw/llvm-opt-benchmark-nightly)](https://github.com/dtcxzyw/llvm-opt-benchmark-nightly) project, compiled the benchmarks with `-O3`, and searched the resulting LLVM IR. The results are shown below.


### `icmp eq i64 lowbit, 0`

The historical zero-predicate scan used a 6,155-file lowbit prefilter from the
then-38,659-file optimized benchmark corpus. It found 56 raw rows in nine files
and four projects; 51 rows were strict deletion-ready matches and five had extra
lowbit uses. Only one strict row is in the requested i64 scope:

| Project | File | Line | Width | Evidence |
| --- | --- | ---: | ---: | --- |
| OpenJDK | `bench/openjdk/optimized/os.ll` | 5590 | i64 | Strict peeled-loop branch; the negation and lowbit values each have one use. |

For historical context only, the same strict zero-predicate scan contained 48
i8 Zed-Rust rows and two i32 CMake rows in addition to the i64 row above. Those
50 rows do not broaden this i64-only report. The five excluded structural rows
have an additional lowbit use, so replacing only the comparison would not delete
the producer chain.

### `icmp eq i64 lowbit, 1`

A historical 32-shard replay over a copied 6,155-file lowbit prefilter from the
then-38,659-file optimized benchmark corpus found 269 strict i64 occurrences in
seven Hyperscan modules. This is one optimization family with repeated
occurrences, not 269 independent issues or a claim of a 269x application-level
speedup.

| Module | Strict i64 occurrences |
| --- | ---: |
| `limex_compile.ll` | 174 |
| `ng_find_matches.ll` | 24 |
| `ng_haig.ll` | 23 |
| `ng_mcclellan.ll` | 21 |
| `ng_squash.ll` | 14 |
| `ng_execute.ll` | 10 |
| `dfa_min.ll` | 3 |
| **Total for this predicate variant** | **269** |

Representative locations include:

| Module | Location | Function |
| --- | --- | --- |
| `ng_haig.ll` | `bench/hyperscan/optimized/ng_haig.ll:1151` | `attemptToBuildHaig` |
| `ng_execute.ll` | `bench/hyperscan/optimized/ng_execute.ll:643` | `getVertices` |
| `ng_mcclellan.ll` | `bench/hyperscan/optimized/ng_mcclellan.ll:2463` | `buildMcClellan` |
| `ng_find_matches.ll` | `bench/hyperscan/optimized/ng_find_matches.ll:5108` | `findMatches` |
| `limex_compile.ll` | `bench/hyperscan/optimized/limex_compile.ll:3381` | `generate` |
| `ng_squash.ll` | `bench/hyperscan/optimized/ng_squash.ll:1439` | `findSquashers` |
| `dfa_min.ll` | `bench/hyperscan/optimized/dfa_min.ll:6774` | `find_overlapping` |

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


More information about the llvm-commits mailing list