public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: Roger Sayle <roger@nextmovesoftware.com>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] middle-end: Support ABIs that pass FP values as wider integers.
Date: Tue, 22 Feb 2022 23:09:18 +0100	[thread overview]
Message-ID: <7b4e8644-9982-a622-f10a-bd89af2e4d58@suse.de> (raw)
In-Reply-To: <008801d82806$771db4e0$65591ea0$@nextmovesoftware.com>

On 2/22/22 17:08, Roger Sayle wrote:
> 
> Hi Tom,
> 
> I'll admit that I'd not myself considered the ABI issues when I initially proposed
> experimental HFmode support for the nvptx backend, and was surprised when
> I finally tracked down the source of the problem you'd reported: that libgcc
> spots HFmode support exists and immediately starts passing/returning values
> in this type.
> 
> The one precedent that I can point to is that LLVM's nvptx backend passes
> HFmode values in SImode regs,   see https://reviews.llvm.org/D28540

Interesting, thanks for the link.

> Their motivation is that not all PTX ISAs support fp16, so for compatibility
> with say sm_30/sm_35, fp16 values are treated like b16, i.e. HImode.
> At this point, the nvptx ABI states that HImode values are passed as SImode,
> so we end up with the interesting mismatch of HFmode<->SImode.

Indeed, that sounds plausible.

And IIUC, that also means that this leaves the door open for us to 
implement fp16 support for pre-sm_53 using b16 in a compatible way.

Then I think the current solution is OK, thanks for digging this up.

Thanks,
-Tom

> I guess the same thing affects host code, where an i386/x86 host that
> doesn't support 16-bit floating point, can pass "unsigned short" values
> to and from the accelerator, and likewise this HImode locally gets passed
> in a wider (often WORD_MODE) integer types on most x86 ABIs.
> 
> My guess is that passing SFmode in DImode may have been supported
> in older versions of GCC, before handling of SUBREGs was tightened up,
> so this might be considered a regression.
> 
> Cheers,
> Roger
> --
> 
>> -----Original Message-----
>> From: Tom de Vries <tdevries@suse.de>
>> Sent: 22 February 2022 15:43
>> To: Roger Sayle <roger@nextmovesoftware.com>; gcc-patches@gcc.gnu.org
>> Subject: Re: [PATCH] middle-end: Support ABIs that pass FP values as wider
>> integers.
>>
>> On 2/9/22 21:12, Roger Sayle wrote:
>>>
>>> This patch adds middle-end support for target ABIs that pass/return
>>> floating point values in integer registers with precision wider than
>>> the original FP mode.  An example, is the nvptx backend where 16-bit
>>> HFmode registers are passed/returned as (promoted to) SImode registers.
>>> Unfortunately, this currently falls foul of the various (recent?)
>>> sanity checks that (very sensibly) prevent creating paradoxical
>>> SUBREGs of floating point registers.  The approach below is to
>>> explicitly perform the conversion/promotion in two steps, via an
>>> integer mode of same precision as the floating point value.  So on
>>> nvptx, 16-bit HFmode is initially converted to 16-bit HImode (using
>>> SUBREG), then zero-extended to SImode, and likewise when going the
>>> other way, parameters truncated to HImode then converted to HFmode
>>> (using SUBREG).  These changes are localized to expand_value_return
>>> and expanding DECL_RTL to support strange ABIs, rather than inside
>>> convert_modes or gen_lowpart, as mismatched precision integer/FP
>>> conversions should be explicit in the RTL, and these semantics not generally
>> visible/implicit in user code.
>>>
>>
>> Hi Roger,
>>
>> I cannot comment on the patch, but I do wonder (after your "strange ABI"
>> comment): did we actively decide on (or align to) a register passing ABI for
>> HFmode, or has it merely been decided by the implementation of
>> promote_arg:
>> ...
>> static machine_mode
>> promote_arg (machine_mode mode, bool prototyped) {
>>     if (!prototyped && mode == SFmode)
>>       /* K&R float promotion for unprototyped functions.  */
>>       mode = DFmode;
>>     else if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (SImode))
>>       mode = SImode;
>>
>>     return mode;
>> }
>> ...
>>
>> There may be a rationale why it's good to pass a HF as SI, but it's not
>> documented there.
>>
>> Anyway, I checked what cuda does for HF, and it passes a byte array:
>> ...
>> .param .align 2 .b8 _Z5helloPj6__halfs_param_1[2], ...
>>
>> So, I guess what I'm saying is I'd like to understand why we're having the HF -> SI
>> promotion.
>>
>> Thanks,
>> - Tom
> 

  reply	other threads:[~2022-02-22 22:09 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-09 20:12 Roger Sayle
2022-02-17 14:35 ` PING - " Tobias Burnus
2022-02-23  8:42   ` PING**2 " Tobias Burnus
2022-02-28  9:41     ` PING**3 " Tobias Burnus
2022-02-28 12:54       ` Richard Biener
2022-03-02 19:18         ` Jeff Law
2022-03-14  8:06           ` PING**4 " Tom de Vries
2022-03-14  8:39             ` Roger Sayle
2022-03-14  9:09               ` Richard Biener
2022-03-14  9:46                 ` Roger Sayle
2022-03-14 10:14                   ` Richard Biener
2022-03-14 11:49                     ` Roger Sayle
2022-03-14 13:27                       ` Richard Biener
2022-03-14 14:30                         ` Roger Sayle
2022-03-14 14:40                           ` Richard Biener
2022-03-14 15:31                           ` Richard Sandiford
2022-03-14 14:59                 ` Jeff Law
2022-03-14 15:08               ` Jeff Law
2022-02-22 15:42 ` Tom de Vries
2022-02-22 16:08   ` Roger Sayle
2022-02-22 22:09     ` Tom de Vries [this message]
2022-02-22 23:19       ` Roger Sayle
2022-03-14 15:30 ` Jeff Law
2022-03-14 17:24   ` Roger Sayle

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=7b4e8644-9982-a622-f10a-bd89af2e4d58@suse.de \
    --to=tdevries@suse.de \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=roger@nextmovesoftware.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).