1 ==========================
2 Convergence And Uniformity
3 ==========================
11 Some parallel environments execute threads in groups that allow
12 communication within the group using special primitives called
13 *convergent* operations. The outcome of a convergent operation is
14 sensitive to the set of threads that executes it "together", i.e.,
17 A value is said to be *uniform* across a set of threads if it is the
18 same across those threads, and *divergent* otherwise. Correspondingly,
19 a branch is said to be a uniform branch if its condition is uniform,
20 and it is a divergent branch otherwise.
22 Whether threads are *converged* or not depends on the paths they take
23 through the control flow graph. Threads take different outgoing edges
24 at a *divergent branch*. Divergent branches constrain
25 program transforms such as changing the CFG or moving a convergent
26 operation to a different point of the CFG. Performing these
27 transformations across a divergent branch can change the sets of
28 threads that execute convergent operations convergently. While these
29 constraints are out of scope for this document, the described
30 *uniformity analysis* allows these transformations to identify
31 uniform branches where these constraints do not hold.
34 uniformity are inter-dependent: When threads diverge at a divergent
35 branch, they may later *reconverge* at a common program point.
36 Subsequent operations are performed convergently, but the inputs may
37 be non-uniform, thus producing divergent outputs.
39 Uniformity is also useful by itself on targets that execute threads in
40 groups with shared execution resources (e.g. waves, warps, or
43 - Uniform outputs can potentially be computed or stored on shared
45 - These targets must "linearize" a divergent branch to ensure that
46 each side of the branch is followed by the corresponding threads in
47 the same group. But linearization is unnecessary at uniform
48 branches, since the whole group of threads follows either one side
49 of the branch or the other.
51 This document presents a definition of convergence that is reasonable
52 for real targets and is compatible with the currently implicit
53 semantics of convergent operations in LLVM IR. This is accompanied by
54 a *uniformity analysis* that extends previous work on divergence analysis
55 [DivergenceSPMD]_ to cover irreducible control-flow.
57 .. [DivergenceSPMD] Julian Rosemann, Simon Moll, and Sebastian
58 Hack. 2021. An Abstract Interpretation for SPMD Divergence on
59 Reducible Control Flow Graphs. Proc. ACM Program. Lang. 5, POPL,
60 Article 31 (January 2021), 35 pages.
61 https://doi.org/10.1145/3434312
67 Described in :ref:`cycle-terminology`.
70 Described in :ref:`cycle-closed-path`.
73 Two paths in a CFG are said to be disjoint if the only nodes common
74 to both are the start node or the end node, or both.
77 A join node of a branch is a node reachable along disjoint paths
78 starting from that branch.
81 A diverged path is a path that starts from a divergent branch and
82 either reaches a join node of the branch or reaches the end of the
83 function without passing through any join node of the branch.
85 Threads and Dynamic Instances
86 =============================
88 Each occurrence of an instruction in the program source is called a
89 *static instance*. When a thread executes a program, each execution of
90 a static instance produces a distinct *dynamic instance* of that
93 Each thread produces a unique sequence of dynamic instances:
95 - The sequence is generated along branch decisions and loop
97 - Starts with a dynamic instance of a "first" instruction.
98 - Continues with dynamic instances of successive "next"
101 Threads are independent; some targets may choose to execute them in
102 groups in order to share resources when possible.
104 .. figure:: convergence-natural-loop.png
105 :name: convergence-natural-loop
108 :name: convergence-thread-example
111 +----------+--------+-----+-----+-----+-----+-----+-----+-----+-----+-----+------+
112 | | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | |
113 +----------+--------+-----+-----+-----+-----+-----+-----+-----+-----+-----+------+
114 | Thread 1 | Entry1 | H1 | B1 | L1 | H3 | | L3 | | | | Exit |
115 +----------+--------+-----+-----+-----+-----+-----+-----+-----+-----+-----+------+
116 | Thread 2 | Entry1 | H2 | | L2 | H4 | B2 | L4 | H5 | B3 | L5 | Exit |
117 +----------+--------+-----+-----+-----+-----+-----+-----+-----+-----+-----+------+
119 In the above table, each row is a different thread, listing the
120 dynamic instances produced by that thread from left to right. Each
121 thread executes the same program that starts with an ``Entry`` node
122 and ends with an ``Exit`` node, but different threads may take
123 different paths through the control flow of the program. The columns
124 are numbered merely for convenience, and empty cells have no special
125 meaning. Dynamic instances listed in the same column are converged.
127 .. _convergence-definition:
132 *Converged-with* is a transitive symmetric relation over dynamic
133 instances produced by *different threads* for the *same static
134 instance*. Informally, two threads that produce converged dynamic
135 instances are said to be *converged*, and they are said to execute
136 that static instance *convergently*, at that point in the execution.
138 *Convergence order* is a strict partial order over dynamic instances
139 that is defined as the transitive closure of:
141 1. If dynamic instance ``P`` is executed strictly before ``Q`` in the
142 same thread, then ``P`` is *convergence-before* ``Q``.
143 2. If dynamic instance ``P`` is executed strictly before ``Q1`` in the
144 same thread, and ``Q1`` is *converged-with* ``Q2``, then ``P`` is
145 *convergence-before* ``Q2``.
146 3. If dynamic instance ``P1`` is *converged-with* ``P2``, and ``P2``
147 is executed strictly before ``Q`` in the same thread, then ``P1``
148 is *convergence-before* ``Q``.
151 :name: convergence-order-example
154 +----------+-------+-----+-----+-----+-----+-----+-----+-----+------+
155 | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
156 +----------+-------+-----+-----+-----+-----+-----+-----+-----+------+
157 | Thread 1 | Entry | ... | | | | S2 | T | ... | Exit |
158 +----------+-------+-----+-----+-----+-----+-----+-----+-----+------+
159 | Thread 2 | Entry | ... | | Q2 | R | S1 | | ... | Exit |
160 +----------+-------+-----+-----+-----+-----+-----+-----+-----+------+
161 | Thread 3 | Entry | ... | P | Q1 | | | | ... | |
162 +----------+-------+-----+-----+-----+-----+-----+-----+-----+------+
164 The above table shows partial sequences of dynamic instances from
165 different threads. Dynamic instances in the same column are assumed
166 to be converged (i.e., related to each other in the converged-with
167 relation). The resulting convergence order includes the edges ``P ->
168 Q2``, ``Q1 -> R``, ``P -> R``, ``P -> T``, etc.
170 The fact that *convergence-before* is a strict partial order is a
171 constraint on the *converged-with* relation. It is trivially satisfied
172 if different dynamic instances are never converged. It is also
173 trivially satisfied for all known implementations for which
174 convergence plays some role. Aside from the strict partial convergence
175 order, there are currently no additional constraints on the
176 *converged-with* relation imposed in LLVM IR.
178 .. _convergence-note-convergence:
182 1. The ``convergent`` attribute on convergent operations does
183 constrain changes to ``converged-with``, but it is expressed in
184 terms of control flow and does not explicitly deal with thread
187 2. The convergence-before relation is not
188 directly observable. Program transforms are in general free to
189 change the order of instructions, even though that obviously
190 changes the convergence-before relation.
192 3. Converged dynamic instances need not be executed at the same
193 time or even on the same resource. Converged dynamic instances
194 of a convergent operation may appear to do so but that is an
195 implementation detail. The fact that ``P`` is convergence-before
196 ``Q`` does not automatically imply that ``P`` happens-before
197 ``Q`` in a memory model sense.
199 4. **Future work:** Providing convergence-related guarantees to
200 compiler frontends enables some powerful optimization techniques
201 that can be used by programmers or by high-level program
202 transforms. Constraints on the ``converged-with`` relation may
203 be added eventually as part of the definition of LLVM
204 IR, so that guarantees can be made that frontends can rely on.
205 For a proposal on how this might work, see `D85603
206 <https://reviews.llvm.org/D85603>`_.
208 .. _convergence-maximal:
213 This section defines a constraint that may be used to
214 produce a *maximal converged-with* relation without violating the
215 strict *convergence-before* order. This maximal converged-with
216 relation is reasonable for real targets and is compatible with
217 convergent operations.
219 The maximal converged-with relation is defined in terms of cycle
220 headers, which are not unique to a given CFG. Each cycle hierarchy for
221 the same CFG results in a different maximal converged-with relation.
223 **Maximal converged-with:**
225 Dynamic instances ``X1`` and ``X2`` produced by different threads
226 for the same static instance ``X`` are converged in the maximal
227 converged-with relation if and only if for every cycle ``C`` with
228 header ``H`` that contains ``X``:
230 - every dynamic instance ``H1`` of ``H`` that precedes ``X1`` in
231 the respective thread is convergence-before ``X2``, and,
232 - every dynamic instance ``H2`` of ``H`` that precedes ``X2`` in
233 the respective thread is convergence-before ``X1``,
234 - without assuming that ``X1`` is converged with ``X2``.
238 For brevity, the rest of the document restricts the term
239 *converged* to mean "related under the maximal converged-with
240 relation for the given cycle hierarchy".
242 Maximal convergence can now be demonstrated in the earlier example as follows:
247 +----------+--------+-----+-----+-----+-----+-----+-----+-----+-----+-----+------+
248 | | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | |
249 +----------+--------+-----+-----+-----+-----+-----+-----+-----+-----+-----+------+
250 | Thread 1 | Entry1 | H1 | B1 | L1 | H3 | | L3 | | | | Exit |
251 +----------+--------+-----+-----+-----+-----+-----+-----+-----+-----+-----+------+
252 | Thread 2 | Entry2 | H2 | | L2 | H4 | B2 | L4 | H5 | B3 | L5 | Exit |
253 +----------+--------+-----+-----+-----+-----+-----+-----+-----+-----+-----+------+
255 - ``Entry1`` and ``Entry2`` are converged.
256 - ``H1`` and ``H2`` are converged.
257 - ``B1`` and ``B2`` are not converged due to ``H4`` which is not
258 convergence-before ``B1``.
259 - ``H3`` and ``H4`` are converged.
260 - ``H3`` is not converged with ``H5`` due to ``H4`` which is not
261 convergence-before ``H3``.
262 - ``L1`` and ``L2`` are converged.
263 - ``L3`` and ``L4`` are converged.
264 - ``L3`` is not converged with ``L5`` due to ``H5`` which is not
265 convergence-before ``L3``.
267 .. _convergence-cycle-headers:
269 Dependence on Cycles Headers
270 ----------------------------
272 Contradictions in convergence order are possible only between two
273 nodes that are inside some cycle. The dynamic instances of such nodes
274 may be interleaved in the same thread, and this interleaving may be
275 different for different threads.
277 When a thread executes a node ``X`` once and then executes it again,
278 it must have followed a closed path in the CFG that includes ``X``.
279 Such a path must pass through the header of at least one cycle --- the
280 smallest cycle that includes the entire closed path. In a given
281 thread, two dynamic instances of ``X`` are either separated by the
282 execution of at least one cycle header, or ``X`` itself is a cycle
285 In reducible cycles (natural loops), each execution of the header is
286 equivalent to the start of a new iteration of the cycle. But this
287 analogy breaks down in the presence of explicit constraints on the
288 converged-with relation, such as those described in :ref:`future
289 work<convergence-note-convergence>`. Instead, cycle headers should be
290 treated as implicit *points of convergence* in a maximal
291 converged-with relation.
293 Consider a sequence of nested cycles ``C1``, ``C2``, ..., ``Ck`` such
294 that ``C1`` is the outermost cycle and ``Ck`` is the innermost cycle,
295 with headers ``H1``, ``H2``, ..., ``Hk`` respectively. When a thread
296 enters the cycle ``Ck``, any of the following is possible:
298 1. The thread directly entered cycle ``Ck`` without having executed
299 any of the headers ``H1`` to ``Hk``.
301 2. The thread executed some or all of the nested headers one or more
304 The maximal converged-with relation captures the following intuition
307 1. When two threads enter a top-level cycle ``C1``, they execute
308 converged dynamic instances of every node that is a :ref:`child
309 <cycle-parent-block>` of ``C1``.
311 2. When two threads enter a nested cycle ``Ck``, they execute
312 converged dynamic instances of every node that is a child of
313 ``Ck``, until either thread exits ``Ck``, if and only if they
314 executed converged dynamic instances of the last nested header that
315 either thread encountered.
317 Note that when a thread exits a nested cycle ``Ck``, it must follow
318 a closed path outside ``Ck`` to reenter it. This requires executing
319 the header of some outer cycle, as described earlier.
321 Consider two dynamic instances ``X1`` and ``X2`` produced by threads ``T1``
322 and ``T2`` for a node ``X`` that is a child of nested cycle ``Ck``.
323 Maximal convergence relates ``X1`` and ``X2`` as follows:
325 1. If neither thread executed any header from ``H1`` to ``Hk``, then
326 ``X1`` and ``X2`` are converged.
328 2. Otherwise, if there are no converged dynamic instances ``Q1`` and
329 ``Q2`` of any header ``Q`` from ``H1`` to ``Hk`` (where ``Q`` is
330 possibly the same as ``X``), such that ``Q1`` precedes ``X1`` and
331 ``Q2`` precedes ``X2`` in the respective threads, then ``X1`` and
332 ``X2`` are not converged.
334 3. Otherwise, consider the pair ``Q1`` and ``Q2`` of converged dynamic
335 instances of a header ``Q`` from ``H1`` to ``Hk`` that occur most
336 recently before ``X1`` and ``X2`` in the respective threads. Then
337 ``X1`` and ``X2`` are converged if and only if there is no dynamic
338 instance of any header from ``H1`` to ``Hk`` that occurs between
339 ``Q1`` and ``X1`` in thread ``T1``, or between ``Q2`` and ``X2`` in
340 thread ``T2``. In other words, ``Q1`` and ``Q2`` represent the last
341 point of convergence, with no other header being executed before
346 .. figure:: convergence-both-diverged-nested.png
347 :name: convergence-both-diverged-nested
349 The above figure shows two nested irreducible cycles with headers
350 ``R`` and ``S``. The nodes ``Entry`` and ``Q`` have divergent
351 branches. The table below shows the convergence between three threads
352 taking different paths through the CFG. Dynamic instances listed in
353 the same column are converged.
358 +---------+-------+-----+-----+-----+-----+-----+-----+-----+------+
359 | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 10 |
360 +---------+-------+-----+-----+-----+-----+-----+-----+-----+------+
361 | Thread1 | Entry | P1 | Q1 | S1 | P3 | Q3 | R1 | S2 | Exit |
362 +---------+-------+-----+-----+-----+-----+-----+-----+-----+------+
363 | Thread2 | Entry | P2 | Q2 | | | | R2 | S3 | Exit |
364 +---------+-------+-----+-----+-----+-----+-----+-----+-----+------+
365 | Thread3 | Entry | | | | | | R3 | S4 | Exit |
366 +---------+-------+-----+-----+-----+-----+-----+-----+-----+------+
368 - ``P2`` and ``P3`` are not converged due to ``S1``
369 - ``Q2`` and ``Q3`` are not converged due to ``S1``
370 - ``S1`` and ``S3`` are not converged due to ``R2``
371 - ``S1`` and ``S4`` are not converged due to ``R3``
373 Informally, ``T1`` and ``T2`` execute the inner cycle a different
374 number of times, without executing the header of the outer cycle. All
375 threads converge in the outer cycle when they first execute the header
378 .. _convergence-uniformity:
383 1. The output of two converged dynamic instances is uniform if and
384 only if it compares equal for those two dynamic instances.
385 2. The output of a static instance ``X`` is uniform *for a given set
386 of threads* if and only if it is uniform for every pair of
387 converged dynamic instances of ``X`` produced by those threads.
389 A non-uniform value is said to be *divergent*.
391 For a set ``S`` of threads, the uniformity of each output of a static
392 instance is determined as follows:
394 1. The semantics of the instruction may specify the output to be
396 2. Otherwise, the output is divergent if the static instance is not
397 :ref:`m-converged <convergence-m-converged>`.
398 3. Otherwise, if the static instance is m-converged:
400 1. If it is a PHI node, its output is uniform if and only
401 if for every pair of converged dynamic instances produced by all
404 a. Both instances choose the same output from converged
405 dynamic instances, and,
406 b. That output is uniform for all threads in ``S``.
407 2. Otherwise, the output is uniform if and only if the input
408 operands are uniform for all threads in ``S``.
410 Divergent Cycle Exits
411 ---------------------
413 When a divergent branch occurs inside a cycle, it is possible that a
414 diverged path continues to an exit of the cycle. This is called a
415 divergent cycle exit. If the cycle is irreducible, the diverged path
416 may re-enter and eventually reach a join within the cycle. Such a join
417 should be examined for the :ref:`diverged entry
418 <convergence-diverged-entry>` criterion.
420 Nodes along the diverged path that lie outside the cycle experience
421 *temporal divergence*, when two threads executing convergently inside
422 the cycle produce uniform values, but exit the cycle along the same
423 divergent path after executing the header a different number of times
424 (informally, on different iterations of the cycle). For a node ``N``
425 inside the cycle the outputs may be uniform for the two threads, but
426 any use ``U`` outside the cycle receives a value from non-converged
427 dynamic instances of ``N``. An output of ``U`` may be divergent,
428 depending on the semantics of the instruction.
430 Static Uniformity Analysis
431 ==========================
433 Irreducible control flow results in different cycle hierarchies
434 depending on the choice of headers during depth-first traversal. As a
435 result, a static analysis cannot always determine the convergence of
436 nodes in irreducible cycles, and any uniformity analysis is limited to
437 those static instances whose convergence is independent of the cycle
440 .. _convergence-m-converged:
442 **m-converged static instances:**
444 A static instance ``X`` is *m-converged* for a given CFG if and only
445 if the maximal converged-with relation for its dynamic instances is
446 the same in every cycle hierarchy that can be constructed for that CFG.
450 In other words, two dynamic instances ``X1`` and ``X2`` of an
451 m-converged static instance ``X`` are converged in some cycle
452 hierarchy if and only if they are also converged in every other
453 cycle hierarchy for the same CFG.
455 As noted earlier, for brevity, we restrict the term *converged* to
456 mean "related under the maximal converged-with relation for a given
460 Each node ``X`` in a given CFG is reported to be m-converged if and
463 1. ``X`` is a :ref:`top-level<cycle-toplevel-block>` node, in which
464 case, there are no cycle headers to influence the convergence of
467 2. Otherwise, if ``X`` is inside a cycle, then every cycle that
468 contains ``X`` satisfies the following necessary conditions:
470 a. Every divergent branch inside the cycle satisfies the
471 :ref:`diverged entry criterion<convergence-diverged-entry>`, and,
472 b. There are no :ref:`diverged paths reaching the
473 cycle<convergence-diverged-outside>` from a divergent branch
478 A reducible cycle :ref:`trivially satisfies
479 <convergence-reducible-cycle>` the above conditions. In particular,
480 if the whole CFG is reducible, then all nodes in the CFG are
483 The uniformity of each output of a static instance
484 is determined using the criteria
485 :ref:`described earlier <convergence-uniformity>`. The discovery of
486 divergent outputs may cause their uses (including branches) to also
487 become divergent. The analysis propagates this divergence until a
488 fixed point is reached.
490 The convergence inferred using these criteria is a safe subset of the
491 maximal converged-with relation for any cycle hierarchy. In
492 particular, it is sufficient to determine if a static instance is
493 m-converged for a given cycle hierarchy ``T``, even if that fact is
494 not detected when examining some other cycle hierarchy ``T'``.
496 This property allows compiler transforms to use the uniformity
497 analysis without being affected by DFS choices made in the underlying
498 cycle analysis. When two transforms use different instances of the
499 uniformity analysis for the same CFG, a "divergent value" result in
500 one analysis instance cannot contradict a "uniform value" result in
503 Generic transforms such as SimplifyCFG, CSE, and loop transforms
504 commonly change the program in ways that change the maximal
505 converged-with relations. This also means that a value that was
506 previously uniform can become divergent after such a transform.
507 Uniformity has to be recomputed after such transforms.
509 Divergent Branch inside a Cycle
510 -------------------------------
512 .. figure:: convergence-divergent-inside.png
513 :name: convergence-divergent-inside
515 The above figure shows a divergent branch ``Q`` inside an irreducible
516 cyclic region. When two threads diverge at ``Q``, the convergence of
517 dynamic instances within the cyclic region depends on the cycle
520 1. In an implementation that detects a single cycle ``C`` with header
521 ``P``, convergence inside the cycle is determined by ``P``.
523 2. In an implementation that detects two nested cycles with headers
524 ``R`` and ``S``, convergence inside those cycles is determined by
525 their respective headers.
527 .. _convergence-diverged-entry:
529 A conservative approach would be to simply report all nodes inside
530 irreducible cycles as having divergent outputs. But it is desirable to
531 recognize m-converged nodes in the CFG in order to maximize
532 uniformity. This section describes one such pattern of nodes derived
533 from *closed paths*, which are a property of the CFG and do not depend
534 on the cycle hierarchy.
536 **Diverged Entry Criterion:**
538 The dynamic instances of all the nodes in a closed path ``P`` are
539 m-converged only if for every divergent branch ``B`` and its
540 join node ``J`` that lie on ``P``, there is no entry to ``P`` which
541 lies on a diverged path from ``B`` to ``J``.
543 .. figure:: convergence-closed-path.png
544 :name: convergence-closed-path
546 Consider the closed path ``P -> Q -> R -> S`` in the above figure.
547 ``P`` and ``R`` are :ref:`entries to the closed
548 path<cycle-closed-path>`. ``Q`` is a divergent branch and ``S`` is a
549 join for that branch, with diverged paths ``Q -> R -> S`` and ``Q ->
552 - If a diverged entry ``R`` exists, then in some cycle hierarchy,
553 ``R`` is the header of the smallest cycle ``C`` containing the
554 closed path and a :ref:`child cycle<cycle-definition>` ``C'``
555 exists in the set ``C - R``, containing both branch ``Q`` and join
556 ``S``. When threads diverge at ``Q``, one subset ``M`` continues
557 inside cycle ``C'``, while the complement ``N`` exits ``C'`` and
558 reaches ``R``. Dynamic instances of ``S`` executed by threads in set
559 ``M`` are not converged with those executed in set ``N`` due to the
560 presence of ``R``. Informally, threads that diverge at ``Q``
561 reconverge in the same iteration of the outer cycle ``C``, but they
562 may have executed the inner cycle ``C'`` differently.
567 +---------+-------+-----+-----+-----+-----+-----+-----+-----+-----+-----+------+
568 | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
569 +---------+-------+-----+-----+-----+-----+-----+-----+-----+-----+-----+------+
570 | Thread1 | Entry | P1 | Q1 | | | | R1 | S1 | P3 | ... | Exit |
571 +---------+-------+-----+-----+-----+-----+-----+-----+-----+-----+-----+------+
572 | Thread2 | Entry | P2 | Q2 | S2 | P4 | Q4 | R2 | S4 | | | Exit |
573 +---------+-------+-----+-----+-----+-----+-----+-----+-----+-----+-----+------+
575 In the table above, ``S2`` is not converged with ``S1`` due to ``R1``.
579 - If ``R`` does not exist, or if any node other than ``R`` is the
580 header of ``C``, then no such child cycle ``C'`` is detected.
581 Threads that diverge at ``Q`` execute converged dynamic instances of
582 ``S`` since they do not encounter the cycle header on any path from
583 ``Q`` to ``S``. Informally, threads that diverge at ``Q``
584 reconverge at ``S`` in the same iteration of ``C``.
589 +---------+-------+-----+-----+-----+-----+-----+-----+-----+-----+------+
590 | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
591 +---------+-------+-----+-----+-----+-----+-----+-----+-----+-----+------+
592 | Thread1 | Entry | P1 | Q1 | R1 | S1 | P3 | Q3 | R3 | S3 | Exit |
593 +---------+-------+-----+-----+-----+-----+-----+-----+-----+-----+------+
594 | Thread2 | Entry | P2 | Q2 | | S2 | P4 | Q4 | R2 | S4 | Exit |
595 +---------+-------+-----+-----+-----+-----+-----+-----+-----+-----+------+
601 In general, the cycle ``C`` in the above statements is not
602 expected to be the same cycle for different headers. Cycles and
603 their headers are tightly coupled; for different headers in the
604 same outermost cycle, the child cycles detected may be different.
605 The property relevant to the above examples is that for every
606 closed path, there is a cycle ``C`` that contains the path and
607 whose header is on that path.
609 The diverged entry criterion must be checked for every closed path
610 passing through a divergent branch ``B`` and its join ``J``. Since
611 :ref:`every closed path passes through the header of some
612 cycle<cycle-closed-path-header>`, this amounts to checking every cycle
613 ``C`` that contains ``B`` and ``J``. When the header of ``C``
614 dominates the join ``J``, there can be no entry to any path from the
615 header to ``J``, which includes any diverged path from ``B`` to ``J``.
616 This is also true for any closed paths passing through the header of
617 an outer cycle that contains ``C``.
619 Thus, the diverged entry criterion can be conservatively simplified
622 For a divergent branch ``B`` and its join node ``J``, the nodes in a
623 cycle ``C`` that contains both ``B`` and ``J`` are m-converged only
626 - ``B`` strictly dominates ``J``, or,
627 - The header ``H`` of ``C`` strictly dominates ``J``, or,
628 - Recursively, there is cycle ``C'`` inside ``C`` that satisfies the
631 When ``J`` is the same as ``H`` or ``B``, the trivial dominance is
632 insufficient to make any statement about entries to diverged paths.
634 .. _convergence-diverged-outside:
636 Diverged Paths reaching a Cycle
637 -------------------------------
639 .. figure:: convergence-divergent-outside.png
640 :name: convergence-divergent-outside
642 The figure shows two cycle hierarchies with a divergent branch in
643 ``Entry`` instead of ``Q``. For two threads that enter the closed path
644 ``P -> Q -> R -> S`` at ``P`` and ``R`` respectively, the convergence
645 of dynamic instances generated along the path depends on whether ``P``
646 or ``R`` is the header.
648 - Convergence when ``P`` is the header.
653 +---------+-------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+------+
654 | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
655 +---------+-------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+------+
656 | Thread1 | Entry | | | | P1 | Q1 | R1 | S1 | P3 | Q3 | | S3 | Exit |
657 +---------+-------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+------+
658 | Thread2 | Entry | | R2 | S2 | P2 | Q2 | | S2 | P4 | Q4 | R3 | S4 | Exit |
659 +---------+-------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+------+
663 - Convergence when ``R`` is the header.
668 +---------+-------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+------+
669 | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
670 +---------+-------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+------+
671 | Thread1 | Entry | | P1 | Q1 | R1 | S1 | P3 | Q3 | S3 | | | Exit |
672 +---------+-------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+------+
673 | Thread2 | Entry | | | | R2 | S2 | P2 | Q2 | S2 | P4 | ... | Exit |
674 +---------+-------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+------+
678 Thus, when diverged paths reach different entries of an irreducible
679 cycle from outside the cycle, the static analysis conservatively
680 reports every node in the cycle as not m-converged.
682 .. _convergence-reducible-cycle:
687 If ``C`` is a reducible cycle with header ``H``, then in any DFS,
688 ``H`` :ref:`must be the header of some cycle<cycle-reducible-headers>`
689 ``C'`` that contains ``C``. Independent of the DFS, there is no entry
690 to the subgraph ``C`` other than ``H`` itself. Thus, we have the
693 1. The diverged entry criterion is trivially satisfied for a divergent
694 branch and its join, where both are inside subgraph ``C``.
695 2. When diverged paths reach the subgraph ``C`` from outside, their
696 convergence is always determined by the same header ``H``.
698 Clearly, this can be determined only in a cycle hierarchy ``T`` where
699 ``C`` is detected as a reducible cycle. No such conclusion can be made
700 in a different cycle hierarchy ``T'`` where ``C`` is part of a larger
701 cycle ``C'`` with the same header, but this does not contradict the