SemOpt: LLM-Driven Code Optimization via Rule-Based Analysis

Read full text
Authors: Yuwei Zhao, Yuan-an Xiao, Qianyu Xiao, Zhao Zhang, Yingfei Xiong
Cited by: 0

Abstract

Automated code optimization improves program performance through refactoring, and recent studies leverage LLMs for this purpose. Existing approaches mine optimization commits from open-source codebases to build large-scale knowledge bases, then employ retrieval techniques such as BM25 to obtain relevant examples for hotspot code, guiding LLMs in optimization. However, semantically equivalent optimizations often appear in syntactically dissimilar code, so current retrieval methods fail to identify pertinent examples, leading to suboptimal results. To address these limitations, we propose SemOpt, a framework that leverages static program analysis to identify code segments, retrieve optimization strategies, and generate optimized results. SemOpt has three LLM-powered components: (1) a strategy library builder that extracts and clusters strategies from code modifications, (2) a rule generator that produces Semgrep static analysis rules to capture each strategy's applicability, and (3) an optimizer that generates optimized code using the strategy library. On a benchmark of 151 C/C++ and 150 Python optimization tasks, SemOpt shows consistent improvements across different LLMs, increasing successful optimizations by 1.38 to 28 times on C/C++ and 4.60 to 6.33 times on Python versus the baseline. On large-scale projects, SemOpt improves performance metrics by 5.04%–218.07% on C/C++ and 61.77%–479.90% on Python, showing cross-language generalization and practical effectiveness.

Fields of Study & Subjects

Software Engineering Research Logic programming and type systems Advanced Software Engineering Methodologies

Publication details

Journal / source
ACM Transactions on Software Engineering and Methodology
Publication date
12 June 2026
Language
EN