Algorithm Search⌘K

Theoremcore

MOP-MFP coincidence theorem

Also called Kildall's theorem, Kam-Ullman coincidence theorem.

In a distributive framework the maximal fixed-point solution equals the meet-over-all-paths solution; in a monotone one it is below it.

The MOP-MFP coincidence theorem compares the two answers of a dataflow analysis. The maximal fixed-point solution (MFP) is what an iterative solver computes. The meet-over-all-paths solution (MOP) is the ideal answer, the meet of the facts that each path produces. In every monotone dataflow framework, MFP is below MOP, so it is safe; in a distributive dataflow framework where every block is reachable, the two are equal. The definitions of the two solutions are on their own pages; this page states the theorem in full, proves it through an exact description of the iterates of the solver, and shows which hypotheses it needs.

Statement

The page uses the meet convention of Kildall and the dragon book. (L,⊓)(L, \sqcap) is a meet semilattice with top ⊤\top, x⊑yx \sqsubseteq y means x⊓y=xx \sqcap y = x, and LL has finite height hh. Lower facts are weaker and safer. Turning the order upside down gives the join convention of abstract interpretation, where the same theorem speaks of least fixed points and joins.

The instance. A control flow graph G=(V,E)G = (V, E) with nn blocks and an entry block ss, a monotone transfer function fB∈Ff_B \in F for each block BB, and a boundary value ι∈L\iota \in L. Let init(s)=ιinit(s) = \iota and init(B)=⊤init(B) = \top for B≠sB \ne s. The equation function is

F(X)[B]=init(B)⊓⊓(P,B)∈EfP(X[P]),F(X)[B] = init(B) \sqcap \mathop{\large\sqcap}_{(P, B) \in E} f_P(X[P]),

where XX gives each block the fact at its start and the empty meet is ⊤\top. MFP is the greatest fixed point of FF.

Paths and walks. A walk of length kk is a sequence of blocks w=(B0,B1,…,Bk)w = (B_0, B_1, \ldots, B_k) with (Bi−1,Bi)∈E(B_{i-1}, B_i) \in E for each ii. Its function is fw=fBk−1∘⋯∘fB0f_w = f_{B_{k-1}} \circ \cdots \circ f_{B_0}, the identity when k=0k = 0. A path to BB is a walk with B0=sB_0 = s and Bk=BB_k = B. Write Paths<j(B)\mathrm{Paths}_{<j}(B) for the paths to BB of length less than jj, and Walksj(B)\mathrm{Walks}_j(B) for the walks of length exactly jj that end at BB, from any start block. Then

MOP[B]=⊓π a path to Bfπ(ι).\mathrm{MOP}[B] = \mathop{\large\sqcap}_{\pi \text{ a path to } B} f_\pi(\iota).

The iterates. X0=⊤X_0 = \top at every block, and Xj+1=F(Xj)X_{j+1} = F(X_j). Define the path bound

Rj[B]=⊓π∈Paths<j(B)fπ(ι)  ⊓⊓w∈Walksj(B)fw(⊤).R_j[B] = \mathop{\large\sqcap}_{\pi \in \mathrm{Paths}_{<j}(B)} f_\pi(\iota) \;\sqcap \mathop{\large\sqcap}_{w \in \mathrm{Walks}_j(B)} f_w(\top).

Theorem. For every instance of a monotone framework of finite height:

  1. Xj[B]⊑Rj[B]X_j[B] \sqsubseteq R_j[B] for every j≥0j \ge 0 and every block BB.
  2. The iterates reach MFP after finitely many steps, and MFP[B]⊑MOP[B]\mathrm{MFP}[B] \sqsubseteq \mathrm{MOP}[B] for every block BB.
  3. If moreover every fBf_B is distributive, fB(x⊓y)=fB(x)⊓fB(y)f_B(x \sqcap y) = f_B(x) \sqcap f_B(y), and every block is reachable from ss, then Xj[B]=Rj[B]X_j[B] = R_j[B] for every jj and BB, and MFP=MOP\mathrm{MFP} = \mathrm{MOP}.

