Compiler Support for Value-Based Indirect Branch Prediction

Muhammad Umar Farooq, Lei Chen, Lizy Kurian JohnCC 2012

Introduction

Indirect branches, such as virtual function calls in C++, switch-case statements, and function pointers, are ubiquitous in modern software. Unlike direct branches with a single destination, indirect branches can target multiple locations, making them notoriously difficult for traditional hardware predictors to handle. Standard mechanisms like the Branch Target Buffer (BTB) or Tagged Target Cache (TTC) rely on execution history, but their limited view of program logic often leads to mispredictions.

This paper explores Value-Based BTB Indexing (VBBI), a technique that leverages the output of "hint instructions"—the specific calculations determining a branch's target—to index the predictor. The primary challenge for VBBI is the timing: if a branch is fetched too soon after its hint instruction, the required value may not be ready, leading to "stale" predictions and subsequent pipeline stalls.

Methodology: Compiler-Driven Optimizations

To address the timing constraints of VBBI, the authors modified the GCC v4.2.1 compiler to identify and optimize hint-jump pairs. The compiler's role is divided into three critical stages:

  1. Identification: Utilizing Static Single Assignment (SSA) form, the compiler traces data dependencies from an indirect branch back to its most recent definition, identifying the optimal hint instruction.
  2. Encoding: The compiler calculates the PC offset between the hint and the jump. This metadata is then encoded into the unused bits of the architecture's jump instruction, as shown in the instruction format below. This allows the hardware to locate the hint value without additional overhead.
Encoding of the hint field into the unused bits of an indirect jump instruction.
  1. Distance Optimization: To ensure the hint value is ready before the jump is fetched, the compiler employs several techniques to increase the "dynamic instruction count" between them. These include Instruction Hoisting (moving hint calculations to the start of loops), Function Inlining, and Inter-procedural Analysis to identify hints across function boundaries.

Experimental Evaluation

The proposed system was evaluated using nine benchmarks from the SPEC95, SPEC2000, and SPEC2006 suites, including gcc, perlbmk, and sjeng. These benchmarks represent integer-heavy workloads with significant indirect branch activity, providing a robust test for the predictor's accuracy.

Key Results

The integration of compiler support significantly enhanced the effectiveness of VBBI. Prediction accuracy improved from a baseline of 66% to 80%. This accuracy boost translated into a 24.8% performance improvement (IPC) over traditional BTB designs and a 17.3% improvement over the state-of-the-art TTC.

As illustrated in the figure below, the optimized VBBI approach drastically reduces the number of mispredictions per 1,000 instructions (MPKI) across nearly all tested benchmarks.

Comparison of mispredictions per kilo instructions (MPKI) across various benchmarks for BTB, TTC, and VBBI predictors.

On average, indirect mispredictions dropped from 3.7 MPKI with a traditional BTB to just 1.3 MPKI with optimized VBBI, demonstrating the power of compiler-assisted hardware prediction in reducing execution overhead.

Conclusion and Future Work

By offloading complex dependency analysis to the compiler, the hardware predictor can remain efficient while achieving superior accuracy. The study highlights that the distance between a hint and its corresponding jump is the most critical factor for success. Future work includes expanding support to languages like C++ and Java, where polymorphism and virtual tables offer even greater potential for gains, though they require more sophisticated compiler analysis.

Summary updated

BibTeX
@inproceedings{farooq2012compiler,
  author = {Muhammad Umar Farooq and Lei Chen and Lizy Kurian John},
  title = {{Compiler Support for Value-Based Indirect Branch Prediction}},
  booktitle = {CC},
  year = {2012},
  doi = {10.1007/978-3-642-28652-0\_10},
}
Figure