[llvm] [Instcombine] Fold a zero-select hexadecimal digit count into ctlz(x | 1) (PR #215073)

via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 23 13:53:46 PDT 2026


================

----------------
ParkHanbum wrote:

Could we avoid scanning `X->users()` here and reuse the `DropFlags` from the existing equivalence attempt?

The existing fold already evaluates the zero case as `F(BW)` by relaxing `ctlz(X, true)` to `ctlz(X, false)`. If that fails, `DropFlags` should already contain the relevant zero-poison `ctlz` found while simplifying `FalseVal`.

So the fallback could simply reuse that `ctlz` and test:

```text
F(BW - 1) == TrueVal
```

If it succeeds, rewrite:

```text
ctlz(X, true) -> ctlz(X | 1, true)
```

and remove the select.

This seems simpler and keeps the fallback local to the `FalseVal` analysis, without an additional traversal over all users of `X`.


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


More information about the llvm-commits mailing list