When threads in a warp take different branches, the GPU may run each path in turn. For a short, cheap branch, predication can avoid that split: threads compute alternatives and select the result matching their own condition. This does extra arithmetic, but avoids the control-flow work of masking threads and switching paths. Compilers often make this change automatically. section 14.3
// Branchless: compute both, select int sum = a + b; #A int diff = a - b; result = condition ? sum : diff; #B
This branchless version computes both arithmetic results, then selects one for each thread. It is suitable when both alternatives are short, cheap, and have no memory-writing side effects. section 14.3
Predication is not always faster: computing both alternatives wastes work, and a branch that touches memory or performs expensive operations may not be predicated. For those cases, the compiler may keep the branch and divergence remains. Consider predication when the branch body is short, cheap, and side-effect-free. section 14.3 section 14.4