Part 3 is the coincidence theorem. Part 1 gives more than the usual statement: the jj-th iterate is exactly the meet of the facts of the paths shorter than jj and of the facts that walks of length jj produce from ⊤\top. A backward problem is the same on the reverse CFG, with the ret blocks in place of ss.

In plain words

An analysis can be exact in two ways. The ideal way follows every route from the start to a point, works out what each route proves, and keeps only what all routes agree on. The practical way gives every point a note and lets neighbors exchange notes until nothing changes, so it combines facts where routes meet instead of at the end.

Combining early can only lose information, never invent it, so the practical answer is never wrong where the ideal one is right. The theorem says when it loses nothing: when the effect of each block on a combined fact is the same as combining the effects on each fact. The proof watches the note exchange round by round and shows that after a given number of rounds a note holds exactly what the short routes prove, plus a hopeful guess that shrinks each round.

Proof

Two facts are used. First, the iterates go down and stop: X0⊒X1⊒⋯X_0 \sqsupseteq X_1 \sqsupseteq \cdots, and XJ=XJ+1=⋯=MFPX_J = X_{J+1} = \cdots = \mathrm{MFP} for some J≤nhJ \le n h. This is proved on the maximal fixed-point solution page. Second, the meet over the infinite set of paths exists, because in a semilattice of finite height with a top every nonempty set has a greatest lower bound (proved on the distributive dataflow framework page); the meet of the empty set is ⊤\top.

Lemma 1 (splitting the last edge). For every j≥0j \ge 0 and block BB:

  • the paths to BB of length less than j+1j + 1 are the path (s)(s) when B=sB = s, together with the paths π⋅B\pi \cdot B for an edge (P,B)(P, B) and a path π∈Paths<j(P)\pi \in \mathrm{Paths}_{<j}(P);
  • the walks of length j+1j + 1 that end at BB are the walks w⋅Bw \cdot B for an edge (P,B)(P, B) and a walk w∈Walksj(P)w \in \mathrm{Walks}_j(P);
  • in both cases fπ⋅B=fP∘fπf_{\pi \cdot B} = f_P \circ f_\pi and fw⋅B=fP∘fwf_{w \cdot B} = f_P \circ f_w.

Proof. Remove the last block of a path or walk of length at least 1; what remains ends at a predecessor PP of BB and is one edge shorter. The only path of length 0 is (s)(s). The function of a walk applies the function of each block except the last, so adding BB at the end adds fPf_P on the outside. □\square

Let Sj(B)S_j(B) be the set of the elements met in Rj[B]R_j[B], that is {fπ(ι):π∈Paths<j(B)}∪{fw(⊤):w∈Walksj(B)}\{f_\pi(\iota) : \pi \in \mathrm{Paths}_{<j}(B)\} \cup \{f_w(\top) : w \in \mathrm{Walks}_j(B)\}. It is finite, since GG is finite and the lengths are bounded, so Rj[B]=⊓Sj(B)R_j[B] = \mathop{\large\sqcap} S_j(B) is a finite meet.

Lemma 2 (the meet of the set is nonempty when BB is reachable). If BB is reachable from ss, then Sj(B)S_j(B) is not empty for every jj.

Proof. For j=0j = 0, the walk (B)(B) is in Walks0(B)\mathrm{Walks}_0(B). For j≥1j \ge 1, take a path π\pi to BB of some length ℓ\ell. If ℓ<j\ell < j, then π∈Paths<j(B)\pi \in \mathrm{Paths}_{<j}(B). Otherwise the last jj edges of π\pi form a walk in Walksj(B)\mathrm{Walks}_j(B). □\square

Part 1. Induction on jj. For j=0j = 0, Paths<0(B)\mathrm{Paths}_{<0}(B) is empty and Walks0(B)={(B)}\mathrm{Walks}_0(B) = \{(B)\} with the identity function, so R0[B]=⊤=X0[B]R_0[B] = \top = X_0[B]. Assume Xj[P]⊑Rj[P]X_j[P] \sqsubseteq R_j[P] for every PP. For each r∈Sj(P)r \in S_j(P) we have Rj[P]⊑rR_j[P] \sqsubseteq r, so monotonicity gives fP(Xj[P])⊑fP(Rj[P])⊑fP(r)f_P(X_j[P]) \sqsubseteq f_P(R_j[P]) \sqsubseteq f_P(r). So fP(Xj[P])f_P(X_j[P]) is a lower bound of {fP(r):r∈Sj(P)}\{f_P(r) : r \in S_j(P)\}, and

