From: David Edelsohn <dje.gcc@gmail.com>
To: Jiufu Guo <guojiufu@linux.ibm.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>,
Segher Boessenkool <segher@kernel.crashing.org>,
linkw@gcc.gnu.org
Subject: Re: [PATCH 1/4] rs6000: build constant via li;rotldi
Date: Fri, 2 Jun 2023 10:22:40 -0400 [thread overview]
Message-ID: <CAGWvny=nZ3Ys08JLTiSE8XMfqnu961RdeNq0trip3RPN+zVeug@mail.gmail.com> (raw)
[-- 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
next reply other threads:[~2023-06-02 14:22 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-02 14:22 David Edelsohn [this message]
2023-06-07 6:09 ` Jiufu Guo
-- strict thread matches above, loose matches on Subject: below --
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
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAGWvny=nZ3Ys08JLTiSE8XMfqnu961RdeNq0trip3RPN+zVeug@mail.gmail.com' \
--to=dje.gcc@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=guojiufu@linux.ibm.com \
--cc=linkw@gcc.gnu.org \
--cc=segher@kernel.crashing.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).