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

Learning Execution through Neural Code fusion

Zhan Shi, Kevin Swersky, Daniel Tarlow, Parthasarathy Ranganathan, Milad Hashemi

TL;DR

Neural Code Fusion (NCF) is a novel approach that "teaches" machine learning models how programs execute by fusing static assembly code with dynamic runtime snapshots (registers and memory) into a single Graph Neural Network (GNN). By bridging the gap between what code looks like and how it actually behaves, NCF achieves a 26% improvement in branch prediction and a 45% boost in memory prefetching over state-of-the-art methods.

The Problem: Hitting the Hardware Ceiling

As Moore’s Law slows down, hardware can no longer provide the "free" exponential performance gains it once did. To keep computing fast, we need smarter software optimizations and hardware predictors.

The authors identify a major gap in how AI currently handles code: most existing models focus purely on static representations—the text of the source code. However, static code doesn't tell the whole story. A single line of code might behave entirely differently depending on the data it processes at runtime.

Traditional hardware predictors for tasks like branch prediction (deciding which way an if statement will go) and prefetching (guessing which data to load into the cache next) rely on simple history-based heuristics. These heuristics are hitting a performance ceiling because they don't truly "understand" the program logic or the complex data structures being manipulated.

Neural Code Fusion (NCF) Methodology

To solve this, the researchers introduced Neural Code Fusion (NCF), an architecture designed to capture both the structure and the live execution state of a program.

Neural Code Fusion Architecture

NCF utilizes four key components to achieve this fusion:

  1. Low-Level Graph Representation: Instead of high-level source code (like C++), NCF uses x86 assembly. Assembly is more uniform and makes operations like register reads and memory accesses explicit, which is easier for a model to digest. This is represented as a graph where nodes are instructions or variables, and edges represent control flow or data usage.
  2. Dynamic Snapshots: This is the core "fusion" step. During execution, NCF takes snapshots of the CPU's general-purpose registers and recently used memory states.
  3. Binary Embeddings: A key technical insight was representing these dynamic values as binary bit-patterns rather than raw scalars or categories. This allows the GNN to learn the hierarchical structure of data (e.g., how bits change in a counter) and generalize to values it hasn't seen before.
  4. Multi-Task Gated GNN (GGNN): A Gated Graph Neural Network propagates information through the fused graph. The model is trained to perform multiple tasks simultaneously, such as predicting the next branch direction and the next memory address to be accessed.

Datasets and Evaluation

The model was evaluated using SPEC CPU2006, an industry-grade benchmark suite used to evaluate computer system performance, generating millions of execution snapshots via the Pin dynamic instrumentation tool. Additionally, an Algorithm Classification Dataset of 15 different programming problems (e.g., sorting, linked lists) was used to test if the model's learned "understanding" of code could transfer to completely different tasks.

Key Insights and Ideas

  • Execution Context is King: Static code is just a blueprint; execution is the actual building. By feeding the model the actual values in registers, the GNN can "see" the state of a loop or the contents of a pointer, making its predictions far more grounded.
  • The Power of Binary: Binary representations proved superior for generalization. If a model sees a counter go from 1 to 40 in training, a scalar representation might struggle with 41. A binary representation, however, understands the underlying bit-flipping logic, allowing it to generalize to much larger, unseen values.
  • Assembly as a Lingua Franca: High-level code has too much "style" (e.g., for vs while loops, or if-else vs ternary operators). Assembly strips this away, providing a tighter, more semantically consistent representation for the neural network.
Mapping High-Level Code to Assembly
  • Transfer Learning for Code: Perhaps the most surprising finding was that a model trained to predict branches (a low-level hardware task) learned enough about program logic to classify high-level algorithms with 96% accuracy, outperforming models trained specifically on massive amounts of source code.

Key Results

NCF demonstrated significant improvements across multiple domains:

  • Branch Prediction: Reduced Mispredictions Per Thousand Instructions (MPKI) by 26% compared to state-of-the-art perceptron-based predictors.
  • Address Prefetching: Improved prediction accuracy by 45% over existing methods like LSTM-delta and address correlation.
  • Algorithm Classification: Using embeddings pre-trained on branch prediction, the model achieved 96.0% accuracy, surpassing the previous state-of-the-art (95.3%) despite using significantly less training data.

Limitations and Future Work

While highly accurate, NCF faces challenges before it can be deployed in live environments:

  • Inference Latency: GNNs are computationally expensive. Real-world hardware predictors need to make decisions in nanoseconds. The authors view this work as a "limit study" showing what is possible, suggesting these large models could eventually be distilled into smaller, faster versions for actual hardware.
  • Scaling to Large Programs: The current approach builds graphs for small windows of execution. Handling massive codebases with millions of instructions remains a challenge due to the memory requirements of GNNs.
  • Sequential History: Traditional predictors excel at remembering long-term patterns (e.g., "this branch always flips every 100 times"). NCF currently focuses more on the immediate graph context; combining NCF with long-term sequential history is a promising next step.

Summary updated

BibTeX
@inproceedings{shi2020learning,
  author = {Zhan Shi and Kevin Swersky and Daniel Tarlow and Parthasarathy Ranganathan and Milad Hashemi},
  title = {{Learning Execution through Neural Code fusion}},
  booktitle = {International Conference on Learning Representations},
  year = {2020},
  url = {https://openreview.net/forum?id=rZEN58qY6-5},
}
Figure