public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] simplify-rtx: Punt on simplify_{,gen_}subreg to IBM double double if bits are lost [PR99648]
@ 2021-04-12 20:09 Jakub Jelinek
  2021-04-13  6:56 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2021-04-12 20:09 UTC (permalink / raw)
  To: Richard Biener, Eric Botcazou, Jeff Law; +Cc: gcc-patches

Hi!

Similarly to PR95450 done on GIMPLE, this patch punts if we try to
simplify_{gen_,}subreg from some constant into the IBM double double
IFmode (or sometimes TFmode) if the double double format wouldn't preserve
the bits.  Not all values are valid in IBM double double, e.g. the format
requires that the upper double is the whole value rounded to double, and
if in some cases such as in the pr71522.c testcase with -m32 -Os -mcpu=power7
some non-floating data is copied through long double variable, we can
simplify a subreg into something that has different value.

Fixed by punting if the planned simplify_immed_subreg result doesn't
encode to bitwise identical values compared to what we were decoding.

As for the simplify_gen_subreg change, I think it would be desirable
to just avoid creating SUBREGs of constants on all targets and for all
constants, if simplify_immed_subreg simplified, fine, otherwise punt,
but as we are late in GCC11 development, the patch instead guards this
behavior on MODE_COMPOSITE_P (outermode) - i.e. only conversions to
powerpc{,64,64le} double double long double - and only for the cases where
simplify_immed_subreg was called.

Bootstrapped/regtested on powerpc64{,le}-linux, on powerpc64-linux tested
with -m32/-m64, ok for trunk?

2021-04-12  Jakub Jelinek  <jakub@redhat.com>

	PR target/99648
	* simplify-rtx.c (simplify_immed_subreg): For MODE_COMPOSITE_P
	outermode, return NULL if the result doesn't encode back to the
	original byte sequence.
	(simplify_gen_subreg): Don't create SUBREGs from constants to
	MODE_COMPOSITE_P outermode.

--- gcc/simplify-rtx.c.jj	2021-04-10 12:45:22.189863341 +0200
+++ gcc/simplify-rtx.c	2021-04-12 12:06:01.469088000 +0200
@@ -7035,12 +7035,19 @@ simplify_immed_subreg (fixed_size_mode o
       while (buffer.length () < buffer_bytes)
 	buffer.quick_push (filler);
     }
