2.8 PredicationPredication is the conditional execution of instructions. Conditional execution is implemented through branches in traditional architectures. IA-64 implements this function through the use of predicated instructions. Predication removes branches used for conditional execution resulting in larger basic blocks and the elimination of associated mispredict penalties.
To illustrate, an unpredicated instruction
Код:
r1 = r2 + r3
when predicated, would be of the form
Код:
if (p5) r1 = r2 + r3
In this example p5 is the controlling predicate that decides whether or not the instruction executes and updates state. If the predicate value is true, then the instruction updates state. Otherwise it generally behaves like a nop. Predicates are assigned values by compare instructions.
Predicated execution avoids branches, and simplifies compiler optimizations by converting a control dependence to a data dependence. Consider the original code:
Код:
if (a>b) c = c + 1
else d = d * e + f
The branch at (a>b) can be avoided by converting the code above to the predicated code:
Код:
pT, pF = compare(a>b)
if (pT) c = c + 1
if (pF) d = d * e + f
The predicate pT is set to 1 if the condition evaluates to true, and to 0 if the condition evaluates to false. The predicate pF is the complement of pT. The control dependence of the instructions c = c + 1 and d = d * e + f on the branch with the condition (a>b) is now converted into a data dependence on compare(a>b) through predicates pT and pF (the branch is eliminated). An added benefit is that the compiler can schedule the instructions under pT and pF to execute in parallel. It is also worth noting that there are several different types of compare instructions that write predicates in different manners including unconditional compares and parallel compares.