public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] expansion: make layout of x_shift*cost[][][] more efficient
@ 2023-04-18 18:17 Vineet Gupta
  2023-04-18 20:48 ` [PATCH v2] " Vineet Gupta
  0 siblings, 1 reply; 4+ messages in thread
From: Vineet Gupta @ 2023-04-18 18:17 UTC (permalink / raw)
  To: gcc-patches
  Cc: kito.cheng, Jeff Law, Palmer Dabbelt, Philipp Tomsich,
	Christoph Mullner, gnu-toolchain, Vineet Gupta

when debugging expmed.[ch] for PR/108987 saw that some of the cost arrays have
less than ideal layout as follows:

   x_shift*cost[0..63][speed][modes]

We would want speed to be first index since a typical compile will have
that fixed, followed by mode and then the shift values.

It should be non-functional from compiler semantics pov, except
executing slightly faster due to better locality of shift values for
given speed and mode. And also a bit more intutive when debugging.

gcc/Changelog:

	* expmed.h (x_shift*_cost): convert to int [speed][mode][shift].
	(shift*_cost_ptr ()): Access x_shift*_cost array directly.

Signed-off-by: Vineet Gupta <vineetg@rivosinc.com>
---
 gcc/expmed.h | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/gcc/expmed.h b/gcc/expmed.h
index c747a0da1637..d032beaef550 100644
--- a/gcc/expmed.h
+++ b/gcc/expmed.h
@@ -161,15 +161,14 @@ struct target_expmed {
   struct expmed_op_cheap x_sdiv_pow2_cheap;
   struct expmed_op_cheap x_smod_pow2_cheap;
 
-  /* Cost of various pieces of RTL.  Note that some of these are indexed by
-     shift count and some by mode.  */
+  /* Cost of various pieces of RTL.  */
   int x_zero_cost[2];
   struct expmed_op_costs x_add_cost;
   struct expmed_op_costs x_neg_cost;
-  struct expmed_op_costs x_shift_cost[MAX_BITS_PER_WORD];
-  struct expmed_op_costs x_shiftadd_cost[MAX_BITS_PER_WORD];
-  struct expmed_op_costs x_shiftsub0_cost[MAX_BITS_PER_WORD];
-  struct expmed_op_costs x_shiftsub1_cost[MAX_BITS_PER_WORD];
+  int x_shift_cost[2][NUM_MODE_IPV_INT][MAX_BITS_PER_WORD];
+  int x_shiftadd_cost[2][NUM_MODE_IPV_INT][MAX_BITS_PER_WORD];
+  int x_shiftsub0_cost[2][NUM_MODE_IPV_INT][MAX_BITS_PER_WORD];
+  int x_shiftsub1_cost[2][NUM_MODE_IPV_INT][MAX_BITS_PER_WORD];
   struct expmed_op_costs x_mul_cost;
   struct expmed_op_costs x_sdiv_cost;
   struct expmed_op_costs x_udiv_cost;
@@ -395,8 +394,8 @@ neg_cost (bool speed, machine_mode mode)
 inline int *
 shift_cost_ptr (bool speed, machine_mode mode, int bits)
 {
-  return expmed_op_cost_ptr (&this_target_expmed->x_shift_cost[bits],
-			     speed, mode);
+  int midx = expmed_mode_index (mode);
+  return &this_target_expmed->x_shift_cost[speed][midex][bits];
 }
 
 /* Set the COST of doing a shift in MODE by BITS when optimizing for SPEED.  */
@@ -421,8 +420,8 @@ shift_cost (bool speed, machine_mode mode, int bits)
 inline int *
 shiftadd_cost_ptr (bool speed, machine_mode mode, int bits)
 {
-  return expmed_op_cost_ptr (&this_target_expmed->x_shiftadd_cost[bits],
-			     speed, mode);
+  int midx = expmed_mode_index (mode);
+  return &this_target_expmed->x_shiftadd_cost[speed][midex][bits];
 }
 
 /* Set the COST of doing a shift in MODE by BITS followed by an add when
@@ -448,8 +447,8 @@ shiftadd_cost (bool speed, machine_mode mode, int bits)
 inline int *
 shiftsub0_cost_ptr (bool speed, machine_mode mode, int bits)
 {
-  return expmed_op_cost_ptr (&this_target_expmed->x_shiftsub0_cost[bits],
-			     speed, mode);
+  int midx = expmed_mode_index (mode);
+  return &this_target_expmed->x_shiftsub0_cost[speed][midex][bits];
 }
 
 /* Set the COST of doing a shift in MODE by BITS and then subtracting a
@@ -475,8 +474,8 @@ shiftsub0_cost (bool speed, machine_mode mode, int bits)
 inline int *
 shiftsub1_cost_ptr (bool speed, machine_mode mode, int bits)
 {
-  return expmed_op_cost_ptr (&this_target_expmed->x_shiftsub1_cost[bits],
-			     speed, mode);
+  int midx = expmed_mode_index (mode);
+  return &this_target_expmed->x_shiftsub1_cost[speed][midex][bits];
 }
 
 /* Set the COST of subtracting a shift in MODE by BITS from a value when
-- 
2.34.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2] expansion: make layout of x_shift*cost[][][] more efficient
  2023-04-18 18:17 [PATCH] expansion: make layout of x_shift*cost[][][] more efficient Vineet Gupta
@ 2023-04-18 20:48 ` Vineet Gupta
  2023-04-19  7:05   ` Richard Biener
  0 siblings, 1 reply; 4+ messages in thread
From: Vineet Gupta @ 2023-04-18 20:48 UTC (permalink / raw)
  To: gcc-patches
  Cc: kito.cheng, Jeff Law, Palmer Dabbelt, Philipp Tomsich,
	Christoph Mullner, gnu-toolchain, Vineet Gupta

when debugging expmed.[ch] for PR/108987 saw that some of the cost arrays have
less than ideal layout as follows:

   x_shift*cost[0..63][speed][modes]

We would want speed to be first index since a typical compile will have
that fixed, followed by mode and then the shift values.

It should be non-functional from compiler semantics pov, except
executing slightly faster due to better locality of shift values for
given speed and mode. And also a bit more intutive when debugging.

gcc/Changelog:

	* expmed.h (x_shift*_cost): convert to int [speed][mode][shift].
	(shift*_cost_ptr ()): Access x_shift*_cost array directly.

Signed-off-by: Vineet Gupta <vineetg@rivosinc.com>
---
Changes since v1:
   - Post a non stale version of patch
---
 gcc/expmed.h | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/gcc/expmed.h b/gcc/expmed.h
index c747a0da1637..22ae1d2d0743 100644
--- a/gcc/expmed.h
+++ b/gcc/expmed.h
@@ -161,15 +161,14 @@ struct target_expmed {
   struct expmed_op_cheap x_sdiv_pow2_cheap;
   struct expmed_op_cheap x_smod_pow2_cheap;
 
-  /* Cost of various pieces of RTL.  Note that some of these are indexed by
-     shift count and some by mode.  */
+  /* Cost of various pieces of RTL.  */
   int x_zero_cost[2];
   struct expmed_op_costs x_add_cost;
   struct expmed_op_costs x_neg_cost;
-  struct expmed_op_costs x_shift_cost[MAX_BITS_PER_WORD];
-  struct expmed_op_costs x_shiftadd_cost[MAX_BITS_PER_WORD];
-  struct expmed_op_costs x_shiftsub0_cost[MAX_BITS_PER_WORD];
-  struct expmed_op_costs x_shiftsub1_cost[MAX_BITS_PER_WORD];
+  int x_shift_cost[2][NUM_MODE_IPV_INT][MAX_BITS_PER_WORD];
+  int x_shiftadd_cost[2][NUM_MODE_IPV_INT][MAX_BITS_PER_WORD];
+  int x_shiftsub0_cost[2][NUM_MODE_IPV_INT][MAX_BITS_PER_WORD];
+  int x_shiftsub1_cost[2][NUM_MODE_IPV_INT][MAX_BITS_PER_WORD];
   struct expmed_op_costs x_mul_cost;
   struct expmed_op_costs x_sdiv_cost;
   struct expmed_op_costs x_udiv_cost;
@@ -395,8 +394,8 @@ neg_cost (bool speed, machine_mode mode)
 inline int *
 shift_cost_ptr (bool speed, machine_mode mode, int bits)
 {
-  return expmed_op_cost_ptr (&this_target_expmed->x_shift_cost[bits],
-			     speed, mode);
+  int midx = expmed_mode_index (mode);
+  return &this_target_expmed->x_shift_cost[speed][midx][bits];
 }
 
 /* Set the COST of doing a shift in MODE by BITS when optimizing for SPEED.  */
@@ -421,8 +420,8 @@ shift_cost (bool speed, machine_mode mode, int bits)
 inline int *
 shiftadd_cost_ptr (bool speed, machine_mode mode, int bits)
 {
-  return expmed_op_cost_ptr (&this_target_expmed->x_shiftadd_cost[bits],
-			     speed, mode);
+  int midx = expmed_mode_index (mode);
+  return &this_target_expmed->x_shiftadd_cost[speed][midx][bits];
 }
 
 /* Set the COST of doing a shift in MODE by BITS followed by an add when
@@ -448,8 +447,8 @@ shiftadd_cost (bool speed, machine_mode mode, int bits)
 inline int *
 shiftsub0_cost_ptr (bool speed, machine_mode mode, int bits)
 {
-  return expmed_op_cost_ptr (&this_target_expmed->x_shiftsub0_cost[bits],
-			     speed, mode);
+  int midx = expmed_mode_index (mode);
+  return &this_target_expmed->x_shiftsub0_cost[speed][midx][bits];
 }
 
 /* Set the COST of doing a shift in MODE by BITS and then subtracting a
@@ -475,8 +474,8 @@ shiftsub0_cost (bool speed, machine_mode mode, int bits)
 inline int *
 shiftsub1_cost_ptr (bool speed, machine_mode mode, int bits)
 {
-  return expmed_op_cost_ptr (&this_target_expmed->x_shiftsub1_cost[bits],
-			     speed, mode);
+  int midx = expmed_mode_index (mode);
+  return &this_target_expmed->x_shiftsub1_cost[speed][midx][bits];
 }
 
 /* Set the COST of subtracting a shift in MODE by BITS from a value when
-- 
2.34.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] expansion: make layout of x_shift*cost[][][] more efficient
  2023-04-18 20:48 ` [PATCH v2] " Vineet Gupta
@ 2023-04-19  7:05   ` Richard Biener
  2023-04-21 16:15     ` [committed] " Vineet Gupta
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Biener @ 2023-04-19  7:05 UTC (permalink / raw)
  To: Vineet Gupta
  Cc: gcc-patches, kito.cheng, Jeff Law, Palmer Dabbelt,
	Philipp Tomsich, Christoph Mullner, gnu-toolchain

On Tue, Apr 18, 2023 at 10:51 PM Vineet Gupta <vineetg@rivosinc.com> wrote:
>
> when debugging expmed.[ch] for PR/108987 saw that some of the cost arrays have
> less than ideal layout as follows:
>
>    x_shift*cost[0..63][speed][modes]
>
> We would want speed to be first index since a typical compile will have
> that fixed, followed by mode and then the shift values.
>
> It should be non-functional from compiler semantics pov, except
> executing slightly faster due to better locality of shift values for
> given speed and mode. And also a bit more intutive when debugging.

OK, but please wait 24h in case somebody else wants to comment.

Thanks,
Richard.

> gcc/Changelog:
>
>         * expmed.h (x_shift*_cost): convert to int [speed][mode][shift].
>         (shift*_cost_ptr ()): Access x_shift*_cost array directly.
>
> Signed-off-by: Vineet Gupta <vineetg@rivosinc.com>
> ---
> Changes since v1:
>    - Post a non stale version of patch
> ---
>  gcc/expmed.h | 27 +++++++++++++--------------
>  1 file changed, 13 insertions(+), 14 deletions(-)
>
> diff --git a/gcc/expmed.h b/gcc/expmed.h
> index c747a0da1637..22ae1d2d0743 100644
> --- a/gcc/expmed.h
> +++ b/gcc/expmed.h
> @@ -161,15 +161,14 @@ struct target_expmed {
>    struct expmed_op_cheap x_sdiv_pow2_cheap;
>    struct expmed_op_cheap x_smod_pow2_cheap;
>
> -  /* Cost of various pieces of RTL.  Note that some of these are indexed by
> -     shift count and some by mode.  */
> +  /* Cost of various pieces of RTL.  */
>    int x_zero_cost[2];
>    struct expmed_op_costs x_add_cost;
>    struct expmed_op_costs x_neg_cost;
> -  struct expmed_op_costs x_shift_cost[MAX_BITS_PER_WORD];
> -  struct expmed_op_costs x_shiftadd_cost[MAX_BITS_PER_WORD];
> -  struct expmed_op_costs x_shiftsub0_cost[MAX_BITS_PER_WORD];
> -  struct expmed_op_costs x_shiftsub1_cost[MAX_BITS_PER_WORD];
> +  int x_shift_cost[2][NUM_MODE_IPV_INT][MAX_BITS_PER_WORD];
> +  int x_shiftadd_cost[2][NUM_MODE_IPV_INT][MAX_BITS_PER_WORD];
> +  int x_shiftsub0_cost[2][NUM_MODE_IPV_INT][MAX_BITS_PER_WORD];
> +  int x_shiftsub1_cost[2][NUM_MODE_IPV_INT][MAX_BITS_PER_WORD];
>    struct expmed_op_costs x_mul_cost;
>    struct expmed_op_costs x_sdiv_cost;
>    struct expmed_op_costs x_udiv_cost;
> @@ -395,8 +394,8 @@ neg_cost (bool speed, machine_mode mode)
>  inline int *
>  shift_cost_ptr (bool speed, machine_mode mode, int bits)
>  {
> -  return expmed_op_cost_ptr (&this_target_expmed->x_shift_cost[bits],
> -                            speed, mode);
> +  int midx = expmed_mode_index (mode);
> +  return &this_target_expmed->x_shift_cost[speed][midx][bits];
>  }
>
>  /* Set the COST of doing a shift in MODE by BITS when optimizing for SPEED.  */
> @@ -421,8 +420,8 @@ shift_cost (bool speed, machine_mode mode, int bits)
>  inline int *
>  shiftadd_cost_ptr (bool speed, machine_mode mode, int bits)
>  {
> -  return expmed_op_cost_ptr (&this_target_expmed->x_shiftadd_cost[bits],
> -                            speed, mode);
> +  int midx = expmed_mode_index (mode);
> +  return &this_target_expmed->x_shiftadd_cost[speed][midx][bits];
>  }
>
>  /* Set the COST of doing a shift in MODE by BITS followed by an add when
> @@ -448,8 +447,8 @@ shiftadd_cost (bool speed, machine_mode mode, int bits)
>  inline int *
>  shiftsub0_cost_ptr (bool speed, machine_mode mode, int bits)
>  {
> -  return expmed_op_cost_ptr (&this_target_expmed->x_shiftsub0_cost[bits],
> -                            speed, mode);
> +  int midx = expmed_mode_index (mode);
> +  return &this_target_expmed->x_shiftsub0_cost[speed][midx][bits];
>  }
>
>  /* Set the COST of doing a shift in MODE by BITS and then subtracting a
> @@ -475,8 +474,8 @@ shiftsub0_cost (bool speed, machine_mode mode, int bits)
>  inline int *
>  shiftsub1_cost_ptr (bool speed, machine_mode mode, int bits)
>  {
> -  return expmed_op_cost_ptr (&this_target_expmed->x_shiftsub1_cost[bits],
> -                            speed, mode);
> +  int midx = expmed_mode_index (mode);
> +  return &this_target_expmed->x_shiftsub1_cost[speed][midx][bits];
>  }
>
>  /* Set the COST of subtracting a shift in MODE by BITS from a value when
> --
> 2.34.1
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [committed] expansion: make layout of x_shift*cost[][][] more efficient
  2023-04-19  7:05   ` Richard Biener
@ 2023-04-21 16:15     ` Vineet Gupta
  0 siblings, 0 replies; 4+ messages in thread
From: Vineet Gupta @ 2023-04-21 16:15 UTC (permalink / raw)
  To: Richard Biener
  Cc: gcc-patches, kito.cheng, Jeff Law, Palmer Dabbelt,
	Philipp Tomsich, Christoph Mullner, gnu-toolchain

On 4/19/23 00:05, Richard Biener wrote:
> On Tue, Apr 18, 2023 at 10:51 PM Vineet Gupta <vineetg@rivosinc.com> wrote:
>> when debugging expmed.[ch] for PR/108987 saw that some of the cost arrays have
>> less than ideal layout as follows:
>>
>>     x_shift*cost[0..63][speed][modes]
>>
>> We would want speed to be first index since a typical compile will have
>> that fixed, followed by mode and then the shift values.
>>
>> It should be non-functional from compiler semantics pov, except
>> executing slightly faster due to better locality of shift values for
>> given speed and mode. And also a bit more intutive when debugging.
> OK, but please wait 24h in case somebody else wants to comment.

Pushed.

Thx,
-Vineet


>
> Thanks,
> Richard.
>
>> gcc/Changelog:
>>
>>          * expmed.h (x_shift*_cost): convert to int [speed][mode][shift].
>>          (shift*_cost_ptr ()): Access x_shift*_cost array directly.
>>
>> Signed-off-by: Vineet Gupta <vineetg@rivosinc.com>
>> ---
>> Changes since v1:
>>     - Post a non stale version of patch
>> ---
>>   gcc/expmed.h | 27 +++++++++++++--------------
>>   1 file changed, 13 insertions(+), 14 deletions(-)
>>
>> diff --git a/gcc/expmed.h b/gcc/expmed.h
>> index c747a0da1637..22ae1d2d0743 100644
>> --- a/gcc/expmed.h
>> +++ b/gcc/expmed.h
>> @@ -161,15 +161,14 @@ struct target_expmed {
>>     struct expmed_op_cheap x_sdiv_pow2_cheap;
>>     struct expmed_op_cheap x_smod_pow2_cheap;
>>
>> -  /* Cost of various pieces of RTL.  Note that some of these are indexed by
>> -     shift count and some by mode.  */
>> +  /* Cost of various pieces of RTL.  */
>>     int x_zero_cost[2];
>>     struct expmed_op_costs x_add_cost;
>>     struct expmed_op_costs x_neg_cost;
>> -  struct expmed_op_costs x_shift_cost[MAX_BITS_PER_WORD];
>> -  struct expmed_op_costs x_shiftadd_cost[MAX_BITS_PER_WORD];
>> -  struct expmed_op_costs x_shiftsub0_cost[MAX_BITS_PER_WORD];
>> -  struct expmed_op_costs x_shiftsub1_cost[MAX_BITS_PER_WORD];
>> +  int x_shift_cost[2][NUM_MODE_IPV_INT][MAX_BITS_PER_WORD];
>> +  int x_shiftadd_cost[2][NUM_MODE_IPV_INT][MAX_BITS_PER_WORD];
>> +  int x_shiftsub0_cost[2][NUM_MODE_IPV_INT][MAX_BITS_PER_WORD];
>> +  int x_shiftsub1_cost[2][NUM_MODE_IPV_INT][MAX_BITS_PER_WORD];
>>     struct expmed_op_costs x_mul_cost;
>>     struct expmed_op_costs x_sdiv_cost;
>>     struct expmed_op_costs x_udiv_cost;
>> @@ -395,8 +394,8 @@ neg_cost (bool speed, machine_mode mode)
>>   inline int *
>>   shift_cost_ptr (bool speed, machine_mode mode, int bits)
>>   {
>> -  return expmed_op_cost_ptr (&this_target_expmed->x_shift_cost[bits],
>> -                            speed, mode);
>> +  int midx = expmed_mode_index (mode);
>> +  return &this_target_expmed->x_shift_cost[speed][midx][bits];
>>   }
>>
>>   /* Set the COST of doing a shift in MODE by BITS when optimizing for SPEED.  */
>> @@ -421,8 +420,8 @@ shift_cost (bool speed, machine_mode mode, int bits)
>>   inline int *
>>   shiftadd_cost_ptr (bool speed, machine_mode mode, int bits)
>>   {
>> -  return expmed_op_cost_ptr (&this_target_expmed->x_shiftadd_cost[bits],
>> -                            speed, mode);
>> +  int midx = expmed_mode_index (mode);
>> +  return &this_target_expmed->x_shiftadd_cost[speed][midx][bits];
>>   }
>>
>>   /* Set the COST of doing a shift in MODE by BITS followed by an add when
>> @@ -448,8 +447,8 @@ shiftadd_cost (bool speed, machine_mode mode, int bits)
>>   inline int *
>>   shiftsub0_cost_ptr (bool speed, machine_mode mode, int bits)
>>   {
>> -  return expmed_op_cost_ptr (&this_target_expmed->x_shiftsub0_cost[bits],
>> -                            speed, mode);
>> +  int midx = expmed_mode_index (mode);
>> +  return &this_target_expmed->x_shiftsub0_cost[speed][midx][bits];
>>   }
>>
>>   /* Set the COST of doing a shift in MODE by BITS and then subtracting a
>> @@ -475,8 +474,8 @@ shiftsub0_cost (bool speed, machine_mode mode, int bits)
>>   inline int *
>>   shiftsub1_cost_ptr (bool speed, machine_mode mode, int bits)
>>   {
>> -  return expmed_op_cost_ptr (&this_target_expmed->x_shiftsub1_cost[bits],
>> -                            speed, mode);
>> +  int midx = expmed_mode_index (mode);
>> +  return &this_target_expmed->x_shiftsub1_cost[speed][midx][bits];
>>   }
>>
>>   /* Set the COST of subtracting a shift in MODE by BITS from a value when
>> --
>> 2.34.1
>>


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-04-21 16:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-18 18:17 [PATCH] expansion: make layout of x_shift*cost[][][] more efficient Vineet Gupta
2023-04-18 20:48 ` [PATCH v2] " Vineet Gupta
2023-04-19  7:05   ` Richard Biener
2023-04-21 16:15     ` [committed] " Vineet Gupta

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).