Recent advances in Large Language Models (LLMs) have opened opportunities to apply high-level code transformations to the field of code optimization, and it has since emerged as one of the most fundamental tasks for LLMs to perform; however, at present, LLMs struggle to apply wide-ranging code optimization tasks due to both the complexity of the code and the inability to independently verify the correctness of the transformations. In this paper, we present the Trusted LLM (T-LLM) Compiler, which proposes an advancement in compiler technology through a collaborative effort involving high-level LLM code transformations, traditional compilers, and verification tools. Experimental results reveal that it can significantly improve code correctness when tested on a set of PolyBench/C benchmarks. Our approach facilitates iterative code optimization efforts with verification strategies that enable corrective actions. Through this approach, T-LLM Compiler achieves code optimization accuracy of up to 83.3% and a speedup of up to 16.1% on the PolyBench/C benchmarks, with the transformed code reaching an average of 26.7% speedup wrt standard baselines. Additionally, we release the project's source code to the open-source community.
Figures & tables
Figure 1. T-LLM Compiler AI-Assistance levels
Figure 2. Architecture of our code optimization and verification system. LLMs are shown in yellow, and other tools are shown in blue.
Kernel
Bisheng with O3 Flag
Bisheng with O2 Flag
GCC with O3 Flag
GCC with O2 Flag
durbin
0.005
0.005
0.005
0.005
lu
5.257
5.258
5.269
5.283
gramschmidt
3.911
3.975
3.884
3.941
ludcmp
5.257
5.23
5.243
5.229
trisolv
0.005
0.004
0.005
0.005
cholesky
2.711
2.71
2.712
2.712
Table 1. Kernels Execution Times in Seconds with Different Compilers and Flags
Experiment
Examples
Transformed Kernels
Accuracy
Average speedup
Average speedup of Correctly Transformed Kernels
Base Prompt
No examples
90.00%
80.00%
1.167
1.240
One-shot Prompt 1
Unrolling
86.67%
90.00%
1.091
1.122
One-shot Prompt 2
Jamming
73.33%
90.00%
1.109
1.175
One-shot Prompt 3
Tiling
83.33%
86.67%
1.112
1.163
One-shot Prompt 4
Interchange
76.67%
83.33%
1.161
1.267
One-shot Prompt 5
Distribution
76.67%
90.00%
1.035
1.055
Table 2. PolyBench/C results with different optimizer prompts using Qwen2.5 - 32B - Instruct as the LLM
LLM Model
Transformed Kernels
Accuracy
Average speedup
Average speedup of Correctly Transformed Kernels
CodeLlama - 7B
6.67%
100%
0.99
0.99
CodeLLama - 13B
10%
100%
0.97
0.74
Qwen2.5 - 32B
90%
100%
1.178
1.198
Table 3. Best PolyBench/C results with different LLMs
Existing evaluations of LLM-based code optimization primarily measure end-to-end speedup, obscuring whether a model actually performs the intended optimization. For compiled languages, this is especially problematic: observed gains may reflect transformations already recoverable by modern optimizing compilers rather than optimization behavior attributable to the model itself. We present PatternBench, a benchmark for studying compiler-transcendent optimization, i.e., performance improvements that remain after aggressive compiler optimization. PatternBench targets residual optimization opportunities across seven classes of transformations and pairs runtime evaluation with an AST-based optimization faithfulness analysis that verifies whether the intended optimization is realized in the generated program. Experiments with frontier, open-weight, and fine-tuned models show that runtime speedup alone provides an incomplete account of optimization capability. Optimization faithfulness is strongly associated with realized speedup, and fine-tuning improves both faithfulness and optimization effectiveness. These results suggest that evaluation of LLM-based code optimization should measure not only performance outcomes, but also whether the target transformation was successfully executed.
Wesley Lu, Runzhou Liu, Hongru Du +1
Georgia Institute of Technology · University of Virginia
Large language models (LLMs) can often generate functionally correct code, but their ability to produce efficient implementations for performance-critical systems tasks remains limited. Existing code benchmarks mainly emphasize correctness or algorithmic problem solving, while realistic systems-level optimization is still underexplored. To address this gap, we introduce PerfCodeBench, an executable benchmark for evaluating LLMs on high-performance code optimization. The tasks require system-level implementation choices, hardware-aware optimization, and careful handling of performance bottlenecks. Each task includes executable correctness checks, a baseline implementation, and a reference optimized solution. This allows us to evaluate both correctness and runtime-oriented efficiency. Our evaluation on a broad set of state-of-the-art LLMs shows a clear gap between model-generated code and expert-optimized implementations. The gap is especially large on tasks involving parallelism and GPU operations. Current models also show weaknesses in cross-language robustness and in consistently reaching expert-level efficiency. These results suggest that performance-aware evaluation are still needed. LLMs should move beyond generating merely correct code toward producing efficient systems software. We submit the benchmark data, evaluation infrastructure, and complete logs of all LLMs-generated code at https://anonymous.4open.science/r/perfcodebench-7CDE.
Optimizing compilers miss profitable transformations when their enabling semantics are absent from the analyzed program representation. We ask whether large language models (LLMs) can recover such semantics from heterogeneous C/C++ context and realize them as validated, contract-preserving artifacts. We introduce SeGaBench, an executable benchmark containing 100 synthetic and 20 source-backed cases spanning low-level assumptions, data-structure invariants, and high-level semantic lifting. Each case includes hidden enabling semantics, an oracle artifact, correctness and semantic validators, and a reproducible performance protocol. We evaluate five LLMs using five independent responses per case. The strongest model produces correct artifacts in 94.8% of responses, achieves at least 1.05x speedup in 83.3%, and obtains a performance success on 93.3% of cases. Nevertheless, correct artifacts often close only part of the oracle gap. These results show that LLMs can complement compiler analysis as speculative semantic proposers, provided that their artifacts are validated and evaluated.
Hailong Jiang, Feng Yu, Emran Hossain +4
School of Computer Science, Information, and Engineering Technology, Youngstown State University · Department of Computer Science, Kent State University · Department of Computer Science, Baylor University +1