TL;DR
MLIRBench is a new execution-grounded benchmark designed to test whether Large Language Models (LLMs) actually understand the low-level logic of compiler Intermediate Representations (IRs). The study reveals a significant "reasoning gap": while top models like Gemini 3.1 Pro can often correctly guess if two programs are equivalent, they struggle to predict the actual numerical outputs or explain the underlying execution behavior.
What Problem Does This Paper Address?
LLMs have become surprisingly good at writing Python or C++, but do they actually "understand" the code, or are they just very sophisticated pattern matchers? This question is critical when dealing with compiler IRs like MLIR (Multi-Level Intermediate Representation).
Unlike high-level source code, IRs explicitly represent dataflow, tensor shapes, and memory movement. Reasoning about them requires a deep understanding of compiler semantics—for instance, knowing how a small change in an indexing map might completely change a tensor operation's result. Existing benchmarks mostly focus on source-level code generation or compilation success. MLIRBench addresses the lack of a rigorous, execution-validated framework to measure how well LLMs reason about the semantic impact of compiler transformations.
Methods
The authors developed a sophisticated multi-agent pipeline to build and evaluate the benchmark:
- Mutation Agent: Starting from a "seed" program, this agent generates variations across five levels of complexity, ranging from simple variable renaming (L1) to structural rewrites (L4) and intentional error-inducing bugs (L5).
- Execution Sandbox Agent: This is the source of ground truth. It uses the IREE compiler to verify, compile, and execute both the original and mutated programs on deterministic inputs. It labels pairs as EQUIV (same output), DIVERGE (different output), or ERROR (compilation/runtime failure).
- LLM Reasoning Agent: The model being tested receives the two MLIR programs and the inputs but is "blinded" to the execution results. It must predict the output of both programs and determine their relationship.
- Judge Agent: A separate LLM (GPT-4o-mini) acts as a judge, scoring the Reasoning Agent not just on the final label, but on the accuracy of its predicted outputs and the quality of its causal explanation.
Datasets
The benchmark originates from 40 manually curated PyTorch programs covering common patterns like reductions, tensor transforms, and boolean operations. These were lowered into two specific MLIR dialects: torch (closer to the source) and linalg (exposing low-level structured loops).
The final MLIRBench dataset consists of:
- 1,768 validated program pairs (888 linalg, 880 torch).
- Execution-derived labels (EQUIV, DIVERGE, ERROR).
- Detailed metadata, including mutation rules and execution traces.
Key Insights and Ideas
- The "Illusion of Understanding": The most striking finding is the gap between classification and execution reasoning. Models are much better at picking the right label (e.g., "these are equivalent") than they are at actually tracing the values through the IR to predict the final result.
- Bit-Exactness Matters: The authors enforced strict bit-exact equality for floating-point operations. Because floating-point math isn't associative, even a "safe" algebraic reordering can change the machine result. MLIRBench captures these subtle semantic shifts that human annotators might miss.
- Dialect Difficulty: Reasoning about the
linalgdialect is generally harder than thetorchdialect becauselinalgexposes complex indexing maps and iterator semantics that require more rigorous symbolic reasoning. - Supervision Transfer: The authors showed that MLIRBench isn't just for testing; it can be used for training. Fine-tuning a model on MLIRBench data significantly improved its ability to predict whether a compiler optimization (like fusion) would actually provide a performance benefit.
Key Results
The researchers evaluated nine models, including frontier models like Gemini 3.1 Pro and Claude 4.5, alongside open-weight models like Llama 4 and Qwen3.
- Top Performer: Gemini 3.1 Pro achieved the highest aggregate score (74.18/100) and a "hard-label" accuracy of 92.65%.
- The Reasoning Gap: While Gemini got the label right ~93% of the time, its result-behavior score (predicting actual outputs) was only 5.04/10. Other models fared even worse, often scoring below 4/10 on execution tracing.
- Mutation Sensitivity: Most models performed well on L1 (syntactic) changes but struggled significantly with L5 (error-inducing) mutations, except for Gemini, which showed strong compiler-error recognition.
Limitations and Future Work
- Dialect Coverage: Currently, the benchmark only covers
torchandlinalg. The authors plan to expand to other critical dialects likeaffine,gpu,vector, andmemref. - Program Diversity: The dataset is built from 40 seed programs. While mutations expand this significantly, the underlying algorithmic variety remains somewhat bounded.
- Fixed Environment: Ground truth is currently tied to the IREE compiler and specific hardware targets. Results might vary slightly across different backends.
- Future Directions: The authors suggest using the benchmark's failure signals to develop "compiler-aware" LLMs that can better assist in debugging and optimization-benefit prediction.
Summary updated