diff mbox series

AArch64: Improve costing of ctz

Message ID PAWPR08MB8982B3D42F3D26C998F1845083EC2@PAWPR08MB8982.eurprd08.prod.outlook.com
State New
Headers show
Series AArch64: Improve costing of ctz | expand

Commit Message

Wilco Dijkstra May 15, 2024, 10:16 a.m. UTC
Improve costing of ctz - both TARGET_CSSC and vector cases were not handled yet.

Passes regress & bootstrap - OK for commit?

gcc:
        * config/aarch64/aarch64.cc (aarch64_rtx_costs): Improve CTZ costing.

---

Comments

Andrew Pinski May 15, 2024, 10:27 a.m. UTC | #1
On Wed, May 15, 2024, 12:17 PM Wilco Dijkstra <Wilco.Dijkstra@arm.com>
wrote:

> Improve costing of ctz - both TARGET_CSSC and vector cases were not
> handled yet.
>
> Passes regress & bootstrap - OK for commit?
>

I should note popcount has a similar issue which I hope to fix next week.
Popcount cost is used during expand so it is very useful to be slightly
more correct.

Thanks,
Andrew



> gcc:
>         * config/aarch64/aarch64.cc (aarch64_rtx_costs): Improve CTZ
> costing.
>
> ---
>
> diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
> index
> fe13c9a0d4863041eb9101882ea57c2094240d16..2a6f76f4008839bf0aa158504430af9b7777971c
> 100644
> --- a/gcc/config/aarch64/aarch64.cc
> +++ b/gcc/config/aarch64/aarch64.cc
> @@ -14309,10 +14309,24 @@ aarch64_rtx_costs (rtx x, machine_mode mode, int
> outer ATTRIBUTE_UNUSED,
>        return false;
>
>      case CTZ:
> -      *cost = COSTS_N_INSNS (2);
> -
> -      if (speed)
> -       *cost += extra_cost->alu.clz + extra_cost->alu.rev;
> +      if (VECTOR_MODE_P (mode))
> +       {
> +         *cost = COSTS_N_INSNS (3);
> +         if (speed)
> +           *cost += extra_cost->vect.alu * 3;
> +       }
> +      else if (TARGET_CSSC)
> +       {
> +         *cost = COSTS_N_INSNS (1);
> +         if (speed)
> +           *cost += extra_cost->alu.clz;
> +       }
> +      else
> +       {
> +         *cost = COSTS_N_INSNS (2);
> +         if (speed)
> +           *cost += extra_cost->alu.clz + extra_cost->alu.rev;
> +       }
>        return false;
>
>      case COMPARE:
>
>
Wilco Dijkstra May 15, 2024, 12:57 p.m. UTC | #2
Hi Andrew,

> I should note popcount has a similar issue which I hope to fix next week.
> Popcount cost is used during expand so it is very useful to be slightly more correct.

It's useful to set the cost so that all of the special cases still apply - even if popcount is
relatively fast, it's still better to use ALU ops with higher throughput whenever possible.

Cheers,
Wilco
Richard Sandiford May 20, 2024, 10:03 a.m. UTC | #3
Wilco Dijkstra <Wilco.Dijkstra@arm.com> writes:
> Improve costing of ctz - both TARGET_CSSC and vector cases were not handled yet.
>
> Passes regress & bootstrap - OK for commit?
>
> gcc:
>         * config/aarch64/aarch64.cc (aarch64_rtx_costs): Improve CTZ costing.

Ok, thanks.

Richard

> diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
> index fe13c9a0d4863041eb9101882ea57c2094240d16..2a6f76f4008839bf0aa158504430af9b7777971c 100644
> --- a/gcc/config/aarch64/aarch64.cc
> +++ b/gcc/config/aarch64/aarch64.cc
> @@ -14309,10 +14309,24 @@ aarch64_rtx_costs (rtx x, machine_mode mode, int outer ATTRIBUTE_UNUSED,
>        return false;
>  
>      case CTZ:
> -      *cost = COSTS_N_INSNS (2);
> -
> -      if (speed)
> -	*cost += extra_cost->alu.clz + extra_cost->alu.rev;
> +      if (VECTOR_MODE_P (mode))
> +	{
> +	  *cost = COSTS_N_INSNS (3);
> +	  if (speed)
> +	    *cost += extra_cost->vect.alu * 3;
> +	}
> +      else if (TARGET_CSSC)
> +	{
> +	  *cost = COSTS_N_INSNS (1);
> +	  if (speed)
> +	    *cost += extra_cost->alu.clz;
> +	}
> +      else
> +	{
> +	  *cost = COSTS_N_INSNS (2);
> +	  if (speed)
> +	    *cost += extra_cost->alu.clz + extra_cost->alu.rev;
> +	}
>        return false;
>  
>      case COMPARE:
diff mbox series

Patch

diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index fe13c9a0d4863041eb9101882ea57c2094240d16..2a6f76f4008839bf0aa158504430af9b7777971c 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -14309,10 +14309,24 @@  aarch64_rtx_costs (rtx x, machine_mode mode, int outer ATTRIBUTE_UNUSED,
       return false;
 
     case CTZ:
-      *cost = COSTS_N_INSNS (2);
-
-      if (speed)
-	*cost += extra_cost->alu.clz + extra_cost->alu.rev;
+      if (VECTOR_MODE_P (mode))
+	{
+	  *cost = COSTS_N_INSNS (3);
+	  if (speed)
+	    *cost += extra_cost->vect.alu * 3;
+	}
+      else if (TARGET_CSSC)
+	{
+	  *cost = COSTS_N_INSNS (1);
+	  if (speed)
+	    *cost += extra_cost->alu.clz;
+	}
+      else
+	{
+	  *cost = COSTS_N_INSNS (2);
+	  if (speed)
+	    *cost += extra_cost->alu.clz + extra_cost->alu.rev;
+	}
       return false;
 
     case COMPARE: