public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 0/4] rs6000: build constant via li/lis;rldicX
@ 2023-02-03 10:22 Jiufu Guo
  2023-02-03 10:22 ` [PATCH 1/4] rs6000: build constant via li;rotldi Jiufu Guo
                   ` (4 more replies)
  0 siblings, 5 replies; 15+ messages in thread
From: Jiufu Guo @ 2023-02-03 10:22 UTC (permalink / raw)
  To: gcc-patches; +Cc: segher, dje.gcc, linkw, guojiufu

Hi,

For a given constant, it would be profitable if we can use 2 insns to build.
This patch enables more constants building through 2 insns: one is "li or lis",
another is 'rldicl, rldicr or rldic'.
Through checking and analyzing the characters of the insns "li/lis;rldicX",
all the possible constant values are considered by this patch.

Previously, a patch is posted, but it is too large.
https://gcc.gnu.org/pipermail/gcc-patches/2022-September/601276.html
As suggested, I split it into this series.

Considering the functionality and size, 4 patches are split as below:
1. Support the constants which can be built by "li;rotldi"
   Both positive and negative values from insn "li" are analyzed.
2. Support the constants which can be built by "lis;rotldi"
   We only need to analyze the negative value from "lis".
   And this patch uses more code to check leading 1s and tailing 0s from "lis".
3. Support the constants which can be built by "li/lis;rldicl/rldicr":
   Leverage the APIs defined/analyzed in patches 1 and 2,
   this patch checks the characters for the mask of "rldicl/rldicr"
   to support more constants.
4. Support the constants which can be built by "li/lis;rldic":
   The mask of "rldic" is relatively complicated, it is analyzed in this
   patch to support more constants.

BR,
Jeff (Jiufu)

^ permalink raw reply	[flat|nested] 15+ messages in thread
* Re: [PATCH 1/4] rs6000: build constant via li;rotldi
@ 2023-06-02 14:22 David Edelsohn
  2023-06-07  6:09 ` Jiufu Guo
  0 siblings, 1 reply; 15+ messages in thread
From: David Edelsohn @ 2023-06-02 14:22 UTC (permalink / raw)
  To: Jiufu Guo; +Cc: GCC Patches, Segher Boessenkool, linkw

[-- Attachment #1: Type: text/plain, Size: 3385 bytes --]

Hi, Jiufu

	* config/rs6000/rs6000.cc (can_be_rotated_to_possitive_li): New function.
	(can_be_rotated_to_negative_li): New function.
	(can_be_built_by_li_and_rotldi): New function.
	(rs6000_emit_set_long_const): Call can_be_built_by_li_and_rotldi.

In English the word "positive" contains one "s", not two.  Please
correct throughout the patches.

Also a style issue, comments before a function should be followed by a
blank line.

> +/* Check if C can be rotated to a possitive value which 'li' instruction

positive
> +   is able to load.  If so, set *ROT to the number by which C is rotated,
> +   and return true.  Return false otherwise.  */

Add a blank line here
> +static bool
> +can_be_rotated_to_possitive_li (HOST_WIDE_INT c, int *rot)

positive
> +{
> +  /* 49 leading zeros and 15 lowbits on the possitive value

low bits, positive

> +     generated by 'li' instruction.  */
> +  return can_be_rotated_to_lowbits (c, 15, rot);
> +}

> +/* Check if value C can be built by 2 instructions: one is 'li', another is
> +   rotldi.
> +
> +   If so, *SHIFT is set to the shift operand of rotldi(rldicl), and *MASK
> +   is set to -1, and return true.  Return false otherwise.  */
> +static bool
> +can_be_built_by_li_and_rotldi (HOST_WIDE_INT c, int *shift,
> +				   HOST_WIDE_INT *mask)
> +{
> +  int n;
> +  if (can_be_rotated_to_possitive_li (c, &n)
> +      || can_be_rotated_to_negative_li (c, &n))
> +    {
> +      *mask = HOST_WIDE_INT_M1;
> +      *shift = HOST_BITS_PER_WIDE_INT - n;
> +      return true;
> +    }
> +
> +  return false;
> +}
> +
>  /* Subroutine of rs6000_emit_set_const, handling PowerPC64 DImode.
>     Output insns to set DEST equal to the constant C as a series of
>     lis, ori and shl instructions.  */
> @@ -10246,15 +10285,14 @@ static void>  rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT c)>  {>    rtx temp;> +  int shift;> +  HOST_WIDE_INT mask;>    HOST_WIDE_INT ud1, ud2, ud3, ud4;>  >    ud1 = c & 0xffff;> -  c = c >> 16;> -  ud2 = c & 0xffff;> -  c = c >> 16;> -  ud3 = c & 0xffff;> -  c = c >> 16;> -  ud4 = c & 0xffff;> +  ud2 = (c >> 16) & 0xffff;> +  ud3 = (c >> 32) & 0xffff;> +  ud4 = (c >> 48) & 0xffff;>  >    if ((ud4 == 0xffff && ud3 == 0xffff && ud2 == 0xffff && (ud1 & 0x8000))>        || (ud4 == 0 && ud3 == 0 && ud2 == 0 && ! (ud1 & 0x8000)))> @@ -10278,6 +10316,19 @@ rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT c)>        emit_move_insn (dest, gen_rtx_XOR (DImode, temp,>  					 GEN_INT ((ud2 ^ 0xffff) << 16)));>      }> +  else if (can_be_built_by_li_and_rotldi (c, &shift, &mask))> +    {> +      temp = !can_create_pseudo_p () ? dest : gen_reg_rtx (DImode);> +      unsigned HOST_WIDE_INT imm = (c | ~mask);> +      imm = (imm >> shift) | (imm << (HOST_BITS_PER_WIDE_INT - shift));> +> +      emit_move_insn (temp, GEN_INT (imm));> +      if (shift != 0)> +	temp = gen_rtx_ROTATE (DImode, temp, GEN_INT (shift));> +      if (mask != HOST_WIDE_INT_M1)

How is mask != HOST_WIDE_INT_M1? The call to
can_by_built_by_li_and_rotldi() set it

to that value and it is not modified in the interim statements.

> +	temp = gen_rtx_AND (DImode, temp, GEN_INT (mask));> +      emit_move_insn (dest, temp);> +    }>    else if (ud3 == 0 && ud4 == 0)>      {>        temp = !can_create_pseudo_p () ? dest : gen_reg_rtx (DImode);

Thanks, David

^ permalink raw reply	[flat|nested] 15+ messages in thread
* [PATCH V2 0/4] rs6000: build constant via li/lis;rldicX
@ 2023-06-08  1:55 Jiufu Guo
  2023-06-08  1:55 ` [PATCH 1/4] rs6000: build constant via li;rotldi Jiufu Guo
  0 siblings, 1 reply; 15+ messages in thread
