EquiBench: Benchmarking Large Language Models’ Understanding of Program Semantics via Equivalence Checking

Anjiang Wei, Jiannan Cao, Ran Li, Hongyu Chen, Yuhui Zhang, Ziheng Wang, Yuan Liu, Thiago S. F. X. Teixeira, Diyi Yang, Ke Wang, Alex AikenDL4C @ NeurIPS 2025

TL;DR

Large Language Models (LLMs) are increasingly used for code tasks, but do they understand code semantics? EquiBench is a new benchmark that tests this by asking if two programs are semantically equivalent (produce the same output for all inputs). The results show current LLMs struggle, often relying on superficial syntax rather than deep reasoning, highlighting a significant gap in their code understanding.

What Problem Does This Paper Address?

As LLMs become powerful tools in software engineering, a crucial question arises: are they truly grasping the meaning (semantics) of the code they process, or are they just good at pattern matching based on syntax? Existing benchmarks often focus on code generation or execution on specific inputs. However, to truly understand program semantics, a model needs to reason about all possible behaviors of a program. This paper tackles the challenge of evaluating this deeper understanding by introducing equivalence checking – determining if two programs, potentially written very differently, behave identically across all inputs. This is a fundamental problem in computer science, as program equivalence is generally undecidable, making it an inherently difficult task for LLMs.

Methods

The core of EquiBench lies in its novel approach to generating program pairs for equivalence checking. Instead of relying on simple syntactic edits, the authors leverage sophisticated program transformation techniques:

  • Program Analysis (Dead Code Elimination - DCE): Compilers remove code that doesn't affect program output. EquiBench uses this to create equivalent pairs by removing dead code and inequivalent pairs by removing live code.
  • Compiler Scheduling (CUDA): For CUDA programs, different scheduling strategies (like shared memory tiling) are applied to optimize performance. These transformations can alter the program's structure significantly while preserving semantic equivalence.
  • Superoptimization (x86-64): Superoptimizers find highly optimized, often non-obvious, instruction sequences that are semantically equivalent to the original code. This creates challenging pairs where syntactic similarity is low.
  • Algorithmic and Variable Renaming (Python): For competitive programming problems, pairs are generated by either changing the core algorithm (e.g., recursion vs. iteration) or by renaming variables to obscure the code's intent.

This automated pipeline ensures high-confidence labels and generates pairs with nontrivial difficulty, covering a wide range of semantic variations.

Datasets

The paper introduces EquiBench, a new benchmark consisting of 2,400 program pairs across four languages (Python, C, CUDA, x86-64) and six equivalence categories. This dataset is designed to be more challenging and systematic than existing equivalence checking benchmarks like EQBENCH (too small) and SeqCoBench (relies on superficial syntactic changes). EquiBench's pairs are generated through automated transformations, ensuring a broad spectrum of semantic differences.

Key Insights and Ideas

  • Equivalence Checking is a Hard Problem for LLMs: The benchmark reveals that even state-of-the-art LLMs struggle significantly with program equivalence, with top accuracies only modestly above random chance on the most challenging categories.
  • Syntax is a Crutch, Not a Crutch: LLMs often rely on syntactic similarity to predict equivalence. When programs are syntactically similar but semantically different, models tend to incorrectly label them as equivalent. Conversely, when programs are semantically equivalent but syntactically dissimilar, models often misclassify them as inequivalent.
  • Prompting Strategies Offer Limited Gains: Simple prompting techniques like few-shot learning and Chain-of-Thought (CoT) provide only marginal improvements, underscoring that the core issue is a lack of deep semantic understanding, not just prompt engineering.
  • Structural Transformations are Key to Difficulty: Categories involving complex transformations like compiler scheduling and superoptimization are significantly harder for LLMs, indicating that reasoning about structural changes is a major hurdle.

Key Results

  • Overall Accuracy is Modest: The best performing LLM achieved an overall accuracy of 82.3%, but in the most challenging categories (DCE and CUDA), the highest accuracies were only 63.8% and 76.2%, respectively, barely above the 50% random baseline.
  • Syntactic Similarity is Misleading: Models achieved much higher accuracy (up to 96.5%) on tasks involving purely syntactic changes like variable renaming (OJ_V category), highlighting their reliance on superficial features.
  • Bias Towards Inequity: Models exhibit a bias towards predicting "inequivalent" for pairs that are actually equivalent, particularly in CUDA and x86-64 categories. This is likely due to the significant structural differences introduced by transformations in these categories.
  • Scaling Helps, But Not Enough: Larger models generally perform better, showing consistent gains as parameter count increases, but this scaling does not overcome the fundamental difficulty of semantic reasoning.

Limitations and Future Work

  • Label Soundness: While the dataset generation relies on robust automated pipelines (compilers, superoptimizers), there's a small possibility of subtle bugs or edge cases leading to incorrect labels. Competitive programming submissions might also have inherent inaccuracies.
  • Extensibility: The modular design of EquiBench allows for future extension to more languages and equivalence categories.
  • Reasoning Trace Evaluation: The paper acknowledges the difficulty of verifying LLM reasoning traces and suggests future work in developing automated methods for this.
  • Future Training Directions: The authors propose several avenues for future LLM training, including distilling reasoning traces, scaling datasets, developing agentic approaches with execution feedback, and incorporating program analysis concepts. They also suggest that future benchmarks should focus on syntactically dissimilar but equivalent pairs, and syntactically similar but inequivalent pairs, to better diagnose LLM capabilities.

Summary updated

BibTeX
@inproceedings{wei2025equibench,
  author = {Anjiang Wei and Jiannan Cao and Ran Li and Hongyu Chen and Yuhui Zhang and Ziheng Wang and Yuan Liu and Thiago S. F. X. Teixeira and Diyi Yang and Ke Wang and Alex Aiken},
  title = {{EquiBench: Benchmarking Large Language Models’ Understanding of Program Semantics via Equivalence Checking}},
  booktitle = {DL4C @ NeurIPS},
  year = {2025},
  url = {https://openreview.net/forum?id=T6xzZvtEAv},
}
Figure