public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] middle-end: Support ABIs that pass FP values as wider integers.
@ 2022-02-09 20:12 Roger Sayle
  2022-02-17 14:35 ` PING - " Tobias Burnus
                   ` (2 more replies)
  0 siblings, 3 replies; 24+ messages in thread
From: Roger Sayle @ 2022-02-09 20:12 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1746 bytes --]


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.

This patch has been tested on x86_64-pc-linux-gnu with make bootstrap
and make -k check with no new failures, and on nvptx-none, where it is
the middle-end portion of a pair of patches to allow the default ISA to
be advanced.  Ok for mainline?


2022-02-09  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
       * cfgexpand.cc (expand_value_return): Allow backends to promote
       a scalar floating point return value to a wider integer mode.
       * expr.cc (expand_expr_real_1) [expand_decl_rtl]: Likewise, allow
       backends to promote scalar FP PARM_DECLs to wider integer modes.


Thanks in advance,
Roger
--


[-- Attachment #2: patchi4.txt --]
[-- Type: text/plain, Size: 2206 bytes --]

diff --git a/gcc/cfgexpand.cc b/gcc/cfgexpand.cc
index d51af2e..c377f16 100644
--- a/gcc/cfgexpand.cc
+++ b/gcc/cfgexpand.cc
@@ -3715,7 +3715,22 @@ expand_value_return (rtx val)
         mode = promote_function_mode (type, old_mode, &unsignedp, funtype, 1);
 
       if (mode != old_mode)
-	val = convert_modes (mode, old_mode, val, unsignedp);
+	{
+	  /* Some ABIs require scalar floating point modes to be returned
+	     in a wider scalar integer mode.  We need to explicitly
+	     reinterpret to an integer mode of the correct precision
+	     before extending to the desired result.  */
+	  if (SCALAR_INT_MODE_P (mode)
+	      && SCALAR_FLOAT_MODE_P (old_mode)
+	      && known_gt (GET_MODE_SIZE (mode), GET_MODE_SIZE (old_mode)))
+	    {
+	      scalar_int_mode imode = int_mode_for_mode (old_mode).require ();
+	      val = force_reg (imode, gen_lowpart (imode, val));
+	      val = convert_modes (mode, imode, val, 1);
+	    }
+	  else
+	    val = convert_modes (mode, old_mode, val, unsignedp);
+	}
 
       if (GET_CODE (return_reg) == PARALLEL)
 	emit_group_load (return_reg, val, type, int_size_in_bytes (type));
diff --git a/gcc/expr.cc b/gcc/expr.cc
index 35e4029..e4efdcd 100644
--- a/gcc/expr.cc
+++ b/gcc/expr.cc
@@ -10674,6 +10674,19 @@ expand_expr_real_1 (tree exp, rtx target, machine_mode tmode,
 	    pmode = promote_ssa_mode (ssa_name, &unsignedp);
 	  gcc_assert (GET_MODE (decl_rtl) == pmode);
 
+	  /* Some ABIs require scalar floating point modes to be passed
+	     in a wider scalar integer mode.  We need to explicitly
+	     truncate to an integer mode of the correct precision before
+	     using a SUBREG to reinterpret as a floating point value.  */
+	  if (SCALAR_FLOAT_MODE_P (mode)
+	      && SCALAR_INT_MODE_P (pmode)
+	      && known_lt (GET_MODE_SIZE (mode), GET_MODE_SIZE (pmode)))
+	    {
+	      scalar_int_mode imode = int_mode_for_mode (mode).require ();
+	      temp = force_reg (imode, gen_lowpart (imode, decl_rtl));
+	      return gen_lowpart_SUBREG (mode, temp);
+	    }
+
 	  temp = gen_lowpart_SUBREG (mode, decl_rtl);
 	  SUBREG_PROMOTED_VAR_P (temp) = 1;
 	  SUBREG_PROMOTED_SET (temp, unsignedp);

^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2022-03-14 17:24 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-09 20:12 [PATCH] middle-end: Support ABIs that pass FP values as wider integers 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
2022-02-22 23:19       ` Roger Sayle
2022-03-14 15:30 ` Jeff Law
2022-03-14 17:24   ` Roger Sayle

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).