NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Verified Code Transpilation with LLMs

Sahil Bhatia, Jie Qiu, Niranjan Hasabnis, Sanjit A. Seshia, Alvin Cheung

Abstract

Traditional verified lifting (VL) techniques—which transpile low-level legacy code into high-performance domain-specific languages (DSLs)—rely on symbolic program synthesis. While these methods provide formal correctness guarantees, they are often brittle, require extensive manual engineering, and struggle with complex arithmetic expressions. This paper presents LLMLIFT, a framework that leverages Large Language Models (LLMs) to automate verified lifting. By using Python as an intermediate representation and prompting LLMs to generate both code and formal correctness proofs (loop invariants), LLMLIFT achieves superior performance and scalability compared to state-of-the-art symbolic tools while reducing manual engineering effort by three orders of magnitude.

Introduction

To leverage modern hardware accelerators like GPUs and TPUs, developers frequently need to "lift" legacy code from general-purpose languages (e.g., C++, Java) into high-level Domain-Specific Languages (DSLs) such as Spark for distributed computing or TACO for tensor algebra. This process, known as transpilation, is critical for performance but notoriously difficult to execute manually without introducing bugs.

Verified Lifting (VL) emerged as a solution to automate this process by using symbolic program synthesis to find a target program and formally prove its functional equivalence to the source. However, traditional VL tools are "brittle." They require domain experts to write thousands of lines of complex heuristics for every new DSL and often fail when code expressions exceed a certain depth or complexity. LLMLIFT addresses these challenges by treating the LLM as a "proposer" and a theorem prover as a "verifier," combining the creative reasoning of neural models with the rigorous guarantees of formal methods.

The LLMLIFT Framework

LLMLIFT introduces a novel architecture that utilizes the general-purpose reasoning capabilities of LLMs to navigate the search space of program synthesis more efficiently than enumerative symbolic search.

Python as an Intermediate Representation (IR)

A significant barrier to using LLMs for transpilation is the lack of training data for niche or emerging DSLs. LLMLIFT bypasses this by defining the semantics of the target DSL within a Python-based environment. Because LLMs are highly proficient in Python, they can reason about the provided DSL operators as if they were standard library functions. This allows the framework to support new languages with minimal setup—requiring only about 100 lines of natural language and Python definitions compared to the 1,000+ lines of specialized code required by traditional lifters.

Joint Code and Proof Generation

Correctness is ensured through a two-phase prompting strategy. First, the system generates a "Program Summary" (the lifted code). Second, it prompts the LLM to generate loop invariants—logical statements that prove the equivalence between the source and target programs. These invariants are then passed to a formal verifier (such as Z3 or cvc5). If the theorem prover rejects the output, LLMLIFT enters a verification loop, using the error feedback to re-prompt the model for corrections.

Experimental Evaluation

The authors evaluated LLMLIFT across four diverse application domains using established benchmarks: Distributed Computing (Java-to-Spark), Network Packet Processing (C-to-Domino), Tensor Processing (C++-to-TACO), and Image Processing (C++-to-Tenspiler).

Performance and Speed

LLMLIFT demonstrated superior success rates across all benchmarks. In the Spark domain, it solved 44 out of 45 benchmarks, outperforming the symbolic tool MetaLift (40/45). In the TACO domain, it achieved a perfect 60/60 score, surpassing C2TACO (57/60). Furthermore, LLMLIFT was significantly faster, averaging a 6x speedup over symbolic competitors. For instance, Spark benchmarks were typically solved in under a minute, whereas MetaLift required an average of three minutes.

Scalability and Complexity

To test the limits of symbolic search, the authors created a synthetic scalability benchmark featuring high-depth arithmetic expressions (e.g., variables raised to the 20th power). Traditional tools using enumerative search fail in these scenarios because the search space explodes exponentially with expression depth. LLMLIFT, utilizing pattern recognition, solved 10/10 of these "hard" benchmarks in less than 2 seconds each. In contrast, the symbolic competitor C2TACO failed to solve a single instance within a 90-minute timeout.

Discussion and Limitations

While LLMLIFT represents a significant advancement, it is not without limitations. The system occasionally suffers from "syntactic hallucinations," where the LLM utilizes Python features (like specific list comprehensions) that the underlying theorem prover cannot yet interpret. Additionally, the system's success is sensitive to prompt engineering; the clarity with which DSL semantics are described directly impacts the model's ability to generate verifiable code. Future work will focus on extending the framework to handle more complex, pointer-heavy data structures and deeply nested loop architectures.

Conclusion

LLMLIFT demonstrates that LLMs can serve as powerful engines for formal program synthesis when paired with a rigorous verification loop. By shifting the burden of search from brittle symbolic algorithms to generative models, LLMLIFT achieves higher accuracy, faster execution, and a radical reduction in the engineering effort required to build verified compilers for new domains.

Summary updated

BibTeX
@inproceedings{bhatia2024verified,
  author = {Sahil Bhatia and Jie Qiu and Niranjan Hasabnis and Sanjit A. Seshia and Alvin Cheung},
  title = {{Verified Code Transpilation with LLMs}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=spwE9sLrfg},
}
Figure