From: Jiufu Guo @ 2023-06-08  1:55 UTC (permalink / raw)
  To: gcc-patches; +Cc: segher, dje.gcc, linkw, bergner, guojiufu

Hi,

These patches are just minor changes based on previous version/comments.
https://gcc.gnu.org/pipermail/gcc-patches/2023-February/611286.html
https://gcc.gnu.org/pipermail/gcc-patches/2023-June/620489.html
And also update the wording for patches in this series.

For a given constant, it would be profitable if we can use 2 insns to build.
This patch enables more constants building through 2 insns: one is "li or lis",
another is 'rldicl, rldicr or rldic'.
Through checking and analyzing the characters of the insns "li/lis;rldicX",
all the possible constant values are considered by this patch.

The below patches are in this series.

Considering the functionality and size, 4 patches are split as below:
1. Support the constants which can be built by "li;rotldi"
   Both positive and negative values from insn "li" are analyzed.
2. Support the constants which can be built by "lis;rotldi"
   We only need to analyze the negative value from "lis".
   And this patch uses more code to check leading 1s and tailing 0s from "lis".
3. Support the constants which can be built by "li/lis;rldicl/rldicr":
   Leverage the APIs defined/analyzed in patches 1 and 2,
   this patch checks the characters for the mask of "rldicl/rldicr"
   to support more constants.
4. Support the constants which can be built by "li/lis;rldic":
   The mask of "rldic" is relatively complicated, it is analyzed in this
   patch to support more constants.

BR,
Jeff (Jiufu)

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

end of thread, other threads:[~2023-06-14  1:16 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-03 10:22 [PATCH 0/4] rs6000: build constant via li/lis;rldicX Jiufu Guo
2023-02-03 10:22 ` [PATCH 1/4] rs6000: build constant via li;rotldi Jiufu Guo
2023-02-03 10:22 ` [PATCH 2/4] rs6000: build constant via lis;rotldi Jiufu Guo
2023-02-03 10:22 ` [PATCH 3/4] rs6000: build constant via li/lis;rldicl/rldicr Jiufu Guo
2023-02-03 10:22 ` [PATCH 4/4] rs6000: build constant via li/lis;rldic Jiufu Guo
2023-02-20  3:16 ` [PATCH 0/4] rs6000: build constant via li/lis;rldicX Jiufu Guo
2023-04-26  4:18   ` Ping^^ " Jiufu Guo
2023-05-31  2:55     ` Ping^^^ " Jiufu Guo
2023-06-02 14:22 [PATCH 1/4] rs6000: build constant via li;rotldi David Edelsohn
2023-06-07  6:09 ` Jiufu Guo
2023-06-08  1:55 [PATCH V2 0/4] rs6000: build constant via li/lis;rldicX Jiufu Guo
2023-06-08  1:55 ` [PATCH 1/4] rs6000: build constant via li;rotldi Jiufu Guo
2023-06-11  1:11   ` David Edelsohn
2023-06-13  3:30     ` Jiufu Guo
2023-06-13 13:47       ` David Edelsohn
2023-06-14  1:16         ` Jiufu Guo

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).