diff mbox

[PATH,mid-end] Check the alternate cost model just as costs_lt_p

Message ID VI1PR0801MB2031738FE8668029BAE25C69FF170@VI1PR0801MB2031.eurprd08.prod.outlook.com
State New
Headers show

Commit Message

Tamar Christina May 2, 2017, 2:34 p.m. UTC
Hi all,

When comparing costs, the rtl function costs_lt_p compares the costs of
A and B such that if they are the same and we were checking for speed,
compare the size and use that as determining factor.

This applies the same principle to the comparison done for the costing
of expr expansions. Potentially makes -Osize code faster and -Ospeed code
smaller.

Bootstrapped on aarch64-none-linux-gnu and x86_64-linux
and reg-tested on aarch64-none-linux-gnu with no regressions.

OK for trunk?

Thanks,
Tamar


gcc/
2017-04-26  Tamar Christina  <tamar.christina@arm.com>

	* expr.c (expand_expr_real_2): Re-cost if previous costs are the same.

Comments

Jeff Law May 2, 2017, 3:08 p.m. UTC | #1
On 05/02/2017 08:34 AM, Tamar Christina wrote:
> Hi all,
> 
> When comparing costs, the rtl function costs_lt_p compares the costs of
> A and B such that if they are the same and we were checking for speed,
> compare the size and use that as determining factor.
> 
> This applies the same principle to the comparison done for the costing
> of expr expansions. Potentially makes -Osize code faster and -Ospeed code
> smaller.
> 
> Bootstrapped on aarch64-none-linux-gnu and x86_64-linux
> and reg-tested on aarch64-none-linux-gnu with no regressions.
> 
> OK for trunk?
> 
> Thanks,
> Tamar
> 
> 
> gcc/
> 2017-04-26  Tamar Christina  <tamar.christina@arm.com>
> 
> 	* expr.c (expand_expr_real_2): Re-cost if previous costs are the same.
OK
jeff
diff mbox

Patch

diff --git a/gcc/expr.c b/gcc/expr.c
index 00f08aad55c90a0563bf93cf578107fe0b871231..2469608311c6793a58e7a042f751f390341242b4 100644
--- a/gcc/expr.c
+++ b/gcc/expr.c
@@ -8837,6 +8837,15 @@  expand_expr_real_2 (sepops ops, rtx target, machine_mode tmode,
 	   end_sequence ();
 	   unsigned uns_cost = seq_cost (uns_insns, speed_p);
 	   unsigned sgn_cost = seq_cost (sgn_insns, speed_p);
+
+	   /* If costs are the same then use as tie breaker the other
+	      other factor.  */
+	   if (uns_cost == sgn_cost)
+	     {
+		uns_cost = seq_cost (uns_insns, !speed_p);
+		sgn_cost = seq_cost (sgn_insns, !speed_p);
+	     }
+
 	   if (uns_cost < sgn_cost || (uns_cost == sgn_cost && unsignedp))
 	     {
 	       emit_insn (uns_insns);