public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jeff Law <jeffreyalaw@gmail.com>
To: Vineet Gupta <vineetg@rivosinc.com>, gcc-patches@gcc.gnu.org
Cc: gnu-toolchain@rivosinc.com, Robin Dapp <rdapp.gcc@gmail.com>,
	Palmer Dabbelt <palmer@rivosinc.com>,
	Andrew Waterman <andrew@sifive.com>
Subject: Re: [PATCH v3] RISC-V: elide unnecessary sign extend when expanding cmp_and_jump
Date: Tue, 31 Oct 2023 18:45:22 -0600	[thread overview]
Message-ID: <495b19be-7e8c-4fa2-9ed4-19bd15044dfc@gmail.com> (raw)
In-Reply-To: <fb69298e-bc83-4aa8-9682-9e021084b981@rivosinc.com>



On 10/31/23 18:05, Vineet Gupta wrote:
> On 10/30/23 13:33, Jeff Law wrote:
>>
>>> +/* Helper function for riscv_extend_comparands to Sign-extend the OP.
>>> +   However if the OP is SI subreg promoted with an inner DI, such as
>>> +       (subreg/s/v:SI (reg/v:DI) 0
>>> +   just peel off the SUBREG to get DI, avoiding extraneous 
>>> extension.  */
>>> +
>>> +static void
>>> +riscv_sign_extend_if_not_subreg_prom (rtx *op)
>>> +{
>>> +  if (GET_MODE (*op) == SImode
> 
> So I may have been partially wrong about v2 patch being wrong and 
> needing this fixup ;-) [1]
> 
> It seems we don't have to limit this to SImode. I re-read the calling 
> convention doc [2] and it says this
> 
> "When passed in registers or on the stack, integer scalars narrower than 
> XLEN
>   bits are widened according to the sign of their type up to 32 bits, then
>   sign-extended to XLEN bits."
> 
> This essentially means signed short, and signed char will be already 
> sign-extended at caller site and need not be done in callee: Palmer 
> mention in internal slack that unadorned char is unsigned on RISC-V 
> hence we don't see the compiler extra work for say 
> gcc.dg/torture/pr75964.c. If the test is however tweaked to use signed 
> chars (or short), it seems caller is doing the work (adjusting the 
> constant being passed to be a sign-extended variant).
> 
> This further validates Jeff's comment about checking for 
> SUBREG_PROMOTED_SIGNED_P (it was anyhow the right thing to begin with 
> anyways).
> 
> At this point I feel like I'm into splitting hairs (in vain) territory, 
> as fixing this might not matter much in practice ...
> 
> I'd suppose we go ahead with the v3 with changes Jeff asked for and 
> maybe do a later fixup to relax SI.
Consider any such fixup pre-approved.  I was thinking that the 8/16 bit 
sub-objects should probably be extended one way or another.  It wouldn't 
make much sense not to.

Not as much of a win as I'd hoped.  But I'll take it

jeff

      reply	other threads:[~2023-11-01  0:45 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-30  3:21 Vineet Gupta
2023-10-30 16:43 ` Patrick O'Neill
2023-10-30 20:33 ` Jeff Law
2023-10-30 23:21   ` Vineet Gupta
2023-10-31 23:45     ` Vineet Gupta
2023-11-01  0:05   ` Vineet Gupta
2023-11-01  0:45     ` Jeff Law [this message]

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=495b19be-7e8c-4fa2-9ed4-19bd15044dfc@gmail.com \
    --to=jeffreyalaw@gmail.com \
    --cc=andrew@sifive.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=gnu-toolchain@rivosinc.com \
    --cc=palmer@rivosinc.com \
    --cc=rdapp.gcc@gmail.com \
    --cc=vineetg@rivosinc.com \
    /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).