Xj+1[B]=init(B)⊓⊓(P,B)∈EfP(Xj[P])  ⊑  init(B)⊓⊓(P,B)∈E  ⊓r∈Sj(P)fP(r).X_{j+1}[B] = init(B) \sqcap \mathop{\large\sqcap}_{(P, B) \in E} f_P(X_j[P]) \;\sqsubseteq\; init(B) \sqcap \mathop{\large\sqcap}_{(P, B) \in E} \; \mathop{\large\sqcap}_{r \in S_j(P)} f_P(r).

By Lemma 1, the right side meets exactly the elements of Sj+1(B)S_{j+1}(B): the term init(s)=ι=f(s)(ι)init(s) = \iota = f_{(s)}(\iota) is the path (s)(s), the term init(B)=⊤init(B) = \top for B≠sB \ne s changes nothing, and the other terms are fP(fπ(ι))=fπ⋅B(ι)f_P(f_\pi(\iota)) = f_{\pi \cdot B}(\iota) and fP(fw(⊤))=fw⋅B(⊤)f_P(f_w(\top)) = f_{w \cdot B}(\top). So Xj+1[B]⊑Rj+1[B]X_{j+1}[B] \sqsubseteq R_{j+1}[B]. □\square

Part 2. Take JJ with Xj=MFPX_j = \mathrm{MFP} for all j≥Jj \ge J. Let π\pi be a path to BB of length ℓ\ell, and j=max⁡(J,ℓ+1)j = \max(J, \ell + 1). Then π∈Paths<j(B)\pi \in \mathrm{Paths}_{<j}(B), so by part 1, MFP[B]=Xj[B]⊑Rj[B]⊑fπ(ι)\mathrm{MFP}[B] = X_j[B] \sqsubseteq R_j[B] \sqsubseteq f_\pi(\iota). So MFP[B]\mathrm{MFP}[B] is a lower bound of all path facts, and therefore MFP[B]⊑MOP[B]\mathrm{MFP}[B] \sqsubseteq \mathrm{MOP}[B]. If no path reaches BB, then MOP[B]=⊤\mathrm{MOP}[B] = \top and the claim is trivial. □\square

Part 3, the iterates. Repeat the induction of part 1 with equalities. The only step that was an inequality is fP(Rj[P])⊑⊓r∈Sj(P)fP(r)f_P(R_j[P]) \sqsubseteq \mathop{\large\sqcap}_{r \in S_j(P)} f_P(r). A distributive function satisfies f(x1⊓⋯⊓xk)=f(x1)⊓⋯⊓f(xk)f(x_1 \sqcap \cdots \sqcap x_k) = f(x_1) \sqcap \cdots \sqcap f(x_k) for every k≥1k \ge 1, by induction on kk. By Lemma 2, Sj(P)S_j(P) is a nonempty finite set, so the step is an equality, and with Xj[P]=Rj[P]X_j[P] = R_j[P] we get fP(Xj[P])=⊓r∈Sj(P)fP(r)f_P(X_j[P]) = \mathop{\large\sqcap}_{r \in S_j(P)} f_P(r). So Xj+1[B]=Rj+1[B]X_{j+1}[B] = R_{j+1}[B]. The nonempty condition matters: for the empty set the left side would be fP(⊤)f_P(\top) and the right side ⊤\top, and these differ for most functions. □\square