-  else
+  else if (!native_encode_rtx (innermode, x, buffer, first_byte, inner_bytes))
+    return NULL_RTX;
+  rtx ret = native_decode_rtx (outermode, buffer, 0);
+  if (ret && MODE_COMPOSITE_P (outermode))
     {
-      if (!native_encode_rtx (innermode, x, buffer, first_byte, inner_bytes))
+      auto_vec<target_unit, 128> buffer2 (buffer_bytes);
+      if (!native_encode_rtx (outermode, ret, buffer2, 0, buffer_bytes))
 	return NULL_RTX;
-      }
-  return native_decode_rtx (outermode, buffer, 0);
+      for (unsigned int i = 0; i < buffer_bytes; ++i)
+	if (buffer[i] != buffer2[i])
+	  return NULL_RTX;
+    }
+  return ret;
 }
 
 /* Simplify SUBREG:OUTERMODE(OP:INNERMODE, BYTE)
@@ -7336,6 +7343,13 @@ simplify_context::simplify_gen_subreg (m
       || GET_MODE (op) == VOIDmode)
     return NULL_RTX;
 
+  if (MODE_COMPOSITE_P (outermode)
+      && (CONST_SCALAR_INT_P (op)
+	  || CONST_DOUBLE_AS_FLOAT_P (op)
+	  || CONST_FIXED_P (op)
+	  || GET_CODE (op) == CONST_VECTOR))
+    return NULL_RTX;
+
   if (validate_subreg (outermode, innermode, op, byte))
     return gen_rtx_SUBREG (outermode, op, byte);
 

	Jakub


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

* Re: [PATCH] simplify-rtx: Punt on simplify_{,gen_}subreg to IBM double double if bits are lost [PR99648]
  2021-04-12 20:09 [PATCH] simplify-rtx: Punt on simplify_{,gen_}subreg to IBM double double if bits are lost [PR99648] Jakub Jelinek
@ 2021-04-13  6:56 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2021-04-13  6:56 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Eric Botcazou, Jeff Law, gcc-patches

On Mon, 12 Apr 2021, Jakub Jelinek wrote:

> Hi!
> 
> Similarly to PR95450 done on GIMPLE, this patch punts if we try to
> simplify_{gen_,}subreg from some constant into the IBM double double
> IFmode (or sometimes TFmode) if the double double format wouldn't preserve
> the bits.  Not all values are valid in IBM double double, e.g. the format
> requires that the upper double is the whole value rounded to double, and
> if in some cases such as in the pr71522.c testcase with -m32 -Os -mcpu=power7
> some non-floating data is copied through long double variable, we can
> simplify a subreg into something that has different value.
> 
> Fixed by punting if the planned simplify_immed_subreg result doesn't
> encode to bitwise identical values compared to what we were decoding.
> 
> As for the simplify_gen_subreg change, I think it would be desirable
> to just avoid creating SUBREGs of constants on all targets and for all
> constants, if simplify_immed_subreg simplified, fine, otherwise punt,
> but as we are late in GCC11 development, the patch instead guards this
> behavior on MODE_COMPOSITE_P (outermode) - i.e. only conversions to
> powerpc{,64,64le} double double long double - and only for the cases where
> simplify_immed_subreg was called.
> 
> Bootstrapped/regtested on powerpc64{,le}-linux, on powerpc64-linux tested
> with -m32/-m64, ok for trunk?

OK.

Richard.

> 2021-04-12  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR target/99648
> 	* simplify-rtx.c (simplify_immed_subreg): For MODE_COMPOSITE_P
> 	outermode, return NULL if the result doesn't encode back to the
> 	original byte sequence.
> 	(simplify_gen_subreg): Don't create SUBREGs from constants to
> 	MODE_COMPOSITE_P outermode.
> 
> --- gcc/simplify-rtx.c.jj	2021-04-10 12:45:22.189863341 +0200
> +++ gcc/simplify-rtx.c	2021-04-12 12:06:01.469088000 +0200
> @@ -7035,12 +7035,19 @@ simplify_immed_subreg (fixed_size_mode o
>        while (buffer.length () < buffer_bytes)
>  	buffer.quick_push (filler);
>      }
> -  else
> +  else if (!native_encode_rtx (innermode, x, buffer, first_byte, inner_bytes))
> +    return NULL_RTX;
> +  rtx ret = native_decode_rtx (outermode, buffer, 0);
> +  if (ret && MODE_COMPOSITE_P (outermode))
>      {
> -      if (!native_encode_rtx (innermode, x, buffer, first_byte, inner_bytes))
> +      auto_vec<target_unit, 128> buffer2 (buffer_bytes);
> +      if (!native_encode_rtx (outermode, ret, buffer2, 0, buffer_bytes))
>  	return NULL_RTX;
> -      }
> -  return native_decode_rtx (outermode, buffer, 0);
> +      for (unsigned int i = 0; i < buffer_bytes; ++i)
> +	if (buffer[i] != buffer2[i])
> +	  return NULL_RTX;
> +    }
> +  return ret;
>  }
>  
>  /* Simplify SUBREG:OUTERMODE(OP:INNERMODE, BYTE)
> @@ -7336,6 +7343,13 @@ simplify_context::simplify_gen_subreg (m
>        || GET_MODE (op) == VOIDmode)
>      return NULL_RTX;
>  
> +  if (MODE_COMPOSITE_P (outermode)
> +      && (CONST_SCALAR_INT_P (op)
> +	  || CONST_DOUBLE_AS_FLOAT_P (op)
> +	  || CONST_FIXED_P (op)
> +	  || GET_CODE (op) == CONST_VECTOR))
> +    return NULL_RTX;
> +
>    if (validate_subreg (outermode, innermode, op, byte))
>      return gen_rtx_SUBREG (outermode, op, byte);
>  
> 
> 	Jakub
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg,
Germany; GF: Felix Imendörffer; HRB 36809 (AG Nuernberg)

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

end of thread, other threads:[~2021-04-13  6:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-12 20:09 [PATCH] simplify-rtx: Punt on simplify_{,gen_}subreg to IBM double double if bits are lost [PR99648] Jakub Jelinek
2021-04-13  6:56 ` Richard Biener

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