If one of branches has significantly greater probability than the other,
then it may be better to rely on CPU's branch prediction and block
reordering, than putting rarely executed instructions into the pipeline.
In this patch we set 10% frequency ratio as a cutoff.
On SPEC2K INT with -O2 this reduced code size for 28 bytes (no regressions).
2011-12-29 Dmitry Plotnikov <dplotni...@ispras.ru>
gcc/
* ifcvt.c (cond_exec_process_if_block): Added check for frequency ratio.
diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c
index ce60ce2..330034e 100644
--- a/gcc/ifcvt.c
+++ b/gcc/ifcvt.c
@@ -445,6 +445,16 @@ cond_exec_process_if_block (ce_if_block_t * ce_info,
int then_n_insns, else_n_insns, n_insns;
enum rtx_code false_code;
+ /* If one of branches has significantly greater probability than the other,
+ then we'd better rely on CPU's branch prediction and block reordering
+ than putting rarely executed instructions into the pipeline. 10% ratio
+ seems like a reasonable cutoff. */
+ if (then_bb && then_bb->frequency < (test_bb->frequency / 10))
+ return FALSE;
+
+ if (else_bb && else_bb->frequency < (test_bb->frequency / 10))
+ return FALSE;
+
/* If test is comprised of && or || elements, and we've failed at handling
all of them together, just use the last test if it is the special case of
&& elements without an ELSE block. */