Part 3, MOP is below MFP. We show MOP[B]⊑r\mathrm{MOP}[B] \sqsubseteq r for every r∈Sj(B)r \in S_j(B). If r=fπ(ι)r = f_\pi(\iota) for a path π\pi, this holds because MOP[B]\mathrm{MOP}[B] is the meet over all paths. If r=fw(⊤)r = f_w(\top) for a walk w=(B0,…,Bj)w = (B_0, \ldots, B_j) with Bj=BB_j = B, take a path α\alpha from ss to B0B_0, which exists because B0B_0 is reachable. Joining α\alpha and ww at B0B_0 gives a path αw\alpha w to BB with fαw=fw∘fαf_{\alpha w} = f_w \circ f_\alpha. Since fα(ι)⊑⊤f_\alpha(\iota) \sqsubseteq \top and fwf_w is monotone,

MOP[B]⊑fαw(ι)=fw(fα(ι))⊑fw(⊤)=r.\mathrm{MOP}[B] \sqsubseteq f_{\alpha w}(\iota) = f_w(f_\alpha(\iota)) \sqsubseteq f_w(\top) = r.

So MOP[B]\mathrm{MOP}[B] is a lower bound of Sj(B)S_j(B), hence MOP[B]⊑Rj[B]=Xj[B]\mathrm{MOP}[B] \sqsubseteq R_j[B] = X_j[B] for every jj. With j≥Jj \ge J this gives MOP[B]⊑MFP[B]\mathrm{MOP}[B] \sqsubseteq \mathrm{MFP}[B], and part 2 gives the other direction. ■\blacksquare

A worked example. Take reaching definitions (meet =∪= \cup, ⊤=∅\top = \emptyset, ι=∅\iota = \emptyset) on this loop, with the definitions d1d_1 of i in entry, d3d_3 of t in head and d2d_2 of i in body:

entry:
  i = 0
  jump head
head:
  t = i < n
  br t body exit
body:
  i = i + 1
  jump head
exit:
  ret i

The edges are entry to head, head to body, body to head and head to exit. The iterates at head are X0=∅X_0 = \emptyset, X1={d1,d2}X_1 = \{d_1, d_2\} and X2=X3={d1,d2,d3}X_2 = X_3 = \{d_1, d_2, d_3\}. Part 3 predicts X1X_1: no path to head is shorter than one edge, and the walks of length 1 that end at head are (entry, head), which gives fentry(∅)={d1}f_{entry}(\emptyset) = \{d_1\}, and (body, head), which gives fbody(∅)={d2}f_{body}(\emptyset) = \{d_2\}. At j=2j = 2 the path (entry, head) gives {d1}\{d_1\} and the only walk of length 2, (head, body, head), gives {d2,d3}\{d_2, d_3\}. The fixed point {d1,d2,d3}\{d_1, d_2, d_3\} is also MOP: the path (entry, head) brings d1d_1, and the path (entry, head, body, head) brings d2d_2 and d3d_3.

Consequences

  • Iterative solvers are exact for the bit-vector problems. The four classic gen-kill problems are distributive, so the worklist dataflow algorithm, round-robin iteration and every other fair order compute MOP on a CFG whose blocks are all reachable. How many rounds that takes is the subject of the Kam-Ullman iteration bound.
  • An early stop is unsafe. By part 1, an iterate that is not yet stable still holds the terms fw(⊤)f_w(\top) of walks that start from the optimistic value. In the example, X1[head]={d1,d2}X_1[\text{head}] = \{d_1, d_2\} misses d3d_3, which does reach head. A solver must run to the fixed point before a client uses its facts.
  • Monotone frameworks are safe. Part 2 needs no distributivity and no reachability. So constant propagation, which is monotone but not distributive, has a safe MFP even where it is less precise than MOP.
  • MOP is not computable in general. Kam and Ullman (1977) proved that no algorithm computes the MOP solution of every instance of every monotone framework. The fixed point is therefore the answer that analyses compute; the theorem says when it is also the ideal one.
  • Interprocedural analysis. Across procedures the ideal answer is the meet over valid paths, in which returns match calls (see interprocedural dataflow analysis). The functional approach of Sharir and Pnueli and the IFDS framework and IDE framework reach that ideal for distributive problems, by the same argument applied to summary functions.

