public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Li, Pan2" <pan2.li@intel.com>
To: Robin Dapp <rdapp.gcc@gmail.com>,
	"gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Cc: "juzhe.zhong@rivai.ai" <juzhe.zhong@rivai.ai>,
	"kito.cheng@sifive.com" <kito.cheng@sifive.com>,
	"Wang, Yanzhang" <yanzhang.wang@intel.com>
Subject: RE: [PATCH v6] RISC-V: Support CALL for RVV floating-point dynamic rounding
Date: Mon, 24 Jul 2023 12:03:08 +0000	[thread overview]
Message-ID: <MW5PR11MB59084BA409907424FE489158A902A@MW5PR11MB5908.namprd11.prod.outlook.com> (raw)
In-Reply-To: <MW5PR11MB590830483C00EC11C7DB16D3A902A@MW5PR11MB5908.namprd11.prod.outlook.com>

Fix some typo inline,  sorry for inconvenience.

-----Original Message-----
From: Li, Pan2 
Sent: Monday, July 24, 2023 7:59 PM
To: Robin Dapp <rdapp.gcc@gmail.com>; gcc-patches@gcc.gnu.org
Cc: juzhe.zhong@rivai.ai; kito.cheng@sifive.com; Wang, Yanzhang <yanzhang.wang@intel.com>
Subject: RE: [PATCH v6] RISC-V: Support CALL for RVV floating-point dynamic rounding

Thanks Robin for comments.

>> Does prev_nonnote_nondebug_insn_bb help here?  In general, we scan
>> back here to the last insn and "recover" if it was a call?  Why
>> can't we set the proper value already before exiting the function?

Good to learn prev_nonnote_nondebug_insn_bb, will have a try here.
First we mark the call as DYN_CALL. We expect the insn next to the call to emit the backup insn.
However, if next instruction is DYN_NONE, the mode switching it self will never call emit. Thus, for each
Insn is DYN_NONE, we will reset it to DYN if the last insn is call and let the mode switching to emit properly.

When meet a call, we assume the rounding mode will be clobbered.

>> What about nondebug insns?  Also maybe next_nonnote_nondebug_insn_bb
>> helps?  How about splitting the function in detection and emit?
>> I.e. bb_ends_in_call (or so) and the emit part.  That way it
>> could be more obvious in "needed" what needs to be done.

The point here is that the call may be the last insn of current bb. Then we have chance to emit backup insn AFTER
the call, because the emit by default emit the insn before current insn.

Thus we try to make up this during the needed process, I know this may not be a good idea but it is the only way
I can locate shortly. I may try to find another way if we can control the insn emit location for each insn.

Pan

-----Original Message-----
From: Robin Dapp <rdapp.gcc@gmail.com> 
Sent: Monday, July 24, 2023 6:29 PM
To: Li, Pan2 <pan2.li@intel.com>; gcc-patches@gcc.gnu.org
Cc: rdapp.gcc@gmail.com; juzhe.zhong@rivai.ai; kito.cheng@sifive.com; Wang, Yanzhang <yanzhang.wang@intel.com>
Subject: Re: [PATCH v6] RISC-V: Support CALL for RVV floating-point dynamic rounding

Hi Pan,

> +  for (insn = PREV_INSN (cur_insn); insn; insn = PREV_INSN (insn))
> +    {
> +      if (INSN_P (insn))
> +	{
> +	  if (CALL_P (insn))
> +	    mode = FRM_MODE_DYN;
> +	  break;
> +	}
> +
> +      if (insn == BB_HEAD (bb))
> +	break;
> +    }
> +
> +  return mode;
> +}

Does prev_nonnote_nondebug_insn_bb help here?  In general, we scan
back here to the last insn and "recover" if it was a call?  Why
can't we set the proper value already before exiting the function?

I guess the more general question is more towards call-clobbered or
not?  In this patch we assume the rounding mode is call clobbered
and restore it ourselves.  Has there been any kind of consensus
on this?  Intuitively I would have expected a function that requires
a non-standard rounding mode to set and restore it itself. 

