diff mbox

[RFC,ARM,4/5] Limit on frequency in if-conversion

Message ID 4EFDEBE8.3090002@ispras.ru
State New
Headers show

Commit Message

Dmitry Melnik Dec. 30, 2011, 4:50 p.m. UTC
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).

Comments

Bernd Schmidt Jan. 9, 2012, 2:57 p.m. UTC | #1
On 12/30/2011 05:50 PM, Dmitry Melnik wrote:
> 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).

This probably should be controlled by a target hook. C6X for example
probably doesn't want this.


Bernd
diff mbox

Patch

2011-12-29  Dmitry Plotnikov <dplotnikov@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.  */