[llvm] [Semilattice] Introduce for dataflow analysis with KnownBits (PR #177616)

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 23 11:11:54 PST 2026


artagnon wrote:

> > It would be good to run an experiment with computeKnownBits() changed to not retain the root context instruction, to confirm that this indeed does not cause significant regressions.
> 
> Agree. I'd like to see a more complete prototype (e.g., migrate InstCombine/InstSimplify to use KnownBitsAnalysis).

Hm, I tried the cheap experiment, and there are [lots of minor regressions](https://github.com/dtcxzyw/llvm-opt-benchmark/pull/3370/changes): could you kindly verify that the experiment is sound?
 
> > I can't say I understand what semilattices have to do with this.
> 
> IIRC it is related to the dataflow analysis algorithm. KnownBits defines a partial order, and we use unionWith/intersectWith to update/merge the result, respectively.

KnownBits define a partial order, which is to say that not every two pairs of KnownBits are comparable, although the parent KnownBits is a refinement of the KnownBits of its immediate children. However, the computation of KnownBits is idempotent, commutative, and associative: two KnownBits computations on the same value are guaranteed to return the same result, and it doesn't matter which leaf's KnownBits computation is performed first (which is to say that the children in the semilattice don't have an order). The KnownBits of a parent depends on the computation of the entire child subgraph, and the KnownBits computation forms a join-semilattice at each of the roots (ignoring the sentinel root): in graph terms, it is simply a graph with multiple parents and multiple children that have multiple leaves.

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


More information about the llvm-commits mailing list