Tightness

  • Distributivity is needed. Let f∈Ff \in F and x,y∈Lx, y \in L with f(x⊓y)≠f(x)⊓f(y)f(x \sqcap y) \ne f(x) \sqcap f(y), and let g1,g2∈Fg_1, g_2 \in F produce x=g1(ι)x = g_1(\iota) and y=g2(ι)y = g_2(\iota). Build a diamond: the entry has the identity function and two successors AA and CC with the functions g1g_1 and g2g_2, both go to a block JJ with the function ff, and JJ goes to an exit. The two paths give MOP[exit]=f(x)⊓f(y)\mathrm{MOP}[\text{exit}] = f(x) \sqcap f(y). MFP meets first, so MFP[J]=x⊓y\mathrm{MFP}[J] = x \sqcap y and MFP[exit]=f(x⊓y)\mathrm{MFP}[\text{exit}] = f(x \sqcap y), which is strictly below f(x)⊓f(y)f(x) \sqcap f(y) by monotonicity and the choice of ff. Constant propagation with (x,y)=(2,3)(x, y) = (2, 3) on one branch and (3,2)(3, 2) on the other, followed by z = x + y, is this case: MOP finds z=5z = 5 and MFP does not. Kam and Ullman (1977) showed that every monotone framework that is not distributive has an instance where MFP differs from MOP.
  • Reachability is needed. A block that the entry does not reach still passes its function value to its successors in every solution of the equations, while MOP ignores it. The distributive dataflow framework page gives an instance where this makes MFP strictly below MOP.
  • Distributivity is not necessary on a given instance. If every block has at most one predecessor, the CFG is a tree, each block has exactly one path, no meet is ever taken, and MFP = MOP for every monotone framework.
  • Finite height is needed for the finite iteration. Take L=Z∪{−∞,+∞}L = \mathbb{Z} \cup \{-\infty, +\infty\} with the meet min⁡\min and ⊤=+∞\top = +\infty, an entry with the identity and ι=0\iota = 0, and a loop block HH with a self-loop and fH(x)=x−1f_H(x) = x - 1, which is distributive. The iterates at HH are +∞,+∞,0,−1,−2,…+\infty, +\infty, 0, -1, -2, \ldots and never stop. The greatest fixed point and MOP are both −∞-\infty, but they are reached only in the limit. Abstract interpreters on such lattices use a widening operator.

History

Kildall (1973) set dataflow analysis in a semilattice with distributive transfer functions. He gave the iterative algorithm that starts from the top element and showed that it computes the meet over all paths. Kam and Ullman (1977) noticed that useful analyses, constant propagation first, are monotone but not distributive. They defined monotone frameworks, proved that the maximal fixed point exists and is below the meet over all paths, showed that every monotone framework that is not distributive has an instance with a gap, and proved that the meet over all paths cannot be computed in general. Textbooks give the result in both conventions: the dragon book with meets, and Nielson, Nielson and Hankin with joins and least fixed points.

References

  1. Gary A. Kildall, A unified approach to global program optimization, Proceedings of the 1st ACM SIGACT-SIGPLAN Symposium on Principles of Programming Languages (POPL 1973), 194-206, the whole paper (the lattice framework, the iterative algorithm from the top element, and the result that it reaches the meet over all paths when the functions are distributive)
  2. John B. Kam and Jeffrey D. Ullman, Monotone data flow analysis frameworks, Acta Informatica 7(3), 1977, 305-317, the whole paper (monotone frameworks, the maximal fixed point below the meet over all paths, a gap in some instance of every monotone framework that is not distributive, and no algorithm for the meet over all paths in general)
  3. Alfred V. Aho, Monica S. Lam, Ravi Sethi and Jeffrey D. Ullman, Compilers, Principles, Techniques, and Tools, second edition, Pearson Addison-Wesley, 2007, Section 9.3.4 (Meaning of a Data-Flow Solution, the maximum fixedpoint against the meet-over-paths solution)
  4. Flemming Nielson, Hanne Riis Nielson and Chris Hankin, Principles of Program Analysis, Springer, 1999, Section 2.4 (Equation Solving, the MFP and MOP solutions and when they agree), in the join convention

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/9MJ0B6/text.yaml