> +
> +/* Insert the backup frm insn to the end of the bb if and only if the call
> +   is the last insn of this bb.  */
> +
> +static void
> +riscv_frm_reconcile_call_as_bb_end (rtx_insn *cur_insn)
> +{
> +  rtx_insn *insn;
> +  basic_block bb = BLOCK_FOR_INSN (cur_insn);
> +
> +  gcc_assert (CALL_P (cur_insn));
> +
> +  if (cur_insn != BB_END (bb))
> +    {
> +      for (insn = NEXT_INSN (cur_insn); insn; insn = NEXT_INSN (insn))
> +	{
> +	  if (INSN_P (insn)) /* If there is one insn after call, do nothing.  */
> +	    return;

What about nondebug insns?  Also maybe next_nonnote_nondebug_insn_bb
helps?  How about splitting the function in detection and emit?
I.e. bb_ends_in_call (or so) and the emit part.  That way it
could be more obvious in "needed" what needs to be done.

Are we handling sibcalls and tail calls properly here?

In general I'm still a bit wary that we are checking mode != prev_mode
but cannot really pinpoint why.  I would have hoped that the generic
code only calls us when this check is unnecessary and if not the
"needed" hook should be adjusted.

I also find it a bit odd to emit instructions when checking
if another mode is needed.  If what's required cannot be accomplished
with the current common code, shouldn't we rather try to amend that?

Regards
 Robin


  reply	other threads:[~2023-07-24 12:03 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-19  3:28 [PATCH v1] " pan2.li
2023-07-19  3:31 ` juzhe.zhong
2023-07-19  6:30   ` Li, Pan2
2023-07-20  6:43 ` [PATCH v4] " pan2.li
2023-07-20  6:47   ` juzhe.zhong
2023-07-21  3:11   ` juzhe.zhong
2023-07-21  6:44     ` Li, Pan2
2023-07-23 13:11 ` [PATCH v5] " pan2.li
2023-07-24  0:53   ` juzhe.zhong
2023-07-24  1:51     ` Li, Pan2
2023-07-24  2:45       ` Li, Pan2
2023-07-24  2:42 ` [PATCH v6] " pan2.li
2023-07-24 10:28   ` Robin Dapp
2023-07-24 11:59     ` Li, Pan2
2023-07-24 12:03       ` Li, Pan2 [this message]
2023-07-25  5:51 ` [PATCH v7] " pan2.li
2023-07-25  6:07   ` Li, Pan2
2023-07-25  8:38     ` Robin Dapp
2023-07-25 11:53       ` Li, Pan2
2023-07-25 13:23         ` Kito Cheng
2023-07-25 14:12           ` Robin Dapp
2023-07-26 13:08             ` Robin Dapp
2023-07-26 21:40               ` Jeff Law
2023-07-26 22:21                 ` 钟居哲
2023-07-26 22:46                   ` Jeff Law
2023-07-26 22:56                     ` 钟居哲
2023-07-27  1:38                       ` Li, Pan2
2023-07-27  8:19                         ` Li, Pan2
2023-07-27  2:09               ` Li, Pan2
2023-07-27  7:25                 ` Robin Dapp
2023-07-27  8:26                   ` Li, Pan2
2023-07-27  8:41                     ` Robin Dapp
2023-07-27 10:27                       ` Li, Pan2
     [not found]             ` <63471C6E126E44CF+D1CEA4C9-0050-43CD-8DE3-26EBD7AEE6DA@rivai.ai>
2023-07-26 13:35               ` Li, Pan2
2023-07-26 13:43                 ` Li, Pan2
2023-07-26 13:46               ` Robin Dapp
2023-07-26 13:57                 ` Kito Cheng
2023-07-26 14:05                   ` Kito Cheng
2023-07-26 14:10                     ` Robin Dapp
2023-07-26 14:18                 ` 钟居哲
2023-07-26 14:30                   ` Li, Pan2
2023-07-26 15:34                     ` Kito Cheng
2023-07-26 16:00                       ` Palmer Dabbelt
2023-07-26 21:01                     ` Robin Dapp
2023-07-28  1:15 ` [PATCH v8] " pan2.li
2023-07-28 10:05   ` Robin Dapp
2023-07-28 12:34     ` Li, Pan2
2023-08-01  7:50       ` Kito Cheng
2023-08-01  8:00         ` Li, Pan2

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=MW5PR11MB59084BA409907424FE489158A902A@MW5PR11MB5908.namprd11.prod.outlook.com \
    --to=pan2.li@intel.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=juzhe.zhong@rivai.ai \
    --cc=kito.cheng@sifive.com \
    --cc=rdapp.gcc@gmail.com \
    --cc=yanzhang.wang@intel.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).