{"slug": "show-hn-autotune-genetic-llvm-phase-ordering-cli-that-beats-clang-o3", "title": "Show HN: Autotune – Genetic LLVM phase-ordering CLI that beats Clang -O3", "summary": "A developer released Autotune, an open-source CLI that uses genetic search over LLVM New Pass Manager phase orderings to build workload-specific pass pipelines, reporting a 13.56× speedup on a 2D convolution kernel (68.90 ms at -O0 down to 5.08 ms) and a 12.58× gain on PolyBench GEMM (227.26 ms to 18.07 ms). Autotune benchmarks against configurable baselines from -O0 to -Os, validates candidates with bitwise, numerical-delta and checksum guards, and re-tests winners with Welch's t-test, Mann-Whitney U, Cohen's d and coefficient-of-variation noise gates before emitting optimized IR, assembly, binaries, CMake snippets and Makefiles. The tool targets compute-intensive kernels on Apple Silicon NEON, AMD Zen and Intel AVX-512, where fixed general-purpose pipelines such as Clang's -O3 are suboptimal because optimization passes are interdependent and non-commutative.", "body_md": "**A production-grade, AI-guided compiler optimization and diagnostics system that systematically searches, validates, and mathematically proves workload-specific LLVM pass pipelines to outperform standard `-O3`.**\n\n[Quick Start](#-quick-start) •\n[Empirical Benchmarks](#-empirical-proof-benchmarks) •\n[Why Autotune?](#-why-autotune-vs-status-quo) •\n[Architecture](#-system-workflow-architecture) •\n[CLI Reference](#-cli-command-reference) •\n[CI/CD Integration](#-continuous-integration-guard-gate) •\n[Documentation](https://github.com/youknowme19/Autotune-The-Phase-Ordering-CLI-Doctor/blob/main/docs)\n\nCompilers like Clang and GCC use fixed, general-purpose pass pipelines (such as `-O3` or `-O2`). While these standard pipelines perform acceptably across millions of disparate software projects, **they are fundamentally suboptimal for any specific compute-intensive workload**. Because compiler optimizations are interdependent and non-commutative—a phenomenon known in computer science as the *Phase-Ordering Problem*—applying Pass A before Pass B can either unlock massive SIMD vectorization or permanently destroy vectorization opportunities.\n\n**Autotune transforms compiler optimization from manual guesswork into a reproducible, developer-usable science:**\n\n1. \n**Analyzes Workload AST** : Extracts loop nesting, memory-to-compute ratios, branch density, and floating-point intensity without modifying source code.\n2. \n**Flexible Baseline Benchmarking** : Benchmarks against configurable baselines (`-O0` ,`-O1` ,`-O2` ,`-O3` , or`-Os` ) using nanosecond-precision monotonic hardware timers.\n3. \n**Genetic Phase-Ordering Search** : Evolves custom sequences of LLVM New Pass Manager (NPM) transformations tailored to your exact silicon microarchitecture (Apple Silicon NEON, AMD Zen, Intel AVX-512).\n4. \n**Strict Pluggable Validation** : Bitwise, numerical delta, and checksum execution guards guarantee that optimized binaries produce 100% correct outputs.\n5. \n**Rigorous Statistical Proof** : Re-evaluates winners with Welch’s t-test, Mann-Whitney U rank-sum tests, Cohen's$d$ effect sizes, and Coefficient of Variation (`CV%` ) noise gates.\n6. \n**Production Artifact Generation** : Emits transformed IR (`.optimized.ll` ), assembly (`.s` ), native binaries (`.bin` ), CMake snippets, Makefiles, and standalone Shell compilation scripts.\n\nImportant\n\n**Zero Data Fabrication Policy**: All speedups and benchmarks reported by Autotune are derived from **real empirical execution** on physical silicon. The language model is never the final authority—hypotheses must survive execution verification, multi-sample confirmation, and statistical significance testing (\n\nThe following table presents real, un-fabricated benchmark results measured across curated workloads on Apple Silicon (ARM64) and Linux (x86_64) using LLVM New Pass Manager. Every result is backed by independent multi-sample re-benchmarking, bitwise correctness checks, and Welch's t-test statistical validation:\n\n| Workload Kernel | Problem Domain | Baseline Config | Baseline Time | Autotune Time | Confirmed Speedup | Evidence Grade | Primary Compiler Mechanics | \n|---|---|---|---|---|---|---|---|\n| **2D Convolution** (`conv2d` ) | Computer Vision / Image Filtering | `-O0` | 68.90 ms | **5.08 ms** | 13.56× Gain | **Grade A** | SROA + Loop Rotate + LICM + Vectorize + Unroll | \n| **PolyBench GEMM** (`gemm` ) | Linear Algebra Matrix Multiplication | `-O0` | 227.26 ms | **18.07 ms** | 12.58× Gain | **Grade A** | SLP Vectorizer + Early-CSE + GVN + Loop Vectorize | \n| **PolyBench BiCG** (`bicg` ) | BiConjugate Gradient Linear Solver | `-O0` | 15.32 ms | **3.21 ms** | 4.77× Gain | **Grade A** | Kernel Loop Pipelining + Interleaved Vectorization | \n| **N-Body Gravity** (`nbody` ) | Astrophysics Particle Simulation | `-O0` | 41.91 ms | **10.33 ms** | 4.06× Gain | **Grade A** | SROA + Pairwise Force SIMD + Reassociation | \n| **Dense Matrix Mult** (`matrix_mult` ) | Scientific Computing / HPC | `-O0` | 46.70 ms | **12.60 ms** | 3.71× Gain | **Grade A** | Loop Flattening + LICM + Invariant Hoisting | \n| **Matrix Transpose** (`matrix_transpose` ) | Cache Locality / Strided Memory | **`-O3`** | 38.48 ms | **28.64 ms** | 1.34× Gain (+30.2%) | **Grade A** | Stride Restructuring over `-O3` + Memory SSA LICM | \n\n*All runs evaluated with $N=10$ confirmation repetitions, 3 warmup iterations, CV noise $< 5.0%$, and $p < 0.0001$.*\n\n| Feature | Standard `clang -O3` | OpenTuner / GCC Plugins | CompilerGym | **Autotune Doctor** | \n|---|---|---|---|---|\n| **Workload-Tailored Passes** | ❌ Fixed Pipeline |  |  | **✅ Fully Automated GA + AI** | \n| **LLVM NPM Support** | ✅ Built-in | ❌ Legacy Pass Manager | ❌ Deprecated Pass Mgr | **✅ Full Modern NPM (LLVM 14-22)** | \n| **Configurable Baselines** | ❌ None | ❌ Ad-hoc | ❌ `-O3` Only | **✅ `-O0`, `-O1`, `-O2`, `-O3`, `-Os`** | \n| **Statistical Proof Engine** | ❌ None | ❌ Mean/Median Only | ❌ Reward Score Only | **✅ Welch**  | \n| **Bitwise Output Verification** | ❌ None |  | ❌ Emulated | **✅ Exact, Numeric, Checksum, Script** | \n| **Production Build Export** | ❌ CLI Flags Only | ❌ Manual Shell Script | ❌ Python Object Only | **✅ CMake, Makefile, Shell, C Header** | \n| **Zero-Knowledge Security** | N/A | ❌ Plaintext configs | ❌ N/A | **✅ Native OS Keyring Isolation** | \n| **CI Regression Gate** | ❌ None | ❌ Custom Scripting | ❌ N/A | **✅ Native `autotune guard` with exit codes** | \n\n``` php\nflowchart TD\n    A[C/C++ Workload Source] --> B[AST Feature Extraction & Profiling]\n    B --> C[Empirical Baseline Benchmarking: -O0 / -O1 / -O2 / -O3]\n    C --> D{Pipeline Seeding}\n    D -->|Offline Heuristics| E[Microarchitecture-Biased Hardware Seeds]\n    D -->|LLM Guidance| F[AI Pass Candidate Synthesis]\n    E --> G[Genetic Algorithm Phase-Order Evolution Engine]\n    F --> G\n    G --> H[LLVM Pipeline Compilation: clang -> opt NPM -> native binary]\n    H --> I[Pluggable Correctness Validation Gate]\n    I -->|Failed / Miscompiled| J[Automatic Discard & Crash Analysis]\n    I -->|Verified Correct| K[Fresh Multi-Sample Confirmation Benchmarking]\n    K --> L[Statistical Verification: Welch t-test, Mann-Whitney U, Cohen's d]\n    L --> M[Evidence Grading: Grade A / B / C / D / F]\n    M --> N[Structured JSON & Interactive Standalone HTML Reports]\n    N --> O[autotune apply / export / guard / reproduce]\n# Recommended (isolated CLI install via pipx):\npipx install autotune-doctor\n\n# Or via pip:\npip install autotune-doctor\n\n# Or zero-setup Docker (includes LLVM/Clang toolchain):\ndocker run --rm -v \"$PWD:/work\" ghcr.io/youknowme19/autotune doctor /work/kernel.c\n\n# Or Homebrew (macOS / Linux):\nbrew install --HEAD packaging/homebrew/autotune.rb\n\n# Or install latest developer build from source:\ngit clone https://github.com/youknowme19/Autotune-The-Phase-Ordering-CLI-Doctor.git\ncd Autotune-The-Phase-Ordering-CLI-Doctor\npip install -e \".[dev]\"\nautotune doctor\nAutotune v0.5.0\nPhase-Ordering CLI Doctor\n\n                         System & Toolchain Diagnostics                         \n┏━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n┃ Check Component     ┃ Status ┃ Details                                       ┃\n┡━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩\n│ Python Version      │ [OK]   │ 3.11.15                                       │\n│ OS & Architecture   │ [OK]   │ Darwin (arm64 - Apple Silicon)                │\n│ Clang Compiler      │ [OK]   │ /opt/homebrew/opt/llvm/bin/clang (v22.1.8)    │\n│ LLVM Opt Binary     │ [OK]   │ /opt/homebrew/opt/llvm/bin/opt (v22.1.8)      │\n│ Measurement Backend │ [OK]   │ macOS high-precision monotonic timing         │\n└─────────────────────┴────────┴───────────────────────────────────────────────┘\nautotune doctor examples/conv2d/kernel.c --preset quick --baseline -O0\n╭──────────────────────────────────────────────────────────╮\n│ AUTOTUNE DOCTOR                                          │\n│ AI-Guided LLVM Phase-Ordering Optimization & Diagnostics │\n╰──────────────────────────────────────────────────────────╯\nAnalyzing kernel.c (Preset: quick)...\n  Gen 01/04 [━━━━━╸──────────────] | Best:  48.494 ms | Gain:  1.47x | Diversity: 1.00 | Valid: 8\n  Gen 02/04 [━━━━━━━━━━╸─────────] | Best:  48.494 ms | Gain:  1.47x | Diversity: 0.62 | Valid: 7\n  Gen 03/04 [━━━━━━━━━━━━━━━╸────] | Best:  48.037 ms | Gain:  1.48x | Diversity: 0.88 | Valid: 7\n  Gen 04/04 [━━━━━━━━━━━━━━━━━━━━╸] | Best:  45.998 ms | Gain:  1.55x | Diversity: 0.88 | Valid: 8\n\n🏆 OPTIMIZATION FOUND\n  - Baseline (-O0):  71.217 ms\n  - Autotune Winner: 45.998 ms\n  - Confirmed Gain:  1.55× (Grade A — IMPROVED)\n  - Correctness:     ✓ PASS\n  - Statistical p:   0.0000 (Cohen's d: 56.27)\n\nWinning pass pipeline:\n  sroa → loop-rotate → licm → instcombine → loop-unroll\n\nArtifacts:\n  - JSON Report: .autotune/runs/run_20260905_195221_f6b2f20b/report.json\n  - HTML Report: .autotune/runs/run_20260905_195221_f6b2f20b/report.html\n\nReproduce:\n  autotune reproduce .autotune/runs/run_20260905_195221_f6b2f20b/report.json\n```\n\nFlagship end-to-end workload optimization, evidence grading, and diagnostics.\n\n```\nautotune doctor <source> [OPTIONS]\n\nOptions:\n  -b, --baseline TEXT                   Baseline optimization level [-O0|-O1|-O2|-O3|-Os|-Oz] (default: -O3)\n  -p, --preset [quick|balanced|aggressive] Search preset budget (default: balanced)\n  -w, --workload PATH                   Path to stdin workload input file\n  --args TEXT                           Space-separated argv arguments passed to executable\n  --correctness-strategy [exitcode|numeric] Validation verification strategy\n  -o, --output-json PATH                Path to export structured JSON report\n  --export-sh PATH                      Export standalone reproduction shell script\n  --cflags TEXT                         Extra compiler/linker flags (e.g. \"-I./include -lm -march=native\")\n  --compile-commands PATH               Path to compile_commands.json to auto-extract project flags\n  --no-llm                              Enforce 100% offline heuristic search (zero network calls)\n```\n\n**Real-World C/C++ Project Usage (CMake / Custom Headers / Libraries):**\n\n```\n# Pass custom include paths, macros, and libraries directly:\nautotune doctor src/solver.cpp --cflags \"-I./include -DFULL_PRECISION -lm -march=native\"\n\n# Or auto-extract flags from your CMake/Meson/Bear compilation database:\nautotune doctor src/solver.cpp --compile-commands build/compile_commands.json\n```\n\nInspects AST structural complexity, loop depths, memory vs compute intensity, and suggests pass families.\n\n```\nautotune profile examples/matrix_transpose/kernel.c\n# Machine-readable JSON output for tooling pipelines:\nautotune profile examples/matrix_transpose/kernel.c --json\n```\n\nGenerates human-readable, scientifically grounded explanations of why the winning pass sequence outperformed baseline.\n\n```\nautotune explain .autotune/runs/run_latest/report.json\n```\n\nExplicitly deconstructs performance gains into:\n\n- **Observed Facts** : Verified empirical runtimes, standard deviation, p-value, instruction delta.\n- **Inferred Compiler Mechanics** : Concrete transformations executed by each LLVM pass.\n- **Hypothesized Synergies** : Inter-pass interactions (e.g., SROA scalarization enabling loop vectorization).\n\nApplies the winning pass pipeline and generates production compiler artifacts without mutating user source code.\n\n```\nautotune apply report.json --output-dir ./build/autotune/\n```\n\nEmits:\n\n- `kernel.ll` — Raw unoptimized LLVM IR.\n- `kernel.optimized.ll` — Bitcode transformed by the winning pass sequence.\n- `kernel.s` — Native target machine assembly.\n- `kernel.bin` — Compiled native binary executable.\n- `manifest.json` — Toolchain triple, SHA-256 provenance hashes, and exact compilation flags.\n\nExports reproducible compilation recipes into standard build systems.\n\n```\n# Export CMake integration snippet:\nautotune export report.json --format cmake -o autotune.cmake\n\n# Export Makefile snippet:\nautotune export report.json --format make -o Makefile.autotune\n\n# Export standalone shell script:\nautotune export report.json --format shell -o build_optimized.sh\n```\n\nContinuous Integration performance gate preventing speed and correctness regressions.\n\n```\n# Fail CI build if candidate regresses by more than 3%:\nautotune guard examples/matrix_transpose/kernel.c --reference report.json --threshold 0.03\n\n# Strict environment mode (fails if CPU architecture or LLVM major version changes):\nautotune guard examples/matrix_transpose/kernel.c --reference report.json --strict-env --ci\n```\n\nIntegrate Autotune directly into your GitHub Actions workflow to block regressions in pull requests:\n\n```\nname: Performance Regression Guard\n\non:\n  push:\n    branches: [ main ]\n  pull_request:\n    branches: [ main ]\n\njobs:\n  autotune-guard:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v4\n      - uses: actions/setup-python@v5\n        with:\n          python-version: \"3.11\"\n      - name: Install LLVM & Clang\n        run: sudo apt-get update && sudo apt-get install -y clang llvm llvm-dev\n      - name: Install Autotune\n        run: pip install autotune-doctor\n      - name: Verify Performance Gate\n        run: |\n          autotune guard src/kernel.c --reference benchmarks/golden_report.json --threshold 0.05 --ci\n```\n\nAutotune does not rely on single-run measurements. Every candidate is evaluated using interleaved runs, Coefficient of Variation (`CV%`) noise checks, and non-parametric statistical tests:\n\n- \n**Welch's t-test** : Parametric two-sample t-test for unequal variances ($p$ -value).\n- \n**Mann-Whitney U test** : Non-parametric rank-sum test robust against timing outliers.\n- \n**Cohen's d** : Standardized effect size quantifying practical optimization impact ($d > 0.8$ denotes large effect).\n\n| Grade | Classification | Speedup ( | Statistical Criteria | Action | \n|---|---|---|---|---|\n| **A** | `IMPROVED` |  |  | Eligible for Production & Knowledge Store | \n| **B** | `MODEST_GAIN` |  |  | Statistically significant minor improvement | \n| **C** | `NOISY_IMPROVEMENT` |  |  | Improvement observed but noisy | \n| **D** | `PARITY` |  | Indistinguishable from Baseline | Optimization neutral | \n| **F** | `REGRESSION` /`FAIL` |  | Incorrect output, crash, or slowdown | Immediate Discard | \n\n- **Zero Secret Leakage** : API keys stored via`autotune config keyring` utilize native OS Keyring mechanisms (`Keychain` on macOS,`SecretService` on Linux) and are never logged, serialized into JSON reports, or committed.\n- **100% Offline Capability** : With`--no-llm` , Autotune runs entirely locally using AST heuristics and genetic algorithms with zero network calls.\n- **Non-Destructive** :`autotune apply` outputs to`.autotune/artifacts/` or custom directories; original source files are never altered.\n\nAutotune is distributed under the **Apache 2.0 License**. See [LICENSE](https://github.com/youknowme19/Autotune-The-Phase-Ordering-CLI-Doctor/blob/main/LICENSE) for details.\n\nIf you use Autotune in your research or production systems, please cite:\n\n```\n@software{autotune_doctor_2026,\n  author = {Autotune Contributors},\n  title = {Autotune: AI-Guided LLVM Phase-Ordering Optimization & Diagnostics System},\n  year = {2026},\n  publisher = {GitHub},\n  journal = {GitHub repository},\n  howpublished = {\\url{https://github.com/youknowme19/Autotune-The-Phase-Ordering-CLI-Doctor}}\n}\n```\n\n", "url": "https://wpnews.pro/news/show-hn-autotune-genetic-llvm-phase-ordering-cli-that-beats-clang-o3", "canonical_source": "https://github.com/youknowme19/Autotune-The-Phase-Ordering-CLI-Doctor", "published_at": "2026-12-06 17:50:37+00:00", "updated_at": "2026-12-06 18:15:55.973161+00:00", "lang": "en", "topics": ["developer-tools", "artificial-intelligence", "ai-tools"], "entities": ["Autotune", "LLVM", "Clang", "GCC", "Apple Silicon", "AMD Zen", "Intel AVX-512", "PolyBench"], "also_reported_by": [], "takeaway": "Autotune's genetic search over LLVM New Pass Manager orderings cut a 2D convolution kernel from 68.90 ms at -O0 to 5.08 ms and PolyBench GEMM from 227.26 ms to 18.07 ms, with every candidate gated by bitwise correctness checks and Welch's t-test before acceptance.", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/show-hn-autotune-genetic-llvm-phase-ordering-cli-that-beats-clang-o3", "markdown": "https://wpnews.pro/news/show-hn-autotune-genetic-llvm-phase-ordering-cli-that-beats-clang-o3.md", "text": "https://wpnews.pro/news/show-hn-autotune-genetic-llvm-phase-ordering-cli-that-beats-clang-o3.txt", "jsonld": "https://wpnews.pro/news/show-hn-autotune-genetic-llvm-phase-ordering-cli-that-beats-clang-o3.jsonld"}}