Re: [PATCH] PR target/85358 patch v2: Add target hook to prevent default widening

2018-05-29 Thread Michael Meissner
On Sat, May 26, 2018 at 08:13:04AM +0200, Richard Biener wrote:
> On May 25, 2018 8:49:47 PM GMT+02:00, Michael Meissner 
>  wrote:
> >I redid the patch to make the target hook only apply for scalar float
> >points,
> >and I removed all of the integer only subcases.
> >
> >I have checked this on a little endian Power8 system, and verified that
> >it
> >bootstraps correctly and there are no regressions.  I have just started
> >an
> >x86_64 build.  Assuming that build has no regressions, can I check this
> >into
> >GCC 9?  This bug appears in GCC 8, and I would like to back port this
> >patch to
> >GCC 8 as well before GCC 8.2 goes out.
> 
> What happens if you hack genmodes to not claim IFmode has any wider 
> relationship with other modes? 

It breaks the initialization of all of the types that initializes each of the
types from smallest to widest using the wider tables.

So you either need to have special types that are initialized without using the
wider table, or you need two sets of wider tables, one used by the
initialization sequences, and the other by normal binop/unop expansion.

There may be other dependencies that I'm not aware of (such as it must be
within the MIN_MODE_FLOAT and MAX_MODE_FLOAT range).

-- 
Michael Meissner, IBM
IBM, M/S 2506R, 550 King Street, Littleton, MA 01460-6245, USA
email: meiss...@linux.ibm.com, phone: +1 (978) 899-4797



Re: [PATCH] PR target/85358 patch v2: Add target hook to prevent default widening

2018-05-28 Thread Segher Boessenkool
On Fri, May 25, 2018 at 02:49:47PM -0400, Michael Meissner wrote:
>   * target.def (default_fp_widening_p): New target hook to automatic
>   widening betwen two floating point modes.

"default" is a pretty bad name.

The rs6000 parts are fine of course, if the rest is.


Segher


Re: [PATCH] PR target/85358 patch v2: Add target hook to prevent default widening

2018-05-26 Thread Richard Biener
On May 25, 2018 8:49:47 PM GMT+02:00, Michael Meissner  
wrote:
>I redid the patch to make the target hook only apply for scalar float
>points,
>and I removed all of the integer only subcases.
>
>I have checked this on a little endian Power8 system, and verified that
>it
>bootstraps correctly and there are no regressions.  I have just started
>an
>x86_64 build.  Assuming that build has no regressions, can I check this
>into
>GCC 9?  This bug appears in GCC 8, and I would like to back port this
>patch to
>GCC 8 as well before GCC 8.2 goes out.

What happens if you hack genmodes to not claim IFmode has any wider 
relationship with other modes? 

Richard. 

>[gcc]
>2018-05-25  Michael Meissner  
>
>   PR target/85358
>   * target.def (default_fp_widening_p): New target hook to automatic
>   widening betwen two floating point modes.
>   * optabs.c (expand_binop): Do not automatically widen a binary or
>   unary scalar floating point op if the backend says that the
>   widening should not occur.
>   (expand_twoval_unop): Likewise.
>   (expand_twoval_binop): Likewise.
>   (expand_unop): Likewise.
>   * config/rs6000/rs6000.c (TARGET_DEFAULT_FP_WIDENING_P): Define.
>   (rs6000_default_fp_widening_p): New target hook to prevent
>   automatic widening between IEEE 128-bit floating point and IBM
>   extended double floating point.
>   * doc/tm.texi (Target Hooks): Document new target hook
>   default_fp_widening_p.
>   * doc/tm.texi.in (Target Hooks): Likewise.
>
>[gcc/testsuite]
>2018-05-25  Michael Meissner  
>
>   PR target/85358
>   * gcc.target/powerpc/pr85358.c: New test.



Re: [PATCH] PR target/85358 patch v2: Add target hook to prevent default widening

2018-05-25 Thread Michael Meissner
I redid the patch to make the target hook only apply for scalar float points,
and I removed all of the integer only subcases.

I have checked this on a little endian Power8 system, and verified that it
bootstraps correctly and there are no regressions.  I have just started an
x86_64 build.  Assuming that build has no regressions, can I check this into
GCC 9?  This bug appears in GCC 8, and I would like to back port this patch to
GCC 8 as well before GCC 8.2 goes out.

[gcc]
2018-05-25  Michael Meissner  

