Control height reduction merges conditional blocks of code and reduces the
number of conditional branches in the hot path based on profiles.
if (hot_cond1) { // Likely true.
do_stg_hot1();
}
if (hot_cond2) { // Likely true.
do_stg_hot2();
}
->
if (hot_cond1 && hot_cond2) { // Hot path.
do_stg_hot1(); do_stg_hot2();
} else { // Cold path.
if (hot_cond1) { do_stg_hot1(); } if (hot_cond2) { do_stg_hot2(); }
}
This speeds up some internal benchmarks up to ~30%.
This calculation is in danger of overflowing when the weights are large. I made a fix in r341444 to calculate the sum weight in 64 bits to prevent the overflow.