public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Also preserve SUBREG_PROMOTED_VAR_P in expr.c's convert_move.
@ 2021-09-11  9:28 Roger Sayle
  2021-09-11 15:17 ` Jeff Law
  0 siblings, 1 reply; 2+ messages in thread
From: Roger Sayle @ 2021-09-11  9:28 UTC (permalink / raw)
  To: 'GCC Patches'

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


This patch catches another place in the middle-end where it's possible
to preserve the SUBREG_PROMOTED_VAR_P annotation on a subreg to the
benefit of later RTL optimizations.  This adds the same logic to
expr.c's convert_move as recently added to convert_modes.

On nvptx-none, the simple test program:

short foo (char c) { return c; }

currently generates three instructions:

mov.u32 %r23, %ar0;
cvt.u16.u32     %r24, %r23;
cvt.s32.s16     %value, %r24;

with this patch, we now generate just one:

mov.u32 %value, %ar0;


This patch should look familiar, it's almost identical to the recent patch
https://gcc.gnu.org/pipermail/gcc-patches/2021-August/578331.html but with
the fix https://gcc.gnu.org/pipermail/gcc-patches/2021-August/578519.html
[Apologies again for this breakage on affected (non-x86_64) targets; I hope
having that fixed within a few hours (before many folks even noticed a
problem) minimized the inconvenience].

This patch has been tested on x86_64-pc-linux-gnu with "make bootstrap"
and "make -k check" with no new failures, and on a cross-compiler to
nvptx-none, with no new failures in its testsuite.  OK for mainline?


2021-09-11  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
	* expr.c (convert_move): Preserve SUBREG_PROMOTED_VAR_P when
	creating a (wider) partial subreg from a SUBREG_PROMOTED_VAR_P
	subreg.

Roger
--


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

diff --git a/gcc/expr.c b/gcc/expr.c
index 17f2c2f..e0bcbcc 100644
--- a/gcc/expr.c
+++ b/gcc/expr.c
@@ -236,8 +236,27 @@ convert_move (rtx to, rtx from, int unsignedp)
 	  >= GET_MODE_PRECISION (to_int_mode))
       && SUBREG_CHECK_PROMOTED_SIGN (from, unsignedp))
     {
+      scalar_int_mode int_orig_mode;
+      scalar_int_mode int_inner_mode;
+      machine_mode orig_mode = GET_MODE (from);
+
       from = gen_lowpart (to_int_mode, SUBREG_REG (from));
       from_mode = to_int_mode;
+
+      /* Preserve SUBREG_PROMOTED_VAR_P if the new mode is wider than
+	 the original mode, but narrower than the inner mode.  */
+      if (GET_CODE (from) == SUBREG
+	  && is_a <scalar_int_mode> (orig_mode, &int_orig_mode)
+	  && GET_MODE_PRECISION (to_int_mode)
+	     > GET_MODE_PRECISION (int_orig_mode)
+	  && is_a <scalar_int_mode> (GET_MODE (SUBREG_REG (from)),
+				     &int_inner_mode)
+	  && GET_MODE_PRECISION (int_inner_mode)
+	     > GET_MODE_PRECISION (to_int_mode))
+	{
+	  SUBREG_PROMOTED_VAR_P (from) = 1;
+	  SUBREG_PROMOTED_SET (from, unsignedp);
+	}
     }
 
   gcc_assert (GET_CODE (to) != SUBREG || !SUBREG_PROMOTED_VAR_P (to));

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

* Re: [PATCH] Also preserve SUBREG_PROMOTED_VAR_P in expr.c's convert_move.
  2021-09-11  9:28 [PATCH] Also preserve SUBREG_PROMOTED_VAR_P in expr.c's convert_move Roger Sayle
@ 2021-09-11 15:17 ` Jeff Law
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2021-09-11 15:17 UTC (permalink / raw)
  To: Roger Sayle, 'GCC Patches'



On 9/11/2021 3:28 AM, Roger Sayle wrote:
> This patch catches another place in the middle-end where it's possible
> to preserve the SUBREG_PROMOTED_VAR_P annotation on a subreg to the
> benefit of later RTL optimizations.  This adds the same logic to
> expr.c's convert_move as recently added to convert_modes.
>
> On nvptx-none, the simple test program:
>
> short foo (char c) { return c; }
>
> currently generates three instructions:
>
> mov.u32 %r23, %ar0;
> cvt.u16.u32     %r24, %r23;
> cvt.s32.s16     %value, %r24;
>
> with this patch, we now generate just one:
>
> mov.u32 %value, %ar0;
>
>
> This patch should look familiar, it's almost identical to the recent patch
> https://gcc.gnu.org/pipermail/gcc-patches/2021-August/578331.html but with
> the fix https://gcc.gnu.org/pipermail/gcc-patches/2021-August/578519.html
> [Apologies again for this breakage on affected (non-x86_64) targets; I hope
> having that fixed within a few hours (before many folks even noticed a
> problem) minimized the inconvenience].
>
> This patch has been tested on x86_64-pc-linux-gnu with "make bootstrap"
> and "make -k check" with no new failures, and on a cross-compiler to
> nvptx-none, with no new failures in its testsuite.  OK for mainline?
>
>
> 2021-09-11  Roger Sayle  <roger@nextmovesoftware.com>
>
> gcc/ChangeLog
> 	* expr.c (convert_move): Preserve SUBREG_PROMOTED_VAR_P when
> 	creating a (wider) partial subreg from a SUBREG_PROMOTED_VAR_P
> 	subreg.
OK

Jeff

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

end of thread, other threads:[~2021-09-11 15:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-11  9:28 [PATCH] Also preserve SUBREG_PROMOTED_VAR_P in expr.c's convert_move Roger Sayle
2021-09-11 15:17 ` Jeff Law

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