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
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