0%

s02 — Research Ratchet: LLVM + GCC Optimization Study

Goal

A ranked optimization-priority list for the optimizing tier (s19/s20), derived from what actually carries LLVM -O2/-O3 and where GCC goes further — filtered through what Ori’s AIMS facts make cheaper or unnecessary and charged for compile latency, peak memory, IR growth, and invalidation breadth as well as generated-code payoff.

Implementation Sketch

Read actual source under ~/projects/reference_repos/lang_repos/llvm-project/ and gcc/ (graph-first). Dossiers in content/:

  • LLVM pass-pipeline anatomy: the default/ pipeline composition (llvm/lib/Passes/PassBuilderPipelines.cpp), which passes dominate measured wins (inlining, SROA, GVN, InstCombine, LICM, loop opts, SLP/loop vectorize), inter-pass ordering constraints, repeated/fixpoint-style pass families, module-global analyses, and the measured time/RSS/IR-growth cost of each family on the Ori-shaped corpus. Use LLVM’s time-passes/statistics/pass-bisect facilities where applicable; do not infer cost from pipeline position.
  • LLVM heuristics mining: inline cost model, SROA limits, GVN scope, where heuristic constants encode decades of tuning — captured as TUNING QUESTIONS Ori must answer empirically on its own corpus (rosetta), not constants to copy.
  • LLVM test-intent mining protocol: how to read llvm/test/Transforms/* regression tests for INTENT (the invariant pinned) and port intent into BIR-pass tests — clean-room rule applies (intent, never text).
  • GCC study (study-only per s00 licensing doc): IPA framework (gcc/ipa-*.cc — inlining, CP, SRA, pure/const detection), VRP (gcc/tree-vrp.cc, ranger), vectorizer organization; capture which IPA ideas AIMS contracts already subsume (EffectSummary vs IPA pure/const; ReprPlan ranges vs VRP) and which are genuinely additive.
  • Output: optimization-priority list — ranked by expected payoff on Ori workloads, AIMS-fact leverage, verification burden, compile-cost envelope, worst-case growth shape, parallel/cache compatibility, and required dependency invalidation. Each candidate receives adopt/adapt/park criteria and a deterministic fuel unit; this list IS the s19 pass-roster input.

Constraints

  • GCC: read-only study, zero code reuse (GPLv3 + uniform zero-copy rule).
  • Every “pass X matters” or “pass X is expensive” claim cites either a pipeline-source position plus local measurement or a named external measurement; folklore claims are marked as such.
  • The study must name the LLVM-O3 pathologies Ori will not reproduce: open-ended saturation/fixpoint work, uncontrolled IR expansion, module-wide mutable analysis state, repeated whole-IR scans, and pass interactions whose marginal runtime gain does not justify compile cost. Findings are design inputs, not claims that every LLVM release exhibits every pathology.

Work Items

  • LLVM pass-pipeline and cost anatomy dossier (O2/O3 composition, ordering constraints, dominant passes, repeated/global work, per-family time/RSS/IR-growth measurements) with file:line citations.
  • LLVM heuristics dossier: inline/SROA/GVN/LICM cost-model questions reframed as Ori empirical-tuning questions tied to the rosetta corpus.
  • Test-intent mining protocol doc + a worked example (one LLVM transform test family ported as intent into a planned BIR-pass test shape).
  • GCC dossier: IPA/VRP/vectorizer study with an AIMS-subsumption table (already-have / additive / not-applicable per idea).
  • Ranked optimization-priority list for the optimizing tier with payoff, compile-cost envelope, deterministic fuel unit, growth bound, cache/parallel compatibility, and adopt/adapt/park verdict; consumed verbatim by s19 planning.