Header image for Comp Opt Light

Comp Opt Light

Prompt

Extremely correctly, properly, intelligently, factually and sensibly tell me the top 50 most likely questions in a tough, tricky and thought provoking interview that focuses on mistakes, fallacies, misassumptions, misunderstandings, pitfalls, oversights, overconfidence, overenthusiasm, overoptimistism, impatience people make/have/show/exhibit when applying, implementing, using and working with the below. Don't make mistakes and don't hallucinate. ### Part 1: Control Flow Graphs, Dominance, and Loops * **1.1 Basic Blocks and CFGs:** Formal definitions of basic blocks, leaders, control flow graph construction, predecessors, successors, and entry/exit nodes. * **1.2 Dominance Relations:** Definition of dominance ($d \text{ dom } n$), strict dominance ($sdom$), immediate dominance ($idom$). Dominator trees and their structural properties. * **1.3 Dominator Computation (Theory):** The Lengauer–Tarjan algorithm (1979); DFS spanning trees, semidominators, path compression, and $O(m \alpha(m, n))$ complexity. * **1.4 Practical Dominance in Modern Compilers:** The Cooper–Harvey–Kennedy (CHK) algorithm (2001); reverse postorder numbering, two-finger intersection function (`intersect`), iterative dataflow fixed-point, and engineering advantages in compilers like LLVM. * **1.5 Dominance Frontiers ($DF$):** Mathematical definition; Cytron et al.'s bottom-up dominator tree walk algorithm computing $DF_{local}$ and $DF_{up}$. * **1.6 Postdominance and Reverse Control Flow:** Postdominance relation ($pdom$), immediate postdominator ($ipdom$), postdominator trees. * **1.7 Natural Loops and Reducibility:** Back-edges ($n \to h$ where $h \text{ dom } n$), loop headers, loop nesting trees, preheaders. * **1.8 Reducible vs. Irreducible CFGs:** Characterization of reducible flow graphs; T1/T2 interval analysis; Hecht–Ullman Property (1974); handling irreducible multi-entry cycles via node splitting. * **1.9 Control Dependence:** Formal Definition (Ferrante, Ottenstein, and Warren); definition of control dependence via postdominance frontiers ($PDF$) on the reversed CFG. * **1.10 Program Dependence Graph (PDG):** Integrating data and control dependence edges. ### Part 2: Static Single Assignment (SSA) Form * **2.1 Motivation and Definitions:** Single definition property, referential transparency, version indexing, and sparse dataflow representations. * **2.2 $\phi$-Functions:** Operational semantics, non-linear evaluation at block entries, and argument binding to incoming CFG edges. * **2.3 SSA Flavors:** Minimal SSA, Pruned SSA (requiring global liveness analysis), and Semi-Pruned SSA (Briggs et al., 1998; using cross-block live variables). * **2.4 Sparse Analysis on SSA:** Why SSA linearizes analysis complexity and decouples dataflow from CFG size (foreshadowing SCCP). * **2.5 SSA Construction:** Iterated Dominance Frontiers ($IDF$); Cytron et al. $\phi$-node placement algorithm; variable renaming via DFS over the dominator tree using version stacks. * **2.6 Semi-Pruned SSA Construction:** Local liveness filtering prior to $IDF$ evaluation to suppress unneeded dead $\phi$-nodes. * **2.7 Memory to Register Promotion:** `mem2reg` pipeline, stack slot allocation analysis, alloca promotion. * **2.8 SSA Destruction (Out-of-SSA / De-SSA):** $\phi$-elimination via parallel copy insertion on incoming edges; critical edge splitting requirement. * *The Lost-Copy Problem:* Overwriting variables prior to reading their value across shared paths. * *The Swap Problem:* Cyclic dependencies between simultaneous $\phi$-copies requiring temporary register spills and permutation sequentialization algorithms. * **2.9 Conventional vs. Transformed SSA (CSSA vs. TSSA):** Coalescing interference graphs and live range splitting hazards. * **2.10 Scalar Replacement of Aggregates (SROA):** Splitting structures, aggregate arrays, and disjoint field tracking. ### Part 3: Data-Flow Analysis * **3.1 Global Optimization Foundations:** Transfer functions, execution paths, safe approximations. * **3.2 The Semi-Lattice Framework:** Bounded semi-lattices, meet ($\sqcap$) and join ($\sqcup$) operators, partial order ($\sqsubseteq$), $\top$, $\bot$. * **3.3 Monotone Frameworks and Convergence:** Monotonicity condition ($x \sqsubseteq y \implies f(x) \sqsubseteq f(y)$); fixed-point theorem of Knaster–Tarski extended to data-flow systems by Kam and Ullman; lattice height bounding termination; worklist algorithms; Meet-Over-Paths (MOP) vs. Maximum Fixed Point (MFP); the Kam–Ullman theorem showing $MFP \sqsubseteq MOP$ and equality under distributivity. * **3.4 Reaching Definitions:** Direction: forward; Meet: $\cup$; May analysis; gen/kill transfer functions. * **3.5 Live Variable Analysis:** Direction: backward; Meet: $\cup$; May analysis; use/def transfer functions. * **3.6 Available Expressions:** Direction: forward; Meet: $\cap$; Must analysis; evaluation/kill transfer functions. * **3.7 Very Busy Expressions:** Direction: backward; Meet: $\cap$; Must analysis; hoisting opportunities. * **3.8 Constant Propagation:** Constant lattice (Top, Constant $c$, Bottom); non-distributivity of the lattice over multiple variable branches. * **3.9 Sparse Conditional Constant Propagation (SCCP):** The Wegman and Zadeck (1991) algorithm; integrating constant folding with branch reachability; dual worklists (CFG flow edges and SSA edges); simultaneous elimination of unreachable blocks and dynamic constant folding. * **3.10 Fundamental Limits:** Undecidability of optimal analysis and Rice's Theorem. ### Part 4: Memory, Aliasing, and Points-To Analysis * **4.1 The Aliasing Problem:** Memory references as the fundamental optimization barrier; May-alias, Must-alias, No-alias relations. * **4.2 Categorization of Alias Analyses:** Flow-sensitivity, context-sensitivity, field-sensitivity, and heap modeling. * **4.3 Points-to Analysis Implementations:** * *Andersen’s Analysis (1994):* Inclusion-based, flow-insensitive, context-insensitive points-to analysis; constraint generation ($p = \&q$, $p = q$, $*p = q$, $p = *q$); dynamic transitive closure on constraint graphs; $O(N^3)$ computational complexity. * *Steensgaard’s Analysis (1996):* Unification-based points-to analysis; equality constraints solved via near-linear time Disjoint Set Union (Union-Find) in $O(N \alpha(N))$; precision trade-offs versus Andersen. * **4.4 Type-Based Alias Analysis (TBAA):** Strict aliasing semantics; C/C++ type inheritance and structural disambiguation in LLVM IR. * **4.5 The C99 `restrict` Qualifier:** Formal semantics, optimization scope, compiler assumptions, and silent miscompilation traps. * **4.6 Dependence Testing Foundations:** Array index expressions in loops; affine subscript equations; GCD test (Bézout's identity); Banerjee’s inequalities; exact integer linear programming via the Omega test. * **4.7 MemorySSA:** LLVM's unified memory modeling; `MemoryDef`, `MemoryUse`, and `MemoryPhi`; single virtual memory versioning; scaling compile-time alias queries. ### Part 5: Scalar Optimizations * **5.1 Value Numbering:** * *Local Value Numbering (LVN):* Basic block hash tables, symbolic expression evaluation, algebraic identities. * *Global Value Numbering (GVN):* Dominator-tree scoped hash-table value numbering (Click 1995). * *Congruence-based GVN (NewGVN):* Partition refinement algorithm; maintaining and splitting congruence classes (Alpern, Wegman, Zadeck 1988). * **5.2 Common Subexpression Elimination (CSE):** Dominance-based CSE (EarlyCSE) vs. GVN. * **5.3 Loop-Invariant Code Motion (LICM):** Hoisting loop-invariant scalar calculations and memory loads; loop preheader insertion and safety conditions. * **5.4 Partial Redundancy Elimination (PRE) and Lazy Code Motion (LCM):** Knoop, Rüthing, Steffen (1992); unifying CSE and LICM; availability, anticipability, earliest, and latest placement analyses; suppressing redundant computations while minimizing register pressure lifetimes. * **5.5 Dead Code Elimination (DCE vs. ADCE):** Standard mark-sweep DCE versus Aggressive Dead Code Elimination (ADCE); reversing control dependence using postdominator trees (Ferrante, Ottenstein, and Warren); discovering dead cycles and unused control flow. * **5.6 Copy Propagation:** Forwarding SSA definitions and eliminating redundant intermediate register transfers. * **5.7 Strength Reduction and Integer Math:** Replacing induction multiplications with additions; Granlund–Montgomery (1994) algorithm for fast division by invariant integers via reciprocal multiplication and shifts. * **5.8 Reassociation and Expression Trees:** Balancing associative arithmetic syntax trees for instruction-level parallelism. * **5.9 Floating-Point Optimization Semantics:** IEEE 754 non-associativity, signed zeros, NaN behaviors, subnormals; LLVM `fast-math` flags permissions menu (`nnan`, `ninf`, `nsz`, `arcp`, `contract`, `afn`, `reassoc`, `fast`). * **5.10 Instruction Combining and Peephole Optimizations:** Pattern matching and DAG rewriting. * **5.11 Memory Promotion Pipelines:** Detailed mechanics of `mem2reg` and SROA passes. ### Part 6: Loop Optimizations, Dependence Analysis, and Vectorization * **6.1 Loop-Carried Dependences:** Iteration vectors, distance vectors, direction vectors ($<, =, >, \le, \dots$), flow (RAW), anti (WAR), output (WAW), and input (RAR) dependences. * **6.2 LICM and Promotion:** Memory dependency checks and store-to-load forwarding within loop bodies. * **6.3 Induction Variables and SCEV:** Canonical induction variables; Scalar Evolution (SCEV); AddRec expressions; closed-form trip count computation; chains of recurrences. * **6.4 Classical Loop Restructuring:** Loop unrolling, unroll-and-jam, loop peeling, loop rotation (transforming `while` loops into guarded `do-while` loops). * **6.5 Loop Unswitching and Versioning:** Hoisting loop-invariant conditional branches; multiversioning loops guarded by runtime alias checks. * **6.6 Loop Interchange:** Reordering nested loop iterations; interchange legality constraints on dependence direction vectors (prohibition of lexicographically negative direction vectors). * **6.7 Loop Fusion and Fission:** Legality, maximizing cache reuse, and eliminating loop overhead. * **6.8 Tiered Dependence Testing Pipeline:** Hierarchical dependence analysis: 1. *GCD Test:* Solvability via Bézout's identity for affine Diophantine equations. 2. *Banerjee's Inequalities:* Extreme value testing on bounded continuous iteration intervals. 3. *Omega Test (William Pugh, 1991/1992):* Exact integer linear programming over Presburger arithmetic. * **6.9 Loop Tiling / Blocking:** Strip-mining and interchange; multi-dimensional iteration space tiling; cache hierarchy fitting (matrix multiplication $O(N^3) \to O(N^3 / \sqrt{M})$ cache misses); cache-oblivious algorithms. * **6.10 Auto-Vectorization (Loop Vectorizer):** SIMD vector factor ($VF$) and interleave factor ($IF$) selection; dependence legality (no backward loop-carried dependences with distance $< VF$); vectorizing reductions; parallel prefix scan algorithms (Hillis–Steele, Blelloch). * **6.11 Superword-Level Parallelism (SLP):** Larsen & Amarasinghe (2000); vectorizing straight-line code within basic blocks; seeding vector packs from stores and bottom-up/top-down isomorphism extension. * **6.12 Software Pipelining and Modulo Scheduling:** Iterative modulo scheduling (Rau, Lam); overlapping iterations of loop bodies across cycles; Initiation Interval ($II$); resource-constrained and recurrence-constrained bounds ($ResMII$, $RecMII$). * **6.13 The Polyhedral Model:** Affine transformation frameworks; iteration domains, access relations, scattering schedules; Pluto automatic polyhedral parallelizer. * **6.14 Software-Directed Prefetching:** Cache latency hiding for regular stride memory access patterns.

Drag to resize
Drag to resize
Drag to resize
Drag to resize
Drag to resize