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.
Quick Start • Empirical Benchmarks • Why Autotune? • Architecture • CLI Reference • CI/CD Integration • Documentation
Compilers 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.
Autotune transforms compiler optimization from manual guesswork into a reproducible, developer-usable science:
Analyzes Workload AST : Extracts loop nesting, memory-to-compute ratios, branch density, and floating-point intensity without modifying source code.
2.
Flexible Baseline Benchmarking : Benchmarks against configurable baselines (-O0 ,-O1 ,-O2 ,-O3 , or-Os ) using nanosecond-precision monotonic hardware timers.
3.
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).
4.
Strict Pluggable Validation : Bitwise, numerical delta, and checksum execution guards guarantee that optimized binaries produce 100% correct outputs.
5.
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.
6.
Production Artifact Generation : Emits transformed IR (.optimized.ll ), assembly (.s ), native binaries (.bin ), CMake snippets, Makefiles, and standalone Shell compilation scripts.
Important
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 (
The 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:
| Workload Kernel | Problem Domain | Baseline Config | Baseline Time | Autotune Time | Confirmed Speedup | Evidence Grade | Primary Compiler Mechanics |
|---|---|---|---|---|---|---|---|
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 |
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 |
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-Body Gravity (nbody ) |
Astrophysics Particle Simulation | -O0 |
41.91 ms | 10.33 ms | 4.06× Gain | Grade A | SROA + Pairwise Force SIMD + Reassociation |
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 |
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 |
All runs evaluated with $N=10$ confirmation repetitions, 3 warmup iterations, CV noise $< 5.0%$, and $p < 0.0001$.
| Feature | Standard clang -O3 |
OpenTuner / GCC Plugins | CompilerGym | Autotune Doctor |
|---|---|---|---|---|
| Workload-Tailored Passes | ❌ Fixed Pipeline | ✅ Fully Automated GA + AI | ||
| LLVM NPM Support | ✅ Built-in | ❌ Legacy Pass Manager | ❌ Deprecated Pass Mgr | ✅ Full Modern NPM (LLVM 14-22) |
| Configurable Baselines | ❌ None | ❌ Ad-hoc | ❌ -O3 Only |
✅ -O0, -O1, -O2, -O3, -Os |
| Statistical Proof Engine | ❌ None | ❌ Mean/Median Only | ❌ Reward Score Only | ✅ Welch |
| Bitwise Output Verification | ❌ None | ❌ Emulated | ✅ Exact, Numeric, Checksum, Script | |
| Production Build Export | ❌ CLI Flags Only | ❌ Manual Shell Script | ❌ Python Object Only | ✅ CMake, Makefile, Shell, C Header |
| Zero-Knowledge Security | N/A | ❌ Plaintext configs | ❌ N/A | ✅ Native OS Keyring Isolation |
| CI Regression Gate | ❌ None | ❌ Custom Scripting | ❌ N/A | ✅ Native autotune guard with exit codes |
flowchart TD
A[C/C++ Workload Source] --> B[AST Feature Extraction & Profiling]
B --> C[Empirical Baseline Benchmarking: -O0 / -O1 / -O2 / -O3]
C --> D{Pipeline Seeding}
D -->|Offline Heuristics| E[Microarchitecture-Biased Hardware Seeds]
D -->|LLM Guidance| F[AI Pass Candidate Synthesis]
E --> G[Genetic Algorithm Phase-Order Evolution Engine]
F --> G
G --> H[LLVM Pipeline Compilation: clang -> opt NPM -> native binary]
H --> I[Pluggable Correctness Validation Gate]
I -->|Failed / Miscompiled| J[Automatic Discard & Crash Analysis]
I -->|Verified Correct| K[Fresh Multi-Sample Confirmation Benchmarking]
K --> L[Statistical Verification: Welch t-test, Mann-Whitney U, Cohen's d]
L --> M[Evidence Grading: Grade A / B / C / D / F]
M --> N[Structured JSON & Interactive Standalone HTML Reports]
N --> O[autotune apply / export / guard / reproduce]
pipx install autotune-doctor
pip install autotune-doctor
docker run --rm -v "$PWD:/work" ghcr.io/youknowme19/autotune doctor /work/kernel.c
brew install --HEAD packaging/homebrew/autotune.rb
git clone https://github.com/youknowme19/Autotune-The-Phase-Ordering-CLI-Doctor.git
cd Autotune-The-Phase-Ordering-CLI-Doctor
pip install -e ".[dev]"
autotune doctor
Autotune v0.5.0
Phase-Ordering CLI Doctor
System & Toolchain Diagnostics
┏━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Check Component ┃ Status ┃ Details ┃
┡━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ Python Version │ [OK] │ 3.11.15 │
│ OS & Architecture │ [OK] │ Darwin (arm64 - Apple Silicon) │
│ Clang Compiler │ [OK] │ /opt/homebrew/opt/llvm/bin/clang (v22.1.8) │
│ LLVM Opt Binary │ [OK] │ /opt/homebrew/opt/llvm/bin/opt (v22.1.8) │
│ Measurement Backend │ [OK] │ macOS high-precision monotonic timing │
└─────────────────────┴────────┴───────────────────────────────────────────────┘
autotune doctor examples/conv2d/kernel.c --preset quick --baseline -O0
╭──────────────────────────────────────────────────────────╮
│ AUTOTUNE DOCTOR │
│ AI-Guided LLVM Phase-Ordering Optimization & Diagnostics │
╰──────────────────────────────────────────────────────────╯
Analyzing kernel.c (Preset: quick)...
Gen 01/04 [━━━━━╸──────────────] | Best: 48.494 ms | Gain: 1.47x | Diversity: 1.00 | Valid: 8
Gen 02/04 [━━━━━━━━━━╸─────────] | Best: 48.494 ms | Gain: 1.47x | Diversity: 0.62 | Valid: 7
Gen 03/04 [━━━━━━━━━━━━━━━╸────] | Best: 48.037 ms | Gain: 1.48x | Diversity: 0.88 | Valid: 7
Gen 04/04 [━━━━━━━━━━━━━━━━━━━━╸] | Best: 45.998 ms | Gain: 1.55x | Diversity: 0.88 | Valid: 8
🏆 OPTIMIZATION FOUND
- Baseline (-O0): 71.217 ms
- Autotune Winner: 45.998 ms
- Confirmed Gain: 1.55× (Grade A — IMPROVED)
- Correctness: ✓ PASS
- Statistical p: 0.0000 (Cohen's d: 56.27)
Winning pass pipeline:
sroa → loop-rotate → licm → instcombine → loop-unroll
Artifacts:
- JSON Report: .autotune/runs/run_20260905_195221_f6b2f20b/report.json
- HTML Report: .autotune/runs/run_20260905_195221_f6b2f20b/report.html
Reproduce:
autotune reproduce .autotune/runs/run_20260905_195221_f6b2f20b/report.json
Flagship end-to-end workload optimization, evidence grading, and diagnostics.
autotune doctor <source> [OPTIONS]
Options:
-b, --baseline TEXT Baseline optimization level [-O0|-O1|-O2|-O3|-Os|-Oz] (default: -O3)
-p, --preset [quick|balanced|aggressive] Search preset budget (default: balanced)
-w, --workload PATH Path to stdin workload input file
--args TEXT Space-separated argv arguments passed to executable
--correctness-strategy [exitcode|numeric] Validation verification strategy
-o, --output-json PATH Path to export structured JSON report
--export-sh PATH Export standalone reproduction shell script
--cflags TEXT Extra compiler/linker flags (e.g. "-I./include -lm -march=native")
--compile-commands PATH Path to compile_commands.json to auto-extract project flags
--no-llm Enforce 100% offline heuristic search (zero network calls)
Real-World C/C++ Project Usage (CMake / Custom Headers / Libraries):
autotune doctor src/solver.cpp --cflags "-I./include -DFULL_PRECISION -lm -march=native"
autotune doctor src/solver.cpp --compile-commands build/compile_commands.json
Inspects AST structural complexity, loop depths, memory vs compute intensity, and suggests pass families.
autotune profile examples/matrix_transpose/kernel.c
autotune profile examples/matrix_transpose/kernel.c --json
Generates human-readable, scientifically grounded explanations of why the winning pass sequence outperformed baseline.
autotune explain .autotune/runs/run_latest/report.json
Explicitly deconstructs performance gains into:
- Observed Facts : Verified empirical runtimes, standard deviation, p-value, instruction delta.
- Inferred Compiler Mechanics : Concrete transformations executed by each LLVM pass.
- Hypothesized Synergies : Inter-pass interactions (e.g., SROA scalarization enabling loop vectorization).
Applies the winning pass pipeline and generates production compiler artifacts without mutating user source code.
autotune apply report.json --output-dir ./build/autotune/
Emits:
kernel.ll— Raw unoptimized LLVM IR.kernel.optimized.ll— Bitcode transformed by the winning pass sequence.kernel.s— Native target machine assembly.kernel.bin— Compiled native binary executable.manifest.json— Toolchain triple, SHA-256 provenance hashes, and exact compilation flags.
Exports reproducible compilation recipes into standard build systems.
autotune export report.json --format cmake -o autotune.cmake
autotune export report.json --format make -o Makefile.autotune
autotune export report.json --format shell -o build_optimized.sh
Continuous Integration performance gate preventing speed and correctness regressions.
autotune guard examples/matrix_transpose/kernel.c --reference report.json --threshold 0.03
autotune guard examples/matrix_transpose/kernel.c --reference report.json --strict-env --ci
Integrate Autotune directly into your GitHub Actions workflow to block regressions in pull requests:
name: Performance Regression Guard
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
autotune-guard:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install LLVM & Clang
run: sudo apt-get update && sudo apt-get install -y clang llvm llvm-dev
- name: Install Autotune
run: pip install autotune-doctor
- name: Verify Performance Gate
run: |
autotune guard src/kernel.c --reference benchmarks/golden_report.json --threshold 0.05 --ci
Autotune 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:
Welch's t-test : Parametric two-sample t-test for unequal variances ($p$ -value). #
Mann-Whitney U test : Non-parametric rank-sum test robust against timing outliers. #
Cohen's d : Standardized effect size quantifying practical optimization impact ($d > 0.8$ denotes large effect).
| Grade | Classification | Speedup ( | Statistical Criteria | Action |
|---|---|---|---|---|
| A | IMPROVED |
Eligible for Production & Knowledge Store | ||
| B | MODEST_GAIN |
Statistically significant minor improvement | ||
| C | NOISY_IMPROVEMENT |
Improvement observed but noisy | ||
| D | PARITY |
Indistinguishable from Baseline | Optimization neutral | |
| F | REGRESSION /FAIL |
Incorrect output, crash, or slowdown | Immediate Discard |
- Zero Secret Leakage : API keys stored via
autotune config keyringutilize native OS Keyring mechanisms (Keychainon macOS,SecretServiceon Linux) and are never logged, serialized into JSON reports, or committed. - 100% Offline Capability : With
--no-llm, Autotune runs entirely locally using AST heuristics and genetic algorithms with zero network calls. - Non-Destructive :
autotune applyoutputs to.autotune/artifacts/or custom directories; original source files are never altered.
Autotune is distributed under the Apache 2.0 License. See LICENSE for details.
If you use Autotune in your research or production systems, please cite:
@software{autotune_doctor_2026,
author = {Autotune Contributors},
title = {Autotune: AI-Guided LLVM Phase-Ordering Optimization & Diagnostics System},
year = {2026},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/youknowme19/Autotune-The-Phase-Ordering-CLI-Doctor}}
}