Abstract
Modern compilers rely on hand-crafted heuristics to guide optimization passes. These human-designed rules often struggle to adapt to the complexity of modern software and hardware and lead to high maintenance burden. To address this challenge, we present Magellan, an agentic framework that evolves the compiler pass itself by synthesizing executable C++ decision logic. Magellan couples an LLM coding agent with evolutionary search and autotuning in a closed loop of generation, evaluation on user-provided macro-benchmarks, and refinement, producing compact heuristics that integrate directly into existing compilers. Across several production optimization tasks, Magellan discovers policies that match or surpass expert baselines. In LLVM function inlining, Magellan synthesizes new heuristics that outperform decades of manual engineering for both binary-size reduction and end-to-end performance. In register allocation, it learns a concise priority rule for live-range processing that matches intricate human-designed policies on a large-scale workload. We also report preliminary results on XLA problems, demonstrating portability beyond LLVM with reduced engineering effort.
Introduction
Modern compilers like LLVM are the backbone of software performance, yet they rely heavily on hand-crafted heuristics to solve NP-hard problems such as function inlining and register allocation. These "rules of thumb" are designed by experts to balance complex trade-offs—for example, determining whether inlining a function will improve execution speed or cause excessive binary bloat.
As hardware and software become more heterogeneous, these manual rules become a maintenance nightmare and often fail to achieve maximum performance. While previous research has explored using Neural Networks (NNs) to replace these rules, NNs are difficult to integrate into production toolchains due to latency and infrastructure overhead. Magellan seeks a "middle ground": using AI to write the C++ code that humans would normally author, ensuring the result is high-performing, maintainable, and easy to deploy.
Methodology: The Magellan Loop
Magellan combines LLM creativity with systematic optimization through a four-stage closed loop:
- Policy Proposal: An LLM (specifically Gemini) acts as a coding agent. It modifies a compiler source file within designated
EVOLVE-BLOCKsections, proposing a C++ "policy template." Crucially, it leaves numerical thresholds as symbolic hyperparameters (e.g.,BaseThreshold). - Local Evaluation: The system recompiles the compiler with the new code and runs it against realistic macro-benchmarks to measure real-world metrics like binary size or execution time.
- Hyperparameter Tuning: While the high-level C++ logic remains fixed, an external autotuner (Google’s Vizier) iteratively tests different values for the symbolic hyperparameters to find the "sweet spot" for that specific logic.
- Feedback Incorporation: The performance scores, logs, and profiling data are fed back to the LLM, which uses evolutionary search to refine the C++ logic for the next generation.
This hierarchical search strategy—separating high-level logic design from low-level parameter tuning—is the key to Magellan's efficiency.
Key Results and Insights
Magellan was evaluated on production-scale workloads, including LLVM internal benchmarks and XLA tasks.
Function Inlining and Size Reduction
In function inlining for size, Magellan discovered that being more aggressive than humans (specifically inlining single-use functions) actually reduced total binary size. This is because inlining unlocks downstream optimizations like dead-code elimination that "conservative" human rules often miss.
Magellan achieved a 5.23% reduction in binary size over LLVM’s upstream heuristic. On a broader set of production binaries, it reached an average reduction of 8.79%, demonstrating strong domain generalization across search infrastructure and embedded workloads.
Performance and Efficiency
For performance-oriented inlining, Magellan surpassed the hand-tuned baseline by 0.61% on the clang benchmark—a significant gain for a mature, heavily optimized compiler. By using an autotuner for parameters, Magellan reduced the "invalid sample rate" (code that doesn't compile or work) by 5x compared to letting the LLM guess both logic and numbers simultaneously.
Simplicity Wins
For register allocation, Magellan converged on a surprisingly simple constant-value priority rule that matched the performance of intricate, human-designed policies. The evolved inlining policy was also roughly 15x shorter (143 lines vs. 2,115 lines) than the manual LLVM implementation, yet it proved more effective.
Conclusion and Future Work
Magellan demonstrates that agentic frameworks can autonomously discover production-grade compiler heuristics that are both compact and high-performing. Future work includes applying Magellan to "green-field" problems like GPU kernel mapping and NPU scheduling, where expert-crafted heuristics do not yet exist. Additionally, the authors aim to automate "feature discovery," where the LLM identifies new compiler variables to use in its decision logic.
Summary updated