expand: Add dump for costing of positive divides

Message ID 20240904015914.2874499-1-quic_apinski@quicinc.com
State Committed
Commit dbd0eb39c690f80e7a9bb7697aaa3f85ff4dbadd
Headers
Series expand: Add dump for costing of positive divides |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gcc_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 warning Patch is already merged

Commit Message

Andrew Pinski Sept. 4, 2024, 1:59 a.m. UTC
  While trying to understand PR 115910 I found it was useful to print out
the two costs of doing a signed and unsigned division just like was added in
r15-3272-g3c89c41991d8e8 for popcount==1.

Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

	* expr.cc (expand_expr_divmod): Add dump of the two costs for
	positive division.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
---
 gcc/expr.cc | 7 +++++++
 1 file changed, 7 insertions(+)
  

Comments

Richard Biener Sept. 4, 2024, 5:23 a.m. UTC | #1
> Am 04.09.2024 um 04:00 schrieb Andrew Pinski <quic_apinski@quicinc.com>:
> 
> While trying to understand PR 115910 I found it was useful to print out
> the two costs of doing a signed and unsigned division just like was added in
> r15-3272-g3c89c41991d8e8 for popcount==1.
> 
> Bootstrapped and tested on x86_64-linux-gnu.

Ok

> gcc/ChangeLog:
> 
>    * expr.cc (expand_expr_divmod): Add dump of the two costs for
>    positive division.
> 
> Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
> ---
> gcc/expr.cc | 7 +++++++
> 1 file changed, 7 insertions(+)
> 
> diff --git a/gcc/expr.cc b/gcc/expr.cc
> index 320be8b17a1..7a471f20e79 100644
> --- a/gcc/expr.cc
> +++ b/gcc/expr.cc
> @@ -9648,6 +9648,7 @@ expand_expr_divmod (tree_code code, machine_mode mode, tree treeop0,
>       end_sequence ();
>       unsigned uns_cost = seq_cost (uns_insns, speed_p);
>       unsigned sgn_cost = seq_cost (sgn_insns, speed_p);
> +      bool was_tie = false;
> 
>       /* If costs are the same then use as tie breaker the other other
>     factor.  */
> @@ -9655,8 +9656,14 @@ expand_expr_divmod (tree_code code, machine_mode mode, tree treeop0,
>    {
>      uns_cost = seq_cost (uns_insns, !speed_p);
>      sgn_cost = seq_cost (sgn_insns, !speed_p);
> +      was_tie = true;
>    }
> 
> +      if (dump_file && (dump_flags & TDF_DETAILS))
> +      fprintf(dump_file, "positive division:%s unsigned cost: %u; "
> +          "signed cost: %u\n", was_tie ? "(needed tie breaker)":"",
> +          uns_cost, sgn_cost);
> +
>       if (uns_cost < sgn_cost || (uns_cost == sgn_cost && unsignedp))
>    {
>      emit_insn (uns_insns);
> --
> 2.43.0
>
  

Patch

diff --git a/gcc/expr.cc b/gcc/expr.cc
index 320be8b17a1..7a471f20e79 100644
--- a/gcc/expr.cc
+++ b/gcc/expr.cc
@@ -9648,6 +9648,7 @@  expand_expr_divmod (tree_code code, machine_mode mode, tree treeop0,
       end_sequence ();
       unsigned uns_cost = seq_cost (uns_insns, speed_p);
       unsigned sgn_cost = seq_cost (sgn_insns, speed_p);
+      bool was_tie = false;
 
       /* If costs are the same then use as tie breaker the other other
 	 factor.  */
@@ -9655,8 +9656,14 @@  expand_expr_divmod (tree_code code, machine_mode mode, tree treeop0,
 	{
 	  uns_cost = seq_cost (uns_insns, !speed_p);
 	  sgn_cost = seq_cost (sgn_insns, !speed_p);
+	  was_tie = true;
 	}
 
+      if (dump_file && (dump_flags & TDF_DETAILS))
+	  fprintf(dump_file, "positive division:%s unsigned cost: %u; "
+		  "signed cost: %u\n", was_tie ? "(needed tie breaker)":"",
+		  uns_cost, sgn_cost);
+
       if (uns_cost < sgn_cost || (uns_cost == sgn_cost && unsignedp))
 	{
 	  emit_insn (uns_insns);