Also preserve SUBREG_PROMOTED_VAR_P in expr.c's convert_move.

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

2021-09-12  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.
This commit is contained in:
Roger Sayle 2021-09-12 15:18:57 +01:00
parent d71126eeea
commit b195fae7c1

View File

@ -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));