Patchwork cse.c: preferable()

login
register
mail settings
Submitter Dimitrios Apostolou
Date Aug. 22, 2011, 8:37 a.m.
Message ID <alpine.LNX.2.02.1108221129520.1374@localhost.localdomain>
Download mbox | patch
Permalink /patch/110870/
State New
Headers show

Comments

Dimitrios Apostolou - Aug. 22, 2011, 8:37 a.m.
Attached patch is also posted at bug #19832 and I think resolves it, as 
well as /maybe/ offers a negligible speedup of 3-4 M instr or a couple 
milliseconds. I also post it here for comments.


2011-08-13  Dimitrios Apostolou  <jimis@gmx.net>

     * cse.c (preferable): Make it more readable and slightly faster,
     without affecting its logic.

Patch

=== modified file 'gcc/cse.c'
--- gcc/cse.c	2011-06-02 21:52:46 +0000

+++ gcc/cse.c	2011-08-13 00:54:06 +0000

@@ -720,32 +720,25 @@  approx_reg_cost (rtx x)

 static int
 preferable (int cost_a, int regcost_a, int cost_b, int regcost_b)
 {
-  /* First, get rid of cases involving expressions that are entirely

-     unwanted.  */

-  if (cost_a != cost_b)

-    {

-      if (cost_a == MAX_COST)

-	return 1;

-      if (cost_b == MAX_COST)

-	return -1;

-    }

+  int cost_diff = cost_a - cost_b;

+  int regcost_diff = regcost_a - regcost_b;

 
-  /* Avoid extending lifetimes of hardregs.  */

-  if (regcost_a != regcost_b)

+  if (cost_diff != 0)

     {
-      if (regcost_a == MAX_COST)

-	return 1;

-      if (regcost_b == MAX_COST)

-	return -1;

+      /* If none of the expressions are entirely unwanted */

+      if ((cost_a != MAX_COST) && (cost_b != MAX_COST)

+	  /* AND only one of the regs is HARD_REG */

+	  && (regcost_diff != 0)

+	  && ((regcost_a == MAX_COST) || (regcost_b == MAX_COST))

+	  )

+	/* Then avoid extending lifetime of HARD_REG */

+	return regcost_diff;

+

+      return cost_diff;

     }
 
-  /* Normal operation costs take precedence.  */

-  if (cost_a != cost_b)

-    return cost_a - cost_b;

-  /* Only if these are identical consider effects on register pressure.  */

-  if (regcost_a != regcost_b)

-    return regcost_a - regcost_b;

-  return 0;

+  /* cost_a == costb, consider effects on register pressure */

+  return regcost_diff;

 }
 
 /* Internal function, to compute cost when X is not a register; called