Performance Analysis

Performance counters reveal very frequent branch mispredictions. Which is a suitable remedy?

  1. AAdd more branches inside the loop
  2. BSort data so branch outcomes become predictable, or eliminate branches with conditional selects or arithmetic
  3. CReduce cache capacity
Show answer and explanation

Answer: B. Sort data so branch outcomes become predictable, or eliminate branches with conditional selects or arithmetic

On a branch misprediction, the CPU discards speculatively executed instructions and restarts, losing a dozen or more cycles each time. With random data, the outcome of a branch such as "if the value is at least 128" cannot be predicted. Sorting the data first makes outcomes uniform and predictable, while conditional-select instructions or bit operations remove the branch entirely. Compilers can also be encouraged to make such transformations.

  • A. That could increase mispredictions further.
  • B. Correct. Make branches predictable or remove them.
  • C. It is unrelated to prediction and would hurt performance.
Practice this topic Back to topic

More Performance Analysis questions

  1. In top-down microarchitecture analysis using performance counters, which are the major categories into which CPU issue slots are divided?
  2. A program is slow, yet CPU utilization is only about 20%. What is the most likely cause?
  3. To check whether a program is compute-bound or memory-bound, its run time is measured at different CPU frequencies. What is the typical result if it is memory-bound?
  4. When the Roofline model shows a workload in the memory-bandwidth-limited region, which direction improves performance?
  5. What does the STREAM benchmark mainly measure?