public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Segher Boessenkool <segher@kernel.crashing.org>
To: Jiufu Guo <guojiufu@linux.ibm.com>
Cc: gcc-patches@gcc.gnu.org, dje.gcc@gmail.com, linkw@gcc.gnu.org
Subject: Re: [PATCH V7] rs6000: Optimize cmp on rotated 16bits constant
Date: Mon, 19 Dec 2022 10:33:55 -0600	[thread overview]
Message-ID: <20221219163355.GO25951@gate.crashing.org> (raw)
In-Reply-To: <20221219140645.34011-1-guojiufu@linux.ibm.com>

Hi!

Mostlt nitpicking left:

On Mon, Dec 19, 2022 at 10:06:45PM +0800, Jiufu Guo wrote:
> When checking eq/ne with a constant which has only 16bits, it can be
> optimized to check the rotated data.  By this, the constant building
> is optimized.
> 
> As the example in PR103743:
> For "in == 0x8000000000000000LL", this patch generates:
>         rotldi 3,3,1 ; cmpldi 0,3,1
> instead of:
>         li 9,-1 ; rldicr 9,9,0,0 ; cmpd 0,3,9

Excellent :-)

> 	* config/rs6000/rs6000-protos.h (can_be_rotated_to_lowbits): New.
> 	(can_be_rotated_to_positive_16bits): New.
> 	(can_be_rotated_to_negative_15bits): New.
> 	* config/rs6000/rs6000.cc (can_be_rotated_to_lowbits): New definition.
> 	(can_be_rotated_to_positive_16bits): New definition.
> 	(can_be_rotated_to_negative_15bits): New definition.
> 	* config/rs6000/rs6000.md (*rotate_on_cmpdi): New define_insn_and_split.

Good names.  Great function comments as well.

> +/* Check if C (as 64bit integer) can be rotated to a constant which constains
> +   nonzero bits at LOWBITS only.

"at the LOWBITS low bits only".  Well it probably is clear what is
meant :-)

> +   Return true if C can be rotated to such constant.  And *ROT is written to
> +   the number by which C is rotated.
> +   Return false otherwise.  */

"If so, *ROT is written" etc.

> +(define_code_iterator eqne [eq ne])

You should say in the changelog that "eqne" was moved.
"(eqne): Move earlier." is plenty of course.

> +(define_insn_and_split "*rotate_on_cmpdi"

> +  rtx note = find_reg_note (curr_insn, REG_BR_PROB, 0);

Move this much later please, to just before it is used.

> +  /* keep the probability info for the prediction of the branch insn.  */

"Keep", sentences start with a capital.

> +}
> +)

These go on one line, as just
})

> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/powerpc/pr103743.c
> @@ -0,0 +1,52 @@
> +/* { dg-options "-O2" } */
> +/* { dg-do compile { target has_arch_ppc64 } } */
> +
> +/* { dg-final { scan-assembler-times {\mcmpldi\M} 10  } } */
> +/* { dg-final { scan-assembler-times {\mcmpdi\M} 4  } } */
> +/* { dg-final { scan-assembler-times {\mrotldi\M} 14  } } */
> +

With so much going on in just one function, I am a bit worried that this
testcase will easily fail in the future.  We will see.

Okay for trunk with those i's dotted.  Thank you!


Segher

  reply	other threads:[~2022-12-19 16:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-19 14:06 Jiufu Guo
2022-12-19 16:33 ` Segher Boessenkool [this message]
2022-12-20  4:35   ` 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=20221219163355.GO25951@gate.crashing.org \
    --to=segher@kernel.crashing.org \
    --cc=dje.gcc@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=guojiufu@linux.ibm.com \
    --cc=linkw@gcc.gnu.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).