public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jeff Law <jeffreyalaw@gmail.com>
To: Manolis Tsamis <manolis.tsamis@vrull.eu>
Cc: Vineet Gupta <vineetg@rivosinc.com>,
	Philipp Tomsich <philipp.tomsich@vrull.eu>,
	Jivan Hakobyan <jivanhakobyan9@gmail.com>,
	gcc-patches@gcc.gnu.org
Subject: Re: RISC-V: Folding memory for FP + constant case
Date: Fri, 4 Aug 2023 10:23:12 -0600	[thread overview]
Message-ID: <e259a35c-8877-70c9-5a7f-4cee11236f3a@gmail.com> (raw)
In-Reply-To: <CAM3yNXoRMKQJ8XQEvNm_1P4Ky2V651x7pTzbcyAuwX+ey-mV1Q@mail.gmail.com>



On 8/4/23 03:52, Manolis Tsamis wrote:
> Hi all,
> 
> It is true that regcprop currently does not propagate sp and hence
> leela is not optimized, but from what I see this should be something
> we can address.
> 
> The reason that the propagation fails is this check that I have added
> when I introduced maybe_copy_reg_attrs:
> 
> else if (REG_POINTER (new_reg) != REG_POINTER (old_reg))
>    {
>      /* Only a single instance of STACK_POINTER_RTX must exist and we cannot
>         modify it. Allow propagation if REG_POINTER for OLD_REG matches and
>         don't touch ORIGINAL_REGNO and REG_ATTRS. */
>      return NULL_RTX;
>    }
> 
> To be honest I did add this back then just to be on the safe side of
> whether a mismatch in REG_POINTER after propagation would be an issue
> (since the original regcprop had caused enough problems).
No worries.  Obviously not propagating is the safe thing to do and if we 
find notable missed cases we can always refine the existing code like 
we're considering now.

> 
> I see two ways to solve this and make fmo able to optimize leela as well:
>   1) Remove the REG_POINTER check in regcprop if that is safe. My
> understanding is that REG_POINTER is used as a hint and there would be
> no correctness issues.
REG_POINTER is meant to be conservatively correct.  If REG_POINTER is 
set, then the register must be a pointer to a valid memory location.  If 
REG_POINTER is not set, then it may or may not point to a valid memory 
location.  sp, fp, ap are by definition pointers and thus have 
REG_POINTER set.

With that definition we can safely copy propagate away an sp->gpr copy 
from a REG_POINTER standpoint.










>   2) Mark the corresponding registers with REG_POINTER. I'm not sure
> where that is supposed to happen.
> 
> Since the instructions look like this:
>    (insn 113 11 16 2 (set (reg:DI 15 a5 [226])
>            (reg/f:DI 2 sp)) 179 {*movdi_64bit}
>         (nil))
> 
> I assume that we'd want to mark a5 as REG_POINTER anyway (which is
> not), and in that case propagation would work.
I'd strongly recommend against that.  The problem is the destination 
register might have been used in another context as an index register. 
We've fixed a few bugs in this space through the years I suspect there 
may be others lurking.  You can't directly set that up in C code, but 
once you get down to RTL it can happen.


> On the other hand if there's no correctness issue w.r.t. REG_POINTER
> and regcprop then removing the additional check would increase
> propagation opportunities in general which is also good.
I think you can safely remove this limitation.

jeff

  reply	other threads:[~2023-08-04 16:23 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-12 20:59 Jivan Hakobyan
2023-07-15  6:16 ` Jeff Law
2023-07-25 11:24   ` Jivan Hakobyan
2023-07-26  3:31     ` Jeff Law
2023-08-01 19:14       ` Vineet Gupta
2023-08-01 20:16         ` Jivan Hakobyan
2023-08-01 21:55         ` Jeff Law
2023-08-01 22:07           ` Philipp Tomsich
2023-08-01 23:03             ` Vineet Gupta
2023-08-01 23:06               ` Philipp Tomsich
2023-08-01 23:13                 ` Vineet Gupta
2023-08-01 23:27                   ` Jeff Law
2023-08-01 23:38                     ` Vineet Gupta
2023-08-01 23:52                       ` Jeff Law
2023-08-04  9:52                         ` Manolis Tsamis
2023-08-04 16:23                           ` Jeff Law [this message]
2023-08-05  9:27                             ` Manolis Tsamis
2023-08-01 23:22                 ` Jeff Law
2023-08-01 23:28                   ` Vineet Gupta
2023-08-01 23:21               ` Jeff Law
2023-08-09 19:31 ` Jeff Law

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=e259a35c-8877-70c9-5a7f-4cee11236f3a@gmail.com \
    --to=jeffreyalaw@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jivanhakobyan9@gmail.com \
    --cc=manolis.tsamis@vrull.eu \
    --cc=philipp.tomsich@vrull.eu \
    --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).