HP Compilers for HP Integrity Servers (September 2011)

Example 1 Using predication
if (a == 0) {
x = 5;
} else {
x = *p;
}
The compiler can use predication to transform control dependencies on branch instructions
into data dependencies on compare instructions.
Example 2 Code from Example 1 generated using branches
cmp.ne.unc p1,p0 = a,0
(p1) br L1 ;;
mov x = 5
br L2 ;;
L1: ld x = [p]
L2:
The assignment to x that is executed is control dependent on the predicate (p1) in the
first branch instruction.
Transforming from control dependence to data dependence has two principal benefits:
Removal of branches, which increases the number of instructions per cycle. For
example, by eliminating the branches in Example 2 (page 6), both assignments
to x can be executed in the same cycle.
Elimination of the misprediction penalty associated with branches. In a pipelined
processor, a branch presents a potential disruption in the pipeline flow. The processor
must predict whether a conditional branch is taken and must predict the target, if it
is indirect. An incorrect prediction flushes and restarts the pipeline. With a deep
pipeline and wide issue bandwidth, this represents a significant loss of performance.
On the Intel Itanium processor, for example, a branch misprediction penalty is 9
cycles, representing 54 lost instruction issue opportunities. Even with sophisticated
branch prediction techniques, a small percentage of mispredicted branches can
translate into significant performance cost.
6 HP compilers for HP Integrity servers