PR target/85358
* target.def (default_fp_widening_p): New target hook to automatic
widening betwen two floating point modes.
* optabs.c (expand_binop): Do not automatically widen a binary or
unary scalar floating point op if the backend says that the
widening should not occur.
(expand_twoval_unop): Likewise.
(expand_twoval_binop): Likewise.
(expand_unop): Likewise.
* config/rs6000/rs6000.c (TARGET_DEFAULT_FP_WIDENING_P): Define.
(rs6000_default_fp_widening_p): New target hook to prevent
automatic widening between IEEE 128-bit floating point and IBM
extended double floating point.
* doc/tm.texi (Target Hooks): Document new target hook
default_fp_widening_p.
* doc/tm.texi.in (Target Hooks): Likewise.

[gcc/testsuite]
2018-05-25  Michael Meissner  

PR target/85358
* gcc.target/powerpc/pr85358.c: New test.

-- 
Michael Meissner, IBM
IBM, M/S 2506R, 550 King Street, Littleton, MA 01460-6245, USA
email: meiss...@linux.ibm.com, phone: +1 (978) 899-4797
Index: gcc/target.def
===
--- gcc/target.def  (.../trunk) (revision 260548)
+++ gcc/target.def  (.../branches/ibm/ieee) (revision 260765)
@@ -3498,6 +3498,17 @@ If this hook allows @code{val} to have a
  hook_bool_mode_uhwi_false)
 
 DEFHOOK
+(default_fp_widening_p,
+ "Return true if GCC can automatically widen @var{mode} to @var{wider_mode}\n\
+if @var{wider_mode} supports an operation in hardware but @var{mode} does\n\
+not.  Both modes are scalar floating point modes.  The default hook always\n\
+returns true.  This hook should be used if all values in @var{mode} cannont\n\
+be represented in @var{wider_mode}, or the rounding characteristics are\n\
+different between the two modes.",
+ bool, (machine_mode wider_mode, machine_mode mode),
+ hook_bool_mode_mode_true)
+
+DEFHOOK
 (libgcc_floating_mode_supported_p,
  "Define this to return nonzero if libgcc provides support for the \n\
 floating-point mode @var{mode}, which is known to pass \n\
Index: gcc/optabs.c
===
--- gcc/optabs.c(.../trunk) (revision 260548)
+++ gcc/optabs.c(.../branches/ibm/ieee) (revision 260765)
@@ -1284,6 +1284,9 @@ expand_binop (machine_mode mode, optab b
 FOR_EACH_WIDER_MODE (wider_mode, mode)
   {
machine_mode next_mode;
+   if (SCALAR_FLOAT_MODE_P (mode)
+   && !targetm.default_fp_widening_p (wider_mode, mode))
+ continue;
if (optab_handler (binoptab, wider_mode) != CODE_FOR_nothing
|| (binoptab == smul_optab
&& GET_MODE_WIDER_MODE (wider_mode).exists (_mode)
@@ -1834,6 +1837,9 @@ expand_binop (machine_mode mode, optab b
   gcc_assert (!convert_optab_p (binoptab));
   FOR_EACH_WIDER_MODE (wider_mode, mode)
{
+ if (SCALAR_FLOAT_MODE_P (mode)
+ && !targetm.default_fp_widening_p (wider_mode, mode))
+   continue;
  if (optab_handler (binoptab, wider_mode)
  || (methods == OPTAB_LIB
  && optab_libfunc (binoptab, wider_mode)))
@@ -1989,6 +1995,9 @@ expand_twoval_unop (optab unoptab, rtx o
 {
   FOR_EACH_WIDER_MODE (wider_mode, mode)
{
+ if (SCALAR_FLOAT_MODE_P (mode)
+ && !targetm.default_fp_widening_p (wider_mode, mode))
+   continue;
  if (optab_handler (unoptab, wider_mode) != CODE_FOR_nothing)
{
  rtx t0 = gen_reg_rtx (wider_mode);
@@ -2070,6 +2079,9 @@ expand_twoval_binop (optab binoptab, rtx
 {
   FOR_EACH_WIDER_MODE (wider_mode, mode)
{
+ if (SCALAR_FLOAT_MODE_P (mode)
+ && !targetm.default_fp_widening_p (wider_mode, mode))
+   continue;
  if (optab_handler (binoptab, wider_mode) != CODE_FOR_nothing)
{
  rtx t0 = gen_reg_rtx (wider_mode);
@@ -2865,6 +2877,9 @@ expand_unop (machine_mode mode, optab un
   if (CLASS_HAS_WIDER_MODES_P (mclass))
 FOR_EACH_WIDER_MODE (wider_mode, mode)
   {
+   if (SCALAR_FLOAT_MODE_P (mode)
+   && !targetm.default_fp_widening_p (wider_mode, mode))
+ continue;
if (optab_handler (unoptab, wider_mode) != CODE_FOR_nothing)
  {
rtx xop0 = op0;
@@ -3032,6 +3047,9