Table of Contents
Fetching ...

Agentic Code Optimization via Compiler-LLM Cooperation

Benjamin Mikek, Danylo Vashchilenko, Bryan Lu, Panpan Xu

Abstract

Generating performant executables from high level languages is critical to software performance across a wide range of domains. Modern compilers perform this task by passing code through a series of well-studied optimizations at progressively lower levels of abstraction, but may miss optimization opportunities that require high-level reasoning about a program's purpose. Recent work has proposed using LLMs to fill this gap. While LLMs can achieve large speedups on some programs, they frequently generate code that is incorrect. In this work, we propose a method to balance the correctness of conventional compiler optimizations with the ``creativity'' of LLM-based code generation: compiler-LLM cooperation. Our approach integrates existing compiler optimization passes with LLM-based code generation at multiple levels of abstraction, retaining the best features of both types of code optimization. We realize our approach with a multi-agent system that includes (1) LLM-based optimization agents for each level of abstraction, (2) individual compiler constituents as tools, (3) an LLM-based test generation agent that probes the correctness and performance of generated code, and (4) a guiding LLM that orchestrates the other components. The strategy enables LLM-based optimization of input programs at multiple levels of abstraction and introduces a method for distributing computational budget between levels. Our extensive evaluation shows that compiler-LLM cooperation outperforms both existing compiler optimizations and level-specific LLM-based baselines, producing speedups up to 1.25x.

Agentic Code Optimization via Compiler-LLM Cooperation

Abstract

Generating performant executables from high level languages is critical to software performance across a wide range of domains. Modern compilers perform this task by passing code through a series of well-studied optimizations at progressively lower levels of abstraction, but may miss optimization opportunities that require high-level reasoning about a program's purpose. Recent work has proposed using LLMs to fill this gap. While LLMs can achieve large speedups on some programs, they frequently generate code that is incorrect. In this work, we propose a method to balance the correctness of conventional compiler optimizations with the ``creativity'' of LLM-based code generation: compiler-LLM cooperation. Our approach integrates existing compiler optimization passes with LLM-based code generation at multiple levels of abstraction, retaining the best features of both types of code optimization. We realize our approach with a multi-agent system that includes (1) LLM-based optimization agents for each level of abstraction, (2) individual compiler constituents as tools, (3) an LLM-based test generation agent that probes the correctness and performance of generated code, and (4) a guiding LLM that orchestrates the other components. The strategy enables LLM-based optimization of input programs at multiple levels of abstraction and introduces a method for distributing computational budget between levels. Our extensive evaluation shows that compiler-LLM cooperation outperforms both existing compiler optimizations and level-specific LLM-based baselines, producing speedups up to 1.25x.

Paper Structure

This paper contains 20 sections, 8 figures, 5 tables.

Figures (8)

  • Figure 1: Comparison between existing work (left) and our multi-level approach (right).
  • Figure 2: Motivating Example
  • Figure 3: Our multi-agent architecture, showing the guiding agent, testing agent, and level-specific optimization agents. The source and assembly agents follow the same design as the expanded IR agent.
  • Figure 4: Histogram of speedups produced by ACCLAIM and each level-specific baseline with $b=18, n = 2, k = 2$, scaled to show distribution of speedups. *Figure \ref{['fig:histo_tool']} omits one program with speedup $1384\times$ for clarity; see the example.
  • Figure 5: Source-level optimizations performed by ACCLAIM on benchmark p02644_s879314742.
  • ...and 3 more figures

Theorems & Definitions (5)

  • definition 1: Rewrite
  • definition 2: Lowering
  • definition 3: Compiler
  • definition 4: Level-Specific Agent
  • definition 5: Testing Agent