[PATCH, rs6000] Lower vec_perm vectorization cost for P8/P9

2019-09-28 Thread Kewen.Lin
Hi,

Recently we are revisiting vectorization cost setting in 
rs6000_builtin_vectorization_cost, and found the current cost of
vec_perm on VSX looks overpriced for Power8 and Power9.  The high
cost was set for Power7 single VSU pipe, but Power8 and Power9
have supported more VSX units, the performance evaluation on
SPEC2017 Power9 shows 2%+ gain on 538.imagick_r, while SPEC2006/
SPEC2017 Power8 evaluations show ~2% gains on 453.povray/
511.povray_r, all don't have any remarkable degradations.

This patch is to lower vec_perm vectorization cost for all
non Power7 VSX architecture (currently Power8 and Power9).

Bootstrapped and regress tested on powerpc64le-linux-gnu.  
Is OK for trunk?


Thanks,
Kewen


gcc/ChangeLog

2019-09-29  Kewen Lin  

* config/rs6000/rs6000.c (rs6000_builtin_vectorization_cost): Lower
vec_perm cost to 1 for non-Power7 VSX architectures.



diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index c2834bd..6b2c6fa 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -4774,7 +4774,8 @@ rs6000_builtin_vectorization_cost (enum 
vect_cost_for_stmt type_of_cost,
 return 1;

   case vec_perm:
-   if (TARGET_VSX)
+   /* Power7 has only one VSU pipe, make it a bit expensive.  */
+   if (TARGET_VSX && rs6000_tune == PROCESSOR_POWER7)
  return 3;
else
  return 1;



Re: [PATCH, rs6000] Support float from/to long conversion vectorization

2019-09-28 Thread Kewen.Lin
Hi Segher,

on 2019/9/28 上午12:12, Segher Boessenkool wrote:
> On Fri, Sep 27, 2019 at 04:52:30PM +0800, Kewen.Lin wrote:
>>> (Maybe one of the gen* tools complains any_fix needs a mode? :QI will do
>>> if so, or :P if you like that better).
>>
>> I didn't encounter any errors, it sounds it's allowable now?
> 
> Ah, that particular warning (from genrecog.c) only happens for a SET,
> so you won't get it here.  It would be a warning, not an error, btw.
> 

Thanks for the clarification.  :)

Committed by r276266.


Thanks,
Kewen



[RFH][libgcc] fp-bit bit ordering (PR 78804)

2019-09-28 Thread Oleg Endo
Hi,

I've been dragging this patch along with me for a while.
At the moment, I don't have the resources to fully test it as requested
by Ian in the PR discussion.

So I would like to ask for general comments on this one and hope that
folks with bigger automated test setups can run the patch through their
machinery for little endian targets.


Summary of the story:

I've noticed this issue on the RX on GCC 6, but it seems it's been
there forever.

On RX, fp-bit is used for software floating point emulation.  The RX
target also uses "MS bit-field" layout by default.  This means that
code like

struct
{
  fractype fraction:FRACBITS __attribute__ ((packed));
  unsigned int exp:EXPBITS __attribute__ ((packed));
  unsigned int sign:1 __attribute__ ((packed));
} bits;

will result in sizeof (bits) != 8

For some reason, this bit-field style declaration is used only for
FLOAT_BIT_ORDER_MISMATCH, which generally seems to be set for little
endian targets.  In other cases (i.e. big endian) open coded bit field
extraction and packing is used on the base integer type, like

 fraction = src->value_raw & fractype)1) << FRACBITS) - 1);
 exp = ((int)(src->value_raw >> FRACBITS)) & ((1 << EXPBITS) - 1);
 sign = ((int)(src->value_raw >> (FRACBITS + EXPBITS))) & 1;

This works of course regardless of the bit-field packing layout of the
target.

Joseph suggested to pack the struct bit, which would fix the issue.  
https://gcc.gnu.org/ml/gcc-bugs/2017-08/msg01651.html

However, I would like to propose to remove the special case of
FLOAT_BIT_ORDER_MISMATCH altogether as in the attached patch.

Any comments?

Cheers,
Oleg



libgcc/ChangeLog

PR libgcc/77804
* fp-bit.h: Remove FLOAT_BIT_ORDER_MISMATCH.
* fp-bit.c (pack_d, unpack_d): Remove special cases for 
FLOAT_BIT_ORDER_MISMATCH.
* config/arc/t-arc: Remove FLOAT_BIT_ORDER_MISMATCH.
Index: libgcc/config/arc/t-arc
===
--- libgcc/config/arc/t-arc	(revision 251045)
+++ libgcc/config/arc/t-arc	(working copy)
@@ -46,7 +46,6 @@
 
 dp-bit.c: $(srcdir)/fp-bit.c
 	echo '#ifndef __big_endian__' > dp-bit.c
-	echo '#define FLOAT_BIT_ORDER_MISMATCH' >> dp-bit.c
 	echo '#endif' >> dp-bit.c
 	echo '#include "fp-bit.h"' >> dp-bit.c
 	echo '#include "config/arc/dp-hack.h"' >> dp-bit.c
@@ -55,7 +54,6 @@
 fp-bit.c: $(srcdir)/fp-bit.c
 	echo '#define FLOAT' > fp-bit.c
 	echo '#ifndef __big_endian__' >> fp-bit.c
-	echo '#define FLOAT_BIT_ORDER_MISMATCH' >> fp-bit.c
 	echo '#endif' >> fp-bit.c
 	echo '#include "config/arc/fp-hack.h"' >> fp-bit.c
 	cat $(srcdir)/fp-bit.c >> fp-bit.c
Index: libgcc/fp-bit.c
===
--- libgcc/fp-bit.c	(revision 251045)
+++ libgcc/fp-bit.c	(working copy)
@@ -316,12 +316,7 @@
   /* We previously used bitfields to store the number, but this doesn't
  handle little/big endian systems conveniently, so use shifts and
  masks */
-#ifdef FLOAT_BIT_ORDER_MISMATCH
-  dst.bits.fraction = fraction;
-  dst.bits.exp = exp;
-  dst.bits.sign = sign;
-#else
-# if defined TFLOAT && defined HALFFRACBITS
+#if defined TFLOAT && defined HALFFRACBITS
  {
halffractype high, low, unity;
int lowsign, lowexp;
@@ -394,11 +389,10 @@
  }
dst.value_raw = ((fractype) high << HALFSHIFT) | low;
  }
-# else
+#else
   dst.value_raw = fraction & fractype)1) << FRACBITS) - (fractype)1);
   dst.value_raw |= ((fractype) (exp & ((1 << EXPBITS) - 1))) << FRACBITS;
   dst.value_raw |= ((fractype) (sign & 1)) << (FRACBITS | EXPBITS);
-# endif
 #endif
 
 #if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
@@ -450,12 +444,7 @@
   src = 
 #endif
   
-#ifdef FLOAT_BIT_ORDER_MISMATCH
-  fraction = src->bits.fraction;
-  exp = src->bits.exp;
-  sign = src->bits.sign;
-#else
-# if defined TFLOAT && defined HALFFRACBITS
+#if defined TFLOAT && defined HALFFRACBITS
  {
halffractype high, low;

@@ -498,11 +487,10 @@
 	 }
  }
  }
-# else
+#else
   fraction = src->value_raw & fractype)1) << FRACBITS) - 1);
   exp = ((int)(src->value_raw >> FRACBITS)) & ((1 << EXPBITS) - 1);
   sign = ((int)(src->value_raw >> (FRACBITS + EXPBITS))) & 1;
-# endif
 #endif
 
   dst->sign = sign;
Index: libgcc/fp-bit.h
===
--- libgcc/fp-bit.h	(revision 251045)
+++ libgcc/fp-bit.h	(working copy)
@@ -128,10 +128,6 @@
 #define NO_DI_MODE
 #endif
 
-#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
-#define FLOAT_BIT_ORDER_MISMATCH
-#endif
-
 #if __BYTE_ORDER__ != __FLOAT_WORD_ORDER__
 #define FLOAT_WORD_ORDER_MISMATCH
 #endif
@@ -354,16 +350,6 @@
 # endif
 #endif
 
-#ifdef FLOAT_BIT_ORDER_MISMATCH
-  struct
-{
-  fractype fraction:FRACBITS __attribute__ ((packed));
-  unsigned int exp:EXPBITS __attribute__ ((packed));
-  unsigned int sign:1 __attribute__ ((packed));
-}
-  bits;
-#endif
-
 #ifdef _DEBUG_BITFLOAT
   struct
 {


Re: [PATCH] PR fortran/91802 -- rank+corank must be less than 16

2019-09-28 Thread Steve Kargl
On Sat, Sep 28, 2019 at 03:06:13PM -0700, Steve Kargl wrote:
> On Sat, Sep 28, 2019 at 01:13:42PM -0700, Jerry DeLisle wrote:
> > On 9/28/19 10:11 AM, Steve Kargl wrote:
> > > Committed as r276254.
> > > 
> > 
> > I am getting this:
> > 
> > gfc -c -fcoarray=single pr91802.f90
> > f951: internal compiler error: free_expr0(): Bad expr type
> > 0x809fc9 gfc_report_diagnostic
> > ../../trunk/gcc/fortran/error.c:776
> > 0x80b62a gfc_internal_error(char const*, ...)
> > ...
> > 
> > I will do a rebuild and rerun in case I missed something.
> > 
> 
> Bummer.  May be due to difference with --enable-checking.
> 

Just bootstrapped trunk in an empty directory.  No issue.

If it persists for you, you can chnage the 'goto cleanup'
in the original patch to 'return m'.  gfortran is exiting,
so leaking memory isn't a concern.

-- 
Steve


Re: [PATCH] PR fortran/91802 -- rank+corank must be less than 16

2019-09-28 Thread Steve Kargl
On Sat, Sep 28, 2019 at 01:13:42PM -0700, Jerry DeLisle wrote:
> On 9/28/19 10:11 AM, Steve Kargl wrote:
> > Committed as r276254.
> > 
> 
> I am getting this:
> 
> gfc -c -fcoarray=single pr91802.f90
> f951: internal compiler error: free_expr0(): Bad expr type
> 0x809fc9 gfc_report_diagnostic
>   ../../trunk/gcc/fortran/error.c:776
> 0x80b62a gfc_internal_error(char const*, ...)
> ...
> 
> I will do a rebuild and rerun in case I missed something.
> 

Bummer.  May be due to difference with --enable-checking.

-- 
Steve


[PATCH] Fix algo constexpr tests in Debug mode

2019-09-28 Thread François Dumont

Here is what I just commited.

I try to use the asm trick in the _GLIBCXX_DEBUG_VERIFY_COND_AT but 
didn't notice any enhancement. So for now I kept my solution to just 
have a non-constexpr call compiler error.


I fix my patch to use __builtin_is_constant_evaluated rather than 
std::is_constant_evaluated in __valid_range.


    * include/bits/stl_algobase.h (__memmove): Return _Tp*.
    (__memmove): Loop as long as __n is not 0.
    (__copy_move<>::__copy_m): Likewise.
    (__copy_move_backward<>::__copy_move_b): Likewise.
    * testsuite/25_algorithms/copy/constexpr.cc: Add check on copied 
values.

    * testsuite/25_algorithms/copy_backward/constexpr.cc: Likewise.
    * testsuite/25_algorithms/copy/constexpr_neg.cc: New.
    * testsuite/25_algorithms/copy_backward/constexpr.cc: New.

    * include/debug/forward_list
(_Sequence_traits<__debug::forward_list<>>::_S_size): Returns __dp_sign
    distance when not empty.
    * include/debug/list
    (_Sequence_traits<__debug::list<>>::_S_size): Likewise.
    * include/debug/helper_functions.h (__dp_sign_max_size): New
    _Distance_precision enum entry.
    * include/debug/safe_iterator.h
    (__copy_move_a(_II, _II, const _Safe_iterator<>&)): Check for output
    iterator _M_can_advance as soon as input range distance precision is
    strictly higher than __dp_size.
    (__copy_move_a(const _Safe_iterator<>&, const _Safe_iterator<>&,
    const _Safe_iterator<>&)): Likewise.
    (__copy_move_backward_a(_II, _II, const _Safe_iterator<>&)): Likewise.
    (__copy_move_backward_a(const _Safe_iterator<>&,
    const _Safe_iterator<>&, const _Safe_iterator<>&)): Likewise.
    (__equal_aux(_II, _II, const _Safe_iterator<>&)): Likewise.
    (__equal_aux(const _Safe_iterator<>&,
    const _Safe_iterator<>&, const _Safe_iterator<>&)): Likewise.

François

On 9/27/19 6:45 PM, Jonathan Wakely wrote:

On 27/09/19 18:24 +0200, François Dumont wrote:

On 9/27/19 2:11 PM, Jonathan Wakely wrote:

On 19/09/19 22:27 +0200, François Dumont wrote:

Hi

    I start working on making recently added constexpr tests to 
work in Debug mode.


The attached patch seems to be necessary for that, right?



On my side I had done this, almost the same.

For the moment there is a FIXME in macros.h to find out how to 
generate a nice compilation error when the condition is not meant.


static_assert can't be called in this context, too bad.

I also try to define a function with a 
__attribute__((__error__("because"))) attribute. But when I make it 
constexpr gcc complains about missing definition. When I provide a 
definition gcc complains that this attribute must be on a 
declaration. And when I split declaration and definition gcc does not 
produce the expected compilation error.


Yes, I've tried similar things without success.

Unless you have the solution I consider that we need help from the 
front-end.


For the moment if Debug mode finds a problem it will be reported as 
_M_error function not being constexpr !


A reasonable workaround is to do:

#ifdef _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED
 if (__builtin_is_constant_evaluated())
   asm("Debug Mode assertion failed");
 else
#endif
 if (!(Cond))
   __gnu_debug::_Error_formatter::...

The builtin is available even for C++98, whereas
std::is_constant_evaluated() is only available for C++20.

This produces errors that include lines like:

asm.cc:12:17:   in ‘constexpr’ expansion of ‘f(-1)’
asm.cc:4:7: error: inline assembly is not a constant expression
   4 |   asm("debug mode assertion failed");
 |   ^~~
asm.cc:8:3: note: in expansion of macro ‘CHECK’
   8 |   _GLIBCXX_ASSERT(i > 0);
 |   ^
asm.cc:4:7: note: only unevaluated inline assembly is allowed in a 
‘constexpr’ function in C++2a

   4 |   asm("debug mode assertion failed");
 |   ^~~
asm.cc:8:3: note: in expansion of macro ‘CHECK’
   8 |   CHECK(i > 0);
 |   ^

It's not ideal, but it does show the failed condition and the text
"debug mode assertion failed" (or whatever message you choose to use
there).





diff --git a/libstdc++-v3/include/bits/stl_algo.h b/libstdc++-v3/include/bits/stl_algo.h
index a672f8b2b39..f25b8b76df6 100644
--- a/libstdc++-v3/include/bits/stl_algo.h
+++ b/libstdc++-v3/include/bits/stl_algo.h
@@ -5054,8 +5054,8 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
*  @param  __last1   Another iterator.
*  @param  __last2   Another iterator.
*  @param  __result  An iterator pointing to the end of the merged range.
-   *  @return An iterator pointing to the first element not less
-   *  than @e val.
+   *  @return   An output iterator equal to @p __result + (__last1 - __first1)
+   *+ (__last2 - __first2).
*
*  Merges the ranges @p [__first1,__last1) and @p [__first2,__last2) into
*  the sorted range @p [__result, __result + (__last1-__first1) +
@@ -5102,8 +5102,8 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
*  @param  __last2   Another iterator.
*  @param  __result  An 

Re: [PATCH] Automatics in equivalence statements

2019-09-28 Thread Andreas Schwab
On Aug 14 2019, Mark Eggleston  wrote:

>     * gfortran.dg/auto_in_equiv_3.f90: New test.

This test fails everywhere.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."


Re: [patch, libgfortran] Bug 91593 - Implicit enum conversions in libgfortran/io/transfer.c

2019-09-28 Thread Janne Blomqvist
On Fri, Sep 27, 2019 at 8:14 PM Jerry DeLisle  wrote:
>
> On 9/23/19 8:12 PM, Jerry DeLisle wrote:
> > On 9/23/19 8:52 AM, Bernhard Reutner-Fischer wrote:
> >> On 22 September 2019 22:51:46 CEST, Jerry DeLisle  
> >> wrote:
> >>> Hi all,
> >>>
> >>> The attached patch eliminates several warnings by adjusting which
> >>> enumerator is
> >>> used in the subject offending code. I fixed this by adding an
> >>> enumerator at the
> >>> end of the file_mode definition.  This then triggered a warning in
> >>> several other
> >>> places for an unhandled case in the switch statements. I cleared those
> >>> by
> >>> throwing in an assert (false) since it cant happen unless something
> >>> really goes
> >>> wrong somehow.
> >>>
> >> I'm curious why you assert (false) instead of the usual gcc_unreachable ()?
> >>
> >> Thanks,
> >>
> >
> > Because I forgot all about gcc_unreachable.  I will give it a try.
> >
> > Jerry
>
> gcc_unreachable is only defined in the gfortran frontend and not the runtime.
> Therefore, I added a define to io.h which invokes __builtin_unreachable and 
> does
> not use fancy_abort. I don't think we need anything fancy.
>
> If no objections, I will commit the attached updated patch with a new 
> ChangeLog.

Just a minor nit, why bother with the #define, why not just use
__builtin_unreachable directly?

(I think for the frontend there's the argument that it might be
compiled with a non-GCC compiler which might not support
__builtin_unreachable. But libgfortran is always compiled with the
corresponding gcc frontend, so this doesn't apply there.)

-- 
Janne Blomqvist


Re: [PATCH] PR fortran/91802 -- rank+corank must be less than 16

2019-09-28 Thread Jerry DeLisle

On 9/28/19 10:11 AM, Steve Kargl wrote:

Committed as r276254.



I am getting this:

gfc -c -fcoarray=single pr91802.f90
f951: internal compiler error: free_expr0(): Bad expr type
0x809fc9 gfc_report_diagnostic
../../trunk/gcc/fortran/error.c:776
0x80b62a gfc_internal_error(char const*, ...)
...

I will do a rebuild and rerun in case I missed something.

This is on x86_64-pc-linux-gnu.

Jerry


[Darwin, PPC, Mode Iterators 4/n, committed] Update macho_high.

2019-09-28 Thread Iain Sandoe
(since Segher asked,  ’n’ is approximately 8 - some of the patterns will be
 harder to convert)

Drop the expander for macho_high and use a mode iterator on the define_insn
for @macho_high_ instead.

as usual, tested on powerpc-darwin9 and powerpc64-linux-gnu
applied to mainline
thanks
Iain

gcc/ChangeLog:

2019-09-28  Iain Sandoe  

* config/darwin.c (gen_macho_high): Amend to include the mode
argument.
(machopic_indirect_data_reference): Amend gen_macho_high call
to include mode argument.
(machopic_legitimize_pic_address): Likewise.
* config/rs6000/rs6000.c (rs6000_legitimize_address):
* config/rs6000/darwin.md (@macho_high_): New, replaces
the macho_high expander and two define_insn entries.

diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c
index 3e4bbffc92..1f72c07ab7 100644
--- a/gcc/config/darwin.c
+++ b/gcc/config/darwin.c
@@ -47,6 +47,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "toplev.h"
 #include "lto-section-names.h"
 #include "intl.h"
+#include "optabs.h"
 
 /* Darwin supports a feature called fix-and-continue, which is used
for rapid turn around debugging.  When code is compiled with the
@@ -108,7 +109,7 @@ section * darwin_sections[NUM_DARWIN_SECTIONS];
 
 /* While we transition to using in-tests instead of ifdef'd code.  */
 #if !HAVE_lo_sum
-#define gen_macho_high(a,b) (a)
+#define gen_macho_high(m,a,b) (a)
 #define gen_macho_low(a,b,c) (a)
 #endif
 
@@ -654,7 +655,7 @@ machopic_indirect_data_reference (rtx orig, rtx reg)
{
  /* Create a new register for CSE opportunities.  */
  rtx hi_reg = (!can_create_pseudo_p () ? reg : gen_reg_rtx (Pmode));
- emit_insn (gen_macho_high (hi_reg, orig));
+ emit_insn (gen_macho_high (Pmode, hi_reg, orig));
  emit_insn (gen_macho_low (reg, hi_reg, orig));
  return reg;
}
@@ -858,7 +859,7 @@ machopic_legitimize_pic_address (rtx orig, machine_mode 
mode, rtx reg)
  rtx asym = XEXP (orig, 0);
  rtx mem;
 
- emit_insn (gen_macho_high (temp_reg, asym));
+ emit_insn (gen_macho_high (Pmode, temp_reg, asym));
  mem = gen_const_mem (GET_MODE (orig),
   gen_rtx_LO_SUM (Pmode, temp_reg,
   copy_rtx (asym)));
diff --git a/gcc/config/rs6000/darwin.md b/gcc/config/rs6000/darwin.md
index b2a52d81b3..0c63a31755 100644
--- a/gcc/config/rs6000/darwin.md
+++ b/gcc/config/rs6000/darwin.md
@@ -150,31 +150,12 @@ You should have received a copy of the GNU General Public 
License
stfd %0,lo16(%2)(%1)"
   [(set_attr "type" "store")])
 
-;; Mach-O PIC trickery.
-(define_expand "macho_high"
-  [(set (match_operand 0 "")
-   (high (match_operand 1 "")))]
-  "TARGET_MACHO"
-{
-  if (TARGET_64BIT)
-emit_insn (gen_macho_high_di (operands[0], operands[1]));
-  else
-emit_insn (gen_macho_high_si (operands[0], operands[1]));
+;; Mach-O PIC.
 
-  DONE;
-})
-
-(define_insn "macho_high_si"
-  [(set (match_operand:SI 0 "gpc_reg_operand" "=b*r")
-   (high:SI (match_operand 1 "" "")))]
-  "TARGET_MACHO && ! TARGET_64BIT"
-  "lis %0,ha16(%1)")
-  
-
-(define_insn "macho_high_di"
-  [(set (match_operand:DI 0 "gpc_reg_operand" "=b*r")
-   (high:DI (match_operand 1 "" "")))]
-  "TARGET_MACHO && TARGET_64BIT"
+(define_insn "@macho_high_"
+  [(set (match_operand:P 0 "gpc_reg_operand" "=b*r")
+   (high:P (match_operand 1 "" "")))]
+  "TARGET_MACHO && (DEFAULT_ABI == ABI_DARWIN)"
   "lis %0,ha16(%1)")
 
 (define_expand "macho_low"
diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index 81aec9c54a..f136dcbf8c 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -7978,7 +7978,7 @@ rs6000_legitimize_address (rtx x, rtx oldx 
ATTRIBUTE_UNUSED,
   if (TARGET_ELF)
emit_insn (gen_elf_high (reg, x));
   else
-   emit_insn (gen_macho_high (reg, x));
+   emit_insn (gen_macho_high (Pmode, reg, x));
   return gen_rtx_LO_SUM (Pmode, reg, x);
 }
   else if (TARGET_TOC
@@ -9691,7 +9691,7 @@ rs6000_emit_move (rtx dest, rtx source, machine_mode mode)
  return;
}
 #endif
- emit_insn (gen_macho_high (target, operands[1]));
+ emit_insn (gen_macho_high (Pmode, target, operands[1]));
  emit_insn (gen_macho_low (operands[0], target, operands[1]));
  return;
}



[PATCH] PR fortran/91714 -- Mangled type-spec

2019-09-28 Thread Steve Kargl
The attached patch issues errors for a few mangled type-specs.
It has been regression tested on x86_64-*-freebsd.  OK to commit?

2019-09-28  Steven G. Kargl  

PR fortran/91714
* decl.c (gfc_match_decl_type_spec):  Issue errors for a few
mangled types.

2019-09-28  Steven G. Kargl  

PR fortran/91714
* gfortran.dg/dec_type_print_3.f90: Update dg-error regex.
* gfortran.dg/pr91714.f90: New test.

A daunting task awaits a brave soul as gfc_match_decl_type_spec
is a minefield for bugs.  This is dues to the fact the the functions
has grown by adding kludge upon kludge upon kludge.  The first
thing to fix is the broken parsing that follows from the
matching of 'type('.

-- 
Steve
Index: gcc/fortran/decl.c
===
--- gcc/fortran/decl.c	(revision 276254)
+++ gcc/fortran/decl.c	(working copy)
@@ -,6 +,7 @@ get_kind:
 	  gfc_next_ascii_char ();
 	  return MATCH_YES;
 	}
+	  gfc_error ("Malformed type-spec at %C");
 	  return MATCH_NO;
 	}
 }
@@ -4457,7 +4458,10 @@ get_kind:
 }
 
   if (matched_type && gfc_match_char (')') != MATCH_YES)
-return MATCH_ERROR;
+{
+  gfc_error ("Malformed type-spec at %C");
+  return MATCH_ERROR;
+}
 
   /* Defer association of the KIND expression of function results
  until after USE and IMPORT statements.  */
@@ -10240,6 +10244,20 @@ gfc_match_derived_decl (void)
   return MATCH_ERROR;
 }
 
+  /*  In free source form, need to check for TYPE XXX as oppose to TYPEXXX.
+  But, we need to simply return for TYPE(.  */ 
+  if (m == MATCH_NO && gfc_current_form == FORM_FREE)
+{
+  char c = gfc_peek_ascii_char ();
+  if (c == '(')
+	return m;
+  if (!gfc_is_whitespace (c))
+	{
+	  gfc_error ("Mangled derived type definition at %C");
+	  return MATCH_NO;
+	}
+}
+
   m = gfc_match (" %n ", name);
   if (m != MATCH_YES)
 return m;
@@ -10247,7 +10265,7 @@ gfc_match_derived_decl (void)
   /* Make sure that we don't identify TYPE IS (...) as a parameterized
  derived type named 'is'.
  TODO Expand the check, when 'name' = "is" by matching " (tname) "
- and checking if this is a(n intrinsic) typename. his picks up
+ and checking if this is a(n intrinsic) typename.  This picks up
  misplaced TYPE IS statements such as in select_type_1.f03.  */
   if (gfc_peek_ascii_char () == '(')
 {
Index: gcc/testsuite/gfortran.dg/dec_type_print_3.f90
===
--- gcc/testsuite/gfortran.dg/dec_type_print_3.f90	(revision 276253)
+++ gcc/testsuite/gfortran.dg/dec_type_print_3.f90	(working copy)
@@ -8,9 +8,9 @@
 
 include 'dec_type_print.f90'
 
-! { dg-error "Invalid character in name" "" { target *-*-* } 52 }
+! { dg-error "Mangled derived type definition" "" { target *-*-* } 52 }
 ! { dg-error "Invalid character in name" "" { target *-*-* } 53 }
-! { dg-error "Invalid character in name" "" { target *-*-* } 54 }
+! { dg-error "Mangled derived type definition" "" { target *-*-* } 54 }
 ! { dg-error "Invalid character in name" "" { target *-*-* } 55 }
 ! { dg-error "Invalid character in name" "" { target *-*-* } 56 }
 ! { dg-error "Invalid character in name" "" { target *-*-* } 57 }
Index: gcc/testsuite/gfortran.dg/pr91714.f90
===
--- gcc/testsuite/gfortran.dg/pr91714.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/pr91714.f90	(working copy)
@@ -0,0 +1,10 @@
+! { dg-do compile }
+! Contributed by Gerhard Steinmetz
+program p
+   typea  ! { dg-error "Mangled derived type" }
+  integer b
+   end type   ! { dg-error "Expecting END PROGRAM" }
+   type(a) :: c   ! { dg-error "is being used before it" }
+   c = a(1)
+   print *, c
+end


Re: [PATCH] PR fortran/91802 -- rank+corank must be less than 16

2019-09-28 Thread Steve Kargl
Committed as r276254.

-- 
steve

On Tue, Sep 24, 2019 at 03:49:06PM -0700, Steve Kargl wrote:
> The attached patch has been tested on x86_64-*-freebsd.  OK to commit?
> 
> 2019-09-24  Steven G. Kargl  
> 
>   PR fortran/91802
>   * decl.c (attr_decl1): Check if rank+corank > 15.
> 
> 2019-09-24  Steven G. Kargl  
> 
>   PR fortran/91802
>   * gfortran.dg/pr91802.f90: New test.
> -- 
> Steve

> Index: gcc/fortran/decl.c
> ===
> --- gcc/fortran/decl.c(revision 275969)
> +++ gcc/fortran/decl.c(working copy)
> @@ -8468,6 +8468,15 @@ attr_decl1 (void)
>goto cleanup;
>  }
>  
> +  /* Check F2018:C822.  */
> +  if (sym->attr.dimension && sym->attr.codimension
> +  && sym->as && sym->as->rank + sym->as->corank > 15)
> +{
> +  gfc_error ("rank + corank of %qs exceeds 15 at %C", sym->name);
> +  m = MATCH_ERROR;
> +  goto cleanup;
> +}
> +
>if (sym->attr.cray_pointee && sym->as != NULL)
>  {
>/* Fix the array spec.  */
> Index: gcc/testsuite/gfortran.dg/pr91802.f90
> ===
> --- gcc/testsuite/gfortran.dg/pr91802.f90 (nonexistent)
> +++ gcc/testsuite/gfortran.dg/pr91802.f90 (working copy)
> @@ -0,0 +1,9 @@
> +! { dg-do compile }
> +! { dg-options "-fcoarray=single" }
> +! Code contributed by Gerhard Steinmetz
> +! PR fortran/91802
> +module m
> +   real :: x
> +   dimension ::   x(1,2,1,2,1,2,1,2)
> +   codimension :: x[1,2,1,2,1,2,1,*] ! { dg-error "exceeds 15" }
> +end


-- 
Steve
20170425 https://www.youtube.com/watch?v=VWUpyCsUKR4
20161221 https://www.youtube.com/watch?v=IbCHE-hONow


Re: [Patch, fortran] PR91726 - [7/8/9/10 Regression] ICE in gfc_conv_array_ref, at fortran/trans-array.c:3612

2019-09-28 Thread Steve Kargl
On Sun, Sep 22, 2019 at 04:28:49PM +0100, Paul Richard Thomas wrote:
> Fixing the original problem in the module took a few minutes. Making
> the module do something useful took rather longer! The testcase in the
> patch compiles with 6-branch but segfaults in runtime.
> 
> Bootstrapped and regtested on FC30/x86_64 - OK to commit and go
> steadily back through the branches over some weeks?
> 
> Regards
> 
> Paul
> 
> 2019-09-22  Paul Thomas  
> 
> PR fortran/91726
> * resolve.c (gfc_expr_to_initialize): Bail out with a copy of
> the original expression if the array ref is a scalar and the
> array_spec has corank.
> * trans-array.c (gfc_conv_array_ref): Such expressions are OK
> even if the array ref codimen is zero.
> * trans-expr.c (gfc_get_class_from_expr): New function taken
> from gfc_get_vptr_from_expr.
> (gfc_get_vptr_from_expr): Call new function.
> * trans-stmt.c (trans_associate_var): If one of these is a
> target expression, extract the class expression from the target
> and copy its fields to a new target variable.
> * trans.h : Add prototype for gfc_get_class_from_expr.
> 
> 2019-09-22  Paul Thomas  
> 
> PR fortran/91726
> * gfortran.dg/coarray_poly_9.f90 : New test.

Looks good to me.

-- 
Steve


Re: [patch, fortran] PR 84487

2019-09-28 Thread Steve Kargl
On Wed, Sep 25, 2019 at 10:24:51PM +0200, Thomas Koenig wrote:
> 
> this patch makes sure that the __def_init variables, which have been
> generated for normal allocatable arrays for quite some time, do not fill
> up huge amounts of space in the object files with zeros. This is done by
> not marking them read-only, which means that they are put into the BSS.
> 
> Setting DECL_ARTIFICIAL on the __def_init variable makes sure it
> is handled as predetermined shared in gfc_omp_predetermined_sharing .
> 
> This is not an optimum solution. As the xfail shows, we are now missing
> out on an optimization (as seen by the xfail that is now needed), and
> having large all-zero variables seems wrong. However, this patch solves
> the most urgent problem in this respect.
> 
> This is an 8/9/10 regression, so I would like to commit this to
> all of these branches (waiting before gcc 9 reopens, of course).
> 
> I wold then close the PR and open an enchancement PR for the xfail
> and the design improvement.
> 
> Test case... I'm not sure what to test for.
> 
> Regression-tested. OK for all affected branches?
> 

Your approach seems reasonable to me.  You may want to
ping Jakub or Tobias as this affects openmp.

-- 
Steve


Re: [PATCH, Fortran] Optionally suppress no-automatic overwrites recursive warning - for approval

2019-09-28 Thread Steve Kargl
On Thu, Sep 26, 2019 at 09:45:28AM +0100, Mark Eggleston wrote:
> Original thread starts here 
> https://gcc.gnu.org/ml/gcc-patches/2019-09/msg01185.html
> 
> OK to commit?
> 

I'm not a big fan of option proliferation.  If you don't 
want to see warns just use -w.  Of course, this is just
MHO.

-- 
Steve


[PATCH v2 1/2] libada: Remove racy duplicate gnatlib installation

2019-09-28 Thread Maciej W. Rozycki
For some reason, presumably historical, the `install-gnatlib' target for 
the default multilib is invoked twice, once via the `ada.install-common' 
target in `gcc/ada/gcc-interface/Make-lang.in' invoked from gcc/ and 
again via the `install-libada' target in libada/.

Apart from doing the same twice this is actually harmful in sufficiently 
parallelized `make' invocation, as the removal of old files performed 
within the `install-gnatlib' recipe in the former case actually races 
with the installation of new files done in the latter case, causing the 
recipe to fail and abort, however non-fatally, having not completed the 
installation of all the built files needed for the newly-built compiler 
to work correctly.

This can be observed with a native `x86_64-linux-gnu' bootstrap:

make[4]: Entering directory '.../gcc/ada'
rm -rf .../lib/gcc/x86_64-linux-gnu/10.0.0/adalib
rm: cannot remove '.../lib/gcc/x86_64-linux-gnu/10.0.0/adalib': Directory not
empty
make[4]: *** [gcc-interface/Makefile:512: install-gnatlib] Error 1
make[4]: Leaving directory '.../gcc/ada'
make[3]: *** [.../gcc/ada/gcc-interface/Make-lang.in:853: install-gnatlib] Error
2
make[2]: [.../gcc/ada/gcc-interface/Make-lang.in:829: ada.install-common] Error
2 (ignored)

which then causes missing files to be reported when an attempt is made 
to use the newly-installed non-functional compiler to build a 
`riscv64-linux-gnu' cross-compiler:

(cd ada/bldtools/sinfo; gnatmake -q xsinfo ; ./xsinfo sinfo.h )
error: "ada.ali" not found, "ada.ads" must be compiled
error: "s-memory.ali" not found, "s-memory.adb" must be compiled
gnatmake: *** bind failed.
/bin/sh: ./xsinfo: No such file or directory
make[2]: *** [.../gcc/ada/Make-generated.in:45: ada/sinfo.h] Error 127
make[2]: Leaving directory '.../gcc'
make[1]: *** [Makefile:4369: all-gcc] Error 2
make[1]: Leaving directory '...'
make: *** [Makefile:965: all] Error 2

Depending on timing `.../lib/gcc/x86_64-linux-gnu/10.0.0/adainclude' may
cause an installation failure instead and the resulting compiler may be 
non-functional in a different way.

Only invoke `install-gnatlib' from within gcc/ then if a legacy build 
process is being used with libada disabled and gnatlib built manually 
with `make -C gcc gnatlib'.

gcc/
* Makefile.in (gnat_install_lib): New variable.
* configure.ac: Substitute it.
* configure: Regenerate.

gcc/ada/
* gcc-interface/Make-lang.in (ada.install-common): Split into...
(gnat-install-tools, gnat-install-lib): ... these.
---
On Fri, 27 Sep 2019, Arnaud Charlet wrote:

> >  Hmm, I've experimented a bit and AFAICT if `--disable-libada' is given 
> > without my proposed change applied, then the gnatlib stuff doesn't get 
> > built in the first place let alone installed anyway.
> 
> With --disable-libada you need to build gnatlib and gnattools explicitly via
> e.g.
> 
> make -C gcc gnatlib gnattools
> 
> (after having done a "make" or "make bootstrap")
> 
> and then you can use "make install"

 Ack.  This seems to be of a very limited use, e.g. it does not support 
building shared libraries or multilibs, and it breaks in my build of a 
`riscv64-linux-gnu' cross-compiler because the `make -C gcc' invocation 
does not pass the `--sysroot=' option set in SYSROOT_CFLAGS_FOR_TARGET and 
consequently the newly-built compiler cannot find system headers needed to 
build gnatlib (also there is a missing ordering dependency beetween the 
`gnatlib' and `gnattools' targets, making the simultaneous invocation as 
given break in parallel `make', with a `You must first build the GNAT 
library: make gnatlib' message).

 I see no particular reason to break what has been working however, so 
here's my proposed rewritten change.  With so many limitations and its 
mismatch with the current GCC build arrangement and practices I'd consider 
your manual build recipe a legacy one though and would rather not invest 
too much effort into supporting it.  Insted I'd recommend everyone to 
switch to building via gnattools/ and libada/ top-level directories.

 NB one can alternatively use `make -C gcc install-gnatlib' to complement 
the manual build process.

 I have verified this change by running my combined build process where a 
native `x86_64-linux-gnu' configuration is built first and then used to 
build a `riscv64-linux-gnu' cross-compiler, both with `--disable-libada' 
specified, without and with this patch applied.  I have added `make -C gcc 
gnatlib && make -C gcc gnattools' as an extra build step before `make 
install'.

 This has run up to failing to find `riscv64-linux-gnu' system headers in 
`make -C gcc gnatlib' as noted above, at which point the installation 
trees had both the same contents, including `x86_64-linux-gnu' gnatlib 
development files and static libraries as well as gnattools in particular.

 I have also verified, with the same build process and the extra `make -C 
gcc' invocations removed, that the usual configuration with 

Re: [patch, libgfortran] Bug 91593 - Implicit enum conversions in libgfortran/io/transfer.c

2019-09-28 Thread Steve Kargl
On Fri, Sep 27, 2019 at 10:14:34AM -0700, Jerry DeLisle wrote:
> 
> If no objections, I will commit the attached updated patch
> with a new ChangeLog.

No objection.

-- 
Steve


Re: [PATCH] PR fortran/91864 -- inquiry parameter is a constant

2019-09-28 Thread Steve Kargl
Committed as r276253.

-- 
steve

On Tue, Sep 24, 2019 at 03:07:31PM -0700, Steve Kargl wrote:
> The attached patch has been tested on x86_64-*-freebsd.  OK to commit?
> 
> 2019-09-24  Steven G. Kargl  
> 
>   PR fortran/91864
>   * gcc/fortran/io.c (match_io_element): An inquiry parameter cannot be
>   read into.
>   * gcc/fortran/match.c (gfc_match_allocate): An inquiry parameter 
>   can be neither an allocate-object nor stat variable.
>   (gfc_match_deallocate): An inquiry parameter cannot be deallocated.
> 
> 2019-09-24  Steven G. Kargl  
> 
>   PR fortran/91864
>   * gcc/testsuite/gfortran.dg/pr91864.f90
> 
> -- 
> Steve

> Index: gcc/fortran/io.c
> ===
> --- gcc/fortran/io.c  (revision 276104)
> +++ gcc/fortran/io.c  (working copy)
> @@ -3657,8 +3657,18 @@ match_io_element (io_kind k, gfc_code **cpp)
>  {
>m = gfc_match_variable (, 0);
>if (m == MATCH_NO)
> - gfc_error ("Expected variable in READ statement at %C");
> + {
> +   gfc_error ("Expecting variable in READ statement at %C");
> +   m = MATCH_ERROR;
> + }
>  
> +  if (m == MATCH_YES && expr->expr_type == EXPR_CONSTANT)
> + {
> +   gfc_error ("Expecting variable or io-implied-do in READ statement "
> +"at %L", >where);
> +   m = MATCH_ERROR;
> + }
> +
>if (m == MATCH_YES
> && expr->expr_type == EXPR_VARIABLE
> && expr->symtree->n.sym->attr.external)
> @@ -3667,7 +3677,6 @@ match_io_element (io_kind k, gfc_code **cpp)
>>where);
> m = MATCH_ERROR;
>   }
> -
>  }
>else
>  {
> Index: gcc/fortran/match.c
> ===
> --- gcc/fortran/match.c   (revision 276104)
> +++ gcc/fortran/match.c   (working copy)
> @@ -4242,6 +4242,12 @@ gfc_match_allocate (void)
>if (m == MATCH_ERROR)
>   goto cleanup;
>  
> +  if (tail->expr->expr_type == EXPR_CONSTANT)
> + {
> +   gfc_error ("Unexpected constant at %C");
> +   goto cleanup;
> + }
> +
>if (gfc_check_do_variable (tail->expr->symtree))
>   goto cleanup;
>  
> @@ -4374,6 +4380,12 @@ alloc_opt_list:
> tmp = NULL;
> saw_stat = true;
>  
> +   if (stat->expr_type == EXPR_CONSTANT)
> + {
> +   gfc_error ("STAT tag at %L cannot be a constant", >where);
> +   goto cleanup;
> + }
> +
> if (gfc_check_do_variable (stat->symtree))
>   goto cleanup;
>  
> @@ -4649,6 +4661,12 @@ gfc_match_deallocate (void)
>   goto cleanup;
>if (m == MATCH_NO)
>   goto syntax;
> +
> +  if (tail->expr->expr_type == EXPR_CONSTANT)
> + {
> +   gfc_error ("Unexpected constant at %C");
> +   goto cleanup;
> + }
>  
>if (gfc_check_do_variable (tail->expr->symtree))
>   goto cleanup;
> Index: gcc/testsuite/gfortran.dg/pr91864.f90
> ===
> --- gcc/testsuite/gfortran.dg/pr91864.f90 (nonexistent)
> +++ gcc/testsuite/gfortran.dg/pr91864.f90 (working copy)
> @@ -0,0 +1,22 @@
> +program p
> +   integer :: i
> +   read (*,*) i%kind   ! { dg-error "Expecting variable or io-implied-do" }
> +end
> +
> +subroutine t
> +   integer, allocatable :: x(:)
> +   integer :: stat
> +   allocate (x(3), stat=stat%kind)   ! { dg-error "cannot be a constant" }
> +end
> +
> +subroutine u
> +   integer, allocatable :: x(:)
> +   integer :: stat
> +   allocate (x(3), stat%kind=stat)   ! { dg-error "Unexpected constant" }
> +end
> +
> +subroutine v
> +   integer, allocatable :: x(:)
> +   integer :: stat
> +   deallocate (x, stat%kind=stat)   ! { dg-error "Unexpected constant" }
> +end


-- 
Steve
20170425 https://www.youtube.com/watch?v=VWUpyCsUKR4
20161221 https://www.youtube.com/watch?v=IbCHE-hONow


Re: C++ PATCH for c++/91889 - follow-up fix for DR 2352

2019-09-28 Thread Jason Merrill
On Sat, Sep 28, 2019 at 7:33 AM Marek Polacek  wrote:
> On Fri, Sep 27, 2019 at 10:08:49PM -0400, Jason Merrill wrote:
> > On 9/26/19 9:45 PM, Marek Polacek wrote:
> > > Jason, you remarked that adding a ck_qual under the ck_ref_bind might be
> > > too much trouble, but it seems it's actually fairly simple.  The comments
> > > hopefully explain my thinking.  Is this what you had in mind?
> >
> > Yes, I'm glad to hear it was simpler than I worried it would be.
> >
> > > +   /* direct_reference_binding might have inserted a ck_qual under
> > > +  this ck_ref_bind for the benefit of conversion sequence ranking.
> > > +  Ignore the conversion; we'll create our own below.  */
> > > +   if (next_conversion (convs)->kind == ck_qual)
> > > + {
> > > +   gcc_assert (same_type_p (TREE_TYPE (expr),
> > > +next_conversion (convs)->type));
> > > +   STRIP_NOPS (expr);
> >
> > Why STRIP_NOPS?
>
> I needed to strip the cast the ck_qual had created so that the call to
> cp_build_addr_expr below won't fail with "lvalue required as the operand of 
> &".
> Perhaps a comment should explain it.

OK with the comment.

Jason


Re: C++ PATCH for c++/91889 - follow-up fix for DR 2352

2019-09-28 Thread Marek Polacek
On Fri, Sep 27, 2019 at 10:08:49PM -0400, Jason Merrill wrote:
> On 9/26/19 9:45 PM, Marek Polacek wrote:
> > Jason, you remarked that adding a ck_qual under the ck_ref_bind might be
> > too much trouble, but it seems it's actually fairly simple.  The comments
> > hopefully explain my thinking.  Is this what you had in mind?
> 
> Yes, I'm glad to hear it was simpler than I worried it would be.
> 
> > +   /* direct_reference_binding might have inserted a ck_qual under
> > +  this ck_ref_bind for the benefit of conversion sequence ranking.
> > +  Ignore the conversion; we'll create our own below.  */
> > +   if (next_conversion (convs)->kind == ck_qual)
> > + {
> > +   gcc_assert (same_type_p (TREE_TYPE (expr),
> > +next_conversion (convs)->type));
> > +   STRIP_NOPS (expr);
> 
> Why STRIP_NOPS?

I needed to strip the cast the ck_qual had created so that the call to
cp_build_addr_expr below won't fail with "lvalue required as the operand of &".
Perhaps a comment should explain it.

Marek


[ping][PR target/85401] initialize the move cost table before using it

2019-09-28 Thread coypu
re-posting, now CC'ing vmakarov who might be the right person to ping
about issues in this file.  apologies for the noise if I'm wrong.

--
This seems to be the way the rest of ira-color.c does it.
I hope it's OK. It does fix the segfault.

2019-09-10  Maya Rashish 

PR target/85401
* ira-color.c: (allocno_copy_cost_saving) Call
ira_init_register_move_cost_if_necessary

diff --git a/gcc/ira-color.c b/gcc/ira-color.c
index 99236994d64..5d721102e19 100644
--- a/gcc/ira-color.c
+++ b/gcc/ira-color.c
@@ -2828,6 +2828,7 @@ allocno_copy_cost_saving (ira_allocno_t allocno, int 
hard_regno)
}
   else
gcc_unreachable ();
+  ira_init_register_move_cost_if_necessary(allocno_mode);
   cost += cp->freq * ira_register_move_cost[allocno_mode][rclass][rclass];
 }
   return cost;




Re: [PATCH v2] libitm: sh: avoid absolute relocation in shared library (PR 86712)

2019-09-28 Thread Oleg Endo
On Sat, 2018-08-04 at 18:00 +0900, Oleg Endo wrote:
> On Fri, 2018-08-03 at 14:54 -0600, Jeff Law wrote:
> > On 07/28/2018 07:04 AM, slyfox.inbox.ru via gcc-patches wrote:
> > > 
> > > From: Sergei Trofimovich 
> > > 
> > > Cc: Andreas Schwab 
> > > Cc: Torvald Riegel 
> > > Cc: Alexandre Oliva 
> > > Cc: Oleg Endo 
> > > Cc: Kaz Kojima 
> > > Signed-off-by: Sergei Trofimovich 
> > > ---
> > >  libitm/config/sh/sjlj.S | 4 ++--
> > >  1 file changed, 2 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/libitm/config/sh/sjlj.S b/libitm/config/sh/sjlj.S
> > > index 043f36749be..f265ab8f898 100644
> > > --- a/libitm/config/sh/sjlj.S
> > > +++ b/libitm/config/sh/sjlj.S
> > > @@ -53,7 +53,7 @@ _ITM_beginTransaction:
> > >  #else
> > >   cfi_def_cfa_offset (4*10)
> > >  #endif
> > > -#if defined HAVE_ATTRIBUTE_VISIBILITY || !defined __PIC__
> > > +#if !defined __PIC__
> > >   mov.l   .Lbegin, r1
> > >   jsr @r1
> > >movr15, r5
> > > @@ -78,7 +78,7 @@ _ITM_beginTransaction:
> > >  
> > >   .align  2
> > >  .Lbegin:
> > > -#if defined HAVE_ATTRIBUTE_VISIBILITY || !defined __PIC__
> > > +#if !defined __PIC__
> > >   .long   GTM_begin_transaction
> > >  #else
> > >   .long   GTM_begin_transaction@PCREL-(.Lbegin0-.)
> > > 
> > 
> > THanks.  I installed this version.
> > 
> 
> Thanks Jeff.
> If there are no objections, I'll backport it to the 7 and 8 branches.
> 
> Cheers,
> Oleg


Finally  committed to GCC 8 as r276246 and to GCC 7 as r276247.

Cheers,
Oleg




[SH][committed] Fix PR 86805

2019-09-28 Thread Oleg Endo
Hi,

This also sets TARGET_HAVE_SPECULATION_SAFE_VALUE to
speculation_safe_value_not_needed for SH.

Tested with "make all-gcc".

Committed on trunk as r276244 and on GCC 9 as r276245.

Cheers,
Oleg

gcc/ChangeLog

PR target/86805
* config/sh/sh.c (TARGET_HAVE_SPECULATION_SAFE_VALUE): Define.
Index: gcc/config/sh/sh.c
===
--- gcc/config/sh/sh.c	(revision 276243)
+++ gcc/config/sh/sh.c	(working copy)
@@ -661,6 +661,9 @@
 #undef TARGET_CONSTANT_ALIGNMENT
 #define TARGET_CONSTANT_ALIGNMENT constant_alignment_word_strings
 
+#undef  TARGET_HAVE_SPECULATION_SAFE_VALUE
+#define TARGET_HAVE_SPECULATION_SAFE_VALUE speculation_safe_value_not_needed
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 
 


[PATCH 02/11] libstdc++ testsuite: Add timed_mutex::try_lock_until test

2019-09-28 Thread Mike Crowe
I was unable to find an existing tests for timed_mutex::try_lock_until and
recursive_timed_mutex::try_lock_until timing out. It would have been easier
to add a single templated test, but since these classes are tested in
separate directories I've created two separate tests.

* testsuite/30_threads/timed_mutex/try_lock_until/3.cc: New
file. Ensure that timed_mutex::try_lock_until actually times out
after the specified time when using both system_clock and
steady_clock.

* testsuite/30_threads/recursive_timed_mutex/try_lock_until/3.cc:
  Likewise but for recursive_timed_mutex.
---
 libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/try_lock_until/3.cc | 
74 -
 libstdc++-v3/testsuite/30_threads/timed_mutex/try_lock_until/3.cc   | 
74 -
 2 files changed, 148 insertions(+)
 create mode 100644 
libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/try_lock_until/3.cc
 create mode 100644 
libstdc++-v3/testsuite/30_threads/timed_mutex/try_lock_until/3.cc

diff --git 
a/libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/try_lock_until/3.cc 
b/libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/try_lock_until/3.cc
new file mode 100644
index 000..4f0b0b5
--- /dev/null
+++ 
b/libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/try_lock_until/3.cc
@@ -0,0 +1,74 @@
+// { dg-do run }
+// { dg-options "-pthread"  }
+// { dg-require-effective-target c++14 }
+// { dg-require-effective-target pthread }
+// { dg-require-gthreads "" }
+
+// Copyright (C) 2013-2019 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// .
+
+
+#include 
+#include 
+#include 
+#include 
+
+template 
+void test()
+{
+  typedef std::recursive_timed_mutex mutex_type;
+
+  try
+{
+  mutex_type m;
+  m.lock();
+  bool b;
+
+  std::thread t([&] {
+try
+  {
+using namespace std::chrono;
+const auto timeout = 100ms;
+const auto start = clock_type::now();
+const auto b = m.try_lock_until(start + timeout);
+const auto t = clock_type::now() - start;
+VERIFY( !b );
+VERIFY( t >= timeout );
+  }
+catch (const std::system_error& e)
+  {
+VERIFY( false );
+  }
+   });
+  t.join();
+  m.unlock();
+}
+  catch (const std::system_error& e)
+{
+  VERIFY( false );
+}
+  catch (...)
+{
+  VERIFY( false );
+}
+}
+
+int main()
+{
+  test();
+  test();
+}
diff --git a/libstdc++-v3/testsuite/30_threads/timed_mutex/try_lock_until/3.cc 
b/libstdc++-v3/testsuite/30_threads/timed_mutex/try_lock_until/3.cc
new file mode 100644
index 000..69d1ea5
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/timed_mutex/try_lock_until/3.cc
@@ -0,0 +1,74 @@
+// { dg-do run }
+// { dg-options "-pthread"  }
+// { dg-require-effective-target c++14 }
+// { dg-require-effective-target pthread }
+// { dg-require-gthreads "" }
+
+// Copyright (C) 2013-2019 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// .
+
+
+#include 
+#include 
+#include 
+#include 
+
+template 
+void test()
+{
+  typedef std::timed_mutex mutex_type;
+
+  try
+{
+  mutex_type m;
+  m.lock();
+  bool b;
+
+  std::thread t([&] {
+try
+  {
+using namespace std::chrono;
+const auto timeout = 100ms;
+const auto start = clock_type::now();
+const auto b = 

[PATCH 10/11] libstdc++ timed_mutex: Ensure that try_lock_for waits for long enough

2019-09-28 Thread Mike Crowe
The user-defined clock used with shared_mutex::try_lock_for and
shared_mutex::try_lock_shared_for may have higher precision than
__clock_t. We may need to round the duration up to ensure that the timeout
is long enough. (See __timed_mutex_impl::_M_try_lock_for)

* include/std/shared_mutex: (try_lock_for) Round up wait duration
  if necessary. (try_lock_shared_for) Likewise.
---
 libstdc++-v3/include/std/shared_mutex | 14 ++
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/libstdc++-v3/include/std/shared_mutex 
b/libstdc++-v3/include/std/shared_mutex
index b637bdc..6e67324 100644
--- a/libstdc++-v3/include/std/shared_mutex
+++ b/libstdc++-v3/include/std/shared_mutex
@@ -471,9 +471,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 template
   bool
-  try_lock_for(const chrono::duration<_Rep, _Period>& __rel_time)
+  try_lock_for(const chrono::duration<_Rep, _Period>& __rtime)
   {
-   return try_lock_until(__clock_t::now() + __rel_time);
+auto __rt = chrono::duration_cast<__clock_t::duration>(__rtime);
+if (ratio_greater<__clock_t::period, _Period>())
+  ++__rt;
+   return try_lock_until(__clock_t::now() + __rt);
   }
 
 // Shared ownership
@@ -484,9 +487,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 template
   bool
-  try_lock_shared_for(const chrono::duration<_Rep, _Period>& __rel_time)
+  try_lock_shared_for(const chrono::duration<_Rep, _Period>& __rtime)
   {
-   return try_lock_shared_until(__clock_t::now() + __rel_time);
+auto __rt = chrono::duration_cast<__clock_t::duration>(__rtime);
+if (ratio_greater<__clock_t::period, _Period>())
+  ++__rt;
+   return try_lock_shared_until(__clock_t::now() + __rt);
   }
 
 #if _GLIBCXX_USE_PTHREAD_RWLOCK_T && _GTHREAD_USE_MUTEX_TIMEDLOCK
-- 
git-series 0.9.1


[PATCH 08/11] libstdc++ testsuite: Also test shared_timed_mutex with steady_clock

2019-09-28 Thread Mike Crowe
* testsuite/30_threads/shared_timed_mutex/try_lock/3.cc: Convert
  existing test to templated function so that it can be called with
  both system_clock and steady_clock.
---
 libstdc++-v3/testsuite/30_threads/shared_timed_mutex/try_lock/3.cc | 17 
-
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/libstdc++-v3/testsuite/30_threads/shared_timed_mutex/try_lock/3.cc 
b/libstdc++-v3/testsuite/30_threads/shared_timed_mutex/try_lock/3.cc
index fd21033..1cf191c 100644
--- a/libstdc++-v3/testsuite/30_threads/shared_timed_mutex/try_lock/3.cc
+++ b/libstdc++-v3/testsuite/30_threads/shared_timed_mutex/try_lock/3.cc
@@ -27,7 +27,8 @@
 #include 
 #include 
 
-int main()
+template 
+void test()
 {
   typedef std::shared_timed_mutex mutex_type;
 
@@ -42,15 +43,15 @@ int main()
   {
 using namespace std::chrono;
 auto timeout = 100ms;
-auto start = system_clock::now();
+auto start = clock_type::now();
 b = m.try_lock_for(timeout);
-auto t = system_clock::now() - start;
+auto t = clock_type::now() - start;
 VERIFY( !b );
 VERIFY( t >= timeout );
 
-start = system_clock::now();
+start = clock_type::now();
 b = m.try_lock_until(start + timeout);
-t = system_clock::now() - start;
+t = clock_type::now() - start;
 VERIFY( !b );
 VERIFY( t >= timeout );
   }
@@ -71,3 +72,9 @@ int main()
   VERIFY( false );
 }
 }
+
+int main()
+{
+  test();
+  test();
+}
-- 
git-series 0.9.1


[PATCH 06/11] libstdc++ testsuite: Move slow_clock to its own header

2019-09-28 Thread Mike Crowe
Move slow_clock test class into a header file so that it can be used by
other tests in the future.

* testsuite/util/slow_clock.h: New file. Move implementation of
slow_clock test class.

* testsuite/30_threads/condition_variable/members/2.cc: Include
slow_clock from header.
---
 libstdc++-v3/testsuite/30_threads/condition_variable/members/2.cc | 17 
+
 libstdc++-v3/testsuite/util/slow_clock.h  | 38 
++
 2 files changed, 39 insertions(+), 16 deletions(-)
 create mode 100644 libstdc++-v3/testsuite/util/slow_clock.h

diff --git a/libstdc++-v3/testsuite/30_threads/condition_variable/members/2.cc 
b/libstdc++-v3/testsuite/30_threads/condition_variable/members/2.cc
index cbac3fa..f821d3f 100644
--- a/libstdc++-v3/testsuite/30_threads/condition_variable/members/2.cc
+++ b/libstdc++-v3/testsuite/30_threads/condition_variable/members/2.cc
@@ -25,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 
 template 
 void test01()
@@ -52,22 +53,6 @@ void test01()
 }
 }
 
-struct slow_clock
-{
-  using rep = std::chrono::system_clock::rep;
-  using period = std::chrono::system_clock::period;
-  using duration = std::chrono::system_clock::duration;
-  using time_point = std::chrono::time_point;
-  static constexpr bool is_steady = false;
-
-  static time_point now()
-  {
-auto real = std::chrono::system_clock::now();
-return time_point{real.time_since_epoch() / 3};
-  }
-};
-
-
 void test01_alternate_clock()
 {
   try
diff --git a/libstdc++-v3/testsuite/util/slow_clock.h 
b/libstdc++-v3/testsuite/util/slow_clock.h
new file mode 100644
index 000..13fc94b
--- /dev/null
+++ b/libstdc++-v3/testsuite/util/slow_clock.h
@@ -0,0 +1,38 @@
+// -*- C++ -*-
+
+// Copyright (C) 2004-2019 Free Software Foundation, Inc.
+
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 3, or (at
+// your option) any later version.
+
+// This library is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING3.  If not see
+// .
+
+
+// A clock that ticks at a third of the speed of system_clock that can be used
+// to ensure that functions with timeouts don't erroneously return early.
+
+#include 
+
+struct slow_clock
+{
+  using rep = std::chrono::system_clock::rep;
+  using period = std::chrono::system_clock::period;
+  using duration = std::chrono::system_clock::duration;
+  using time_point = std::chrono::time_point;
+  static constexpr bool is_steady = false;
+
+  static time_point now()
+  {
+auto real = std::chrono::system_clock::now();
+return time_point{real.time_since_epoch() / 3};
+  }
+};
-- 
git-series 0.9.1


[PATCH 11/11] shared_mutex: Fix try_lock_until and try_lock_shared_until on arbitrary clock

2019-09-28 Thread Mike Crowe
This is the equivalent to PR libstdc++/91906, but for shared_mutex.

A non-standard clock may tick more slowly than std::chrono::steady_clock.
This means that we risk returning false early when the specified timeout
may not have expired. This can be avoided by looping until the timeout time
as reported by the non-standard clock has been reached.

Unfortunately, we have no way to tell whether the non-standard clock ticks
more quickly that std::chrono::steady_clock. If it does then we risk
returning later than would be expected, but that is unavoidable without
waking up periodically to check, which would be rather too expensive.

* include/std/shared_mutex (try_lock_until, try_lock_shared_until):
Loop until the absolute timeout time is reached as measured against
the appropriate clock.  *
testsuite/30_threads/shared_mutex/try_lock_until/1.cc: New
file. Test shared_mutex::try_lock_until and
shared_mutex::try_lock_shared_until timeouts against various
clocks.
---
 libstdc++-v3/include/std/shared_mutex  | 28 
++-
 libstdc++-v3/testsuite/30_threads/shared_mutex/try_lock_until/1.cc | 87 
-
 2 files changed, 109 insertions(+), 6 deletions(-)
 create mode 100644 
libstdc++-v3/testsuite/30_threads/shared_mutex/try_lock_until/1.cc

diff --git a/libstdc++-v3/include/std/shared_mutex 
b/libstdc++-v3/include/std/shared_mutex
index 6e67324..40d45a1 100644
--- a/libstdc++-v3/include/std/shared_mutex
+++ b/libstdc++-v3/include/std/shared_mutex
@@ -554,9 +554,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   bool
   try_lock_until(const chrono::time_point<_Clock, _Duration>& __atime)
   {
-typename _Clock::time_point __now = _Clock::now();
-auto __rtime = __atime - __now;
-return try_lock_for(__rtime);
+// The user-supplied clock may not tick at the same rate as
+// steady_clock, so we must loop in order to guarantee that
+// the timeout has expired before returning false.
+   typename _Clock::time_point __now = _Clock::now();
+while (__atime > __now) {
+  auto __rtime = __atime - __now;
+  if (try_lock_for(__rtime))
+return true;
+  __now = _Clock::now();
+}
+return false;
   }
 
 // Shared ownership
@@ -631,9 +639,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   try_lock_shared_until(const chrono::time_point<_Clock,
 _Duration>& __atime)
   {
-typename _Clock::time_point __now = _Clock::now();
-auto __rtime = __atime - __now;
-return try_lock_shared_for(__rtime);
+// The user-supplied clock may not tick at the same rate as
+// steady_clock, so we must loop in order to guarantee that
+// the timeout has expired before returning false.
+   typename _Clock::time_point __now = _Clock::now();
+while (__atime > __now) {
+  auto __rtime = __atime - __now;
+  if (try_lock_shared_for(__rtime))
+return true;
+  __now = _Clock::now();
+}
+return false;
   }
 
 #else // ! (_GLIBCXX_USE_PTHREAD_RWLOCK_T && _GTHREAD_USE_MUTEX_TIMEDLOCK)
diff --git a/libstdc++-v3/testsuite/30_threads/shared_mutex/try_lock_until/1.cc 
b/libstdc++-v3/testsuite/30_threads/shared_mutex/try_lock_until/1.cc
new file mode 100644
index 000..77baad9
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/shared_mutex/try_lock_until/1.cc
@@ -0,0 +1,87 @@
+// { dg-do run }
+// { dg-options "-pthread"  }
+// { dg-require-effective-target c++14 }
+// { dg-require-effective-target pthread }
+// { dg-require-gthreads "" }
+
+// Copyright (C) 2013-2019 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// .
+
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+template 
+void test()
+{
+  typedef std::shared_timed_mutex mutex_type;
+
+  try
+{
+  mutex_type m;
+  m.lock();
+  bool b;
+
+  std::thread t([&] {
+try
+  {
+using namespace std::chrono;
+const auto timeout = 100ms;
+
+   {
+ const auto start = clock_type::now();
+ 

[PATCH 04/11] libstdc++ testsuite: Also test unique_lock::try_lock_until with steady_clock

2019-09-28 Thread Mike Crowe
* testsuite/30_threads/unique_lock/locking/4.cc: Template test
functions so they can be used to test both steady_clock and
system_clock.
---
 libstdc++-v3/testsuite/30_threads/unique_lock/locking/4.cc | 12 +--
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/libstdc++-v3/testsuite/30_threads/unique_lock/locking/4.cc 
b/libstdc++-v3/testsuite/30_threads/unique_lock/locking/4.cc
index f10cd3f..1c544be 100644
--- a/libstdc++-v3/testsuite/30_threads/unique_lock/locking/4.cc
+++ b/libstdc++-v3/testsuite/30_threads/unique_lock/locking/4.cc
@@ -26,17 +26,18 @@
 #include 
 #include 
 
-int main()
+template 
+void test()
 {
   typedef std::timed_mutex mutex_type;
   typedef std::unique_lock lock_type;
-  typedef std::chrono::system_clock clock_type;
 
   try 
 {
   mutex_type m;
   lock_type l(m, std::defer_lock);
-  clock_type::time_point t = clock_type::now() + std::chrono::seconds(1);
+  const typename clock_type::time_point t = clock_type::now()
++ std::chrono::seconds(1);
 
   try
{
@@ -61,6 +62,11 @@ int main()
 {
   VERIFY( false );
 }
+}
 
+int main()
+{
+  test();
+  test();
   return 0;
 }
-- 
git-series 0.9.1


[PATCH 01/11] libstdc++ testsuite: Check return value from timed_mutex::try_lock_until

2019-09-28 Thread Mike Crowe
* testsuite/30_threads/unique_lock/locking/4.cc: Wrap call to
timed_mutex::try_lock_until in VERIFY macro to check its return
value.
---
 libstdc++-v3/testsuite/30_threads/unique_lock/locking/4.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libstdc++-v3/testsuite/30_threads/unique_lock/locking/4.cc 
b/libstdc++-v3/testsuite/30_threads/unique_lock/locking/4.cc
index fe0935f..f10cd3f 100644
--- a/libstdc++-v3/testsuite/30_threads/unique_lock/locking/4.cc
+++ b/libstdc++-v3/testsuite/30_threads/unique_lock/locking/4.cc
@@ -40,7 +40,7 @@ int main()
 
   try
{
- l.try_lock_until(t);
+ VERIFY( l.try_lock_until(t) );
}
   catch(const std::system_error&)
{
-- 
git-series 0.9.1


[PATCH 03/11] libstdc++ testsuite: Also test timed_mutex with steady_clock

2019-09-28 Thread Mike Crowe
* testsuite/30_threads/timed_mutex/try_lock_until/57641.cc:
  Template test functions and use them to test both steady_clock
  and system_clock.
---
 libstdc++-v3/testsuite/30_threads/timed_mutex/try_lock_until/57641.cc | 18 
+-
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git 
a/libstdc++-v3/testsuite/30_threads/timed_mutex/try_lock_until/57641.cc 
b/libstdc++-v3/testsuite/30_threads/timed_mutex/try_lock_until/57641.cc
index 12ee52f..6355d8f 100644
--- a/libstdc++-v3/testsuite/30_threads/timed_mutex/try_lock_until/57641.cc
+++ b/libstdc++-v3/testsuite/30_threads/timed_mutex/try_lock_until/57641.cc
@@ -49,18 +49,26 @@ struct clock
 std::timed_mutex mx;
 bool locked = false;
 
+template 
 void f()
 {
-  locked = mx.try_lock_until(clock::now() + C::milliseconds(1));
+  locked = mx.try_lock_until(ClockType::now() + C::milliseconds(1));
 }
 
-int main()
+template 
+void test()
 {
   std::lock_guard l(mx);
-  auto start = C::system_clock::now();
-  std::thread t(f);
+  auto start = ClockType::now();
+  std::thread t(f);
   t.join();
-  auto stop = C::system_clock::now();
+  auto stop = ClockType::now();
   VERIFY( (stop - start) < C::seconds(9) );
   VERIFY( !locked );
 }
+
+int main()
+{
+  test();
+  test();
+}
-- 
git-series 0.9.1


[PATCH 05/11] PR libstdc++/78237 Add full steady_clock support to timed_mutex

2019-09-28 Thread Mike Crowe
The pthread_mutex_clocklock function is available in glibc since the 2.30
release. If this function is available in the C library it can be used to
fix PR libstdc++/78237 by supporting steady_clock properly with
timed_mutex.

This means that code using timed_mutex::try_lock_for or
timed_mutex::wait_until with steady_clock is no longer subject to timing
out early or potentially waiting for much longer if the system clock is
warped at an inopportune moment.

If pthread_mutex_clocklock is available then steady_clock is deemed to be
the "best" clock available which means that it is used for the relative
try_lock_for calls and absolute try_lock_until calls using steady_clock and
user-defined clocks. Calls explicitly using system_clock (aka
high_resolution_clock) continue to use CLOCK_REALTIME via
__gthread_cond_timedwait.

If pthread_mutex_clocklock is not available then system_clock is deemed to
be the "best" clock available which means that the previous suboptimal
behaviour remains.

* acinclude.m4: Define GLIBCXX_CHECK_PTHREAD_MUTEX_CLOCKLOCK to
detect presence of pthread_mutex_clocklock function.

* config.h.in: Add _GLIBCXX_USE_PTHREAD_MUTEX_CLOCKLOCK define.

* configure.ac: Call GLIBCXX_CHECK_PTHREAD_MUTEX_CLOCKLOCK.

* configure: Add generated part to detect pthread_mutex_clocklock
function.

* include/std/mutex (__timed_mutex_impl): Remove unnecessary
__clock_t. (_M_try_lock_for) Use best clock to
turn relative timeout into absolute timeout. (_M_try_lock_until)
Keep existing implementation for system_clock. Add new
implementation for steady_clock that calls _M_clocklock. Modify
overload for user-defined clock to use a relative wait so that it
automatically uses the best clock.

* include/std/mutex (timed_mutex): If pthread_mutex_clocklock is
available, add _M_clocklock method that calls it.

* include/std/mutex (recursive_timed_mutex): Likewise.
---
 libstdc++-v3/acinclude.m4  | 31 +-
 libstdc++-v3/config.h.in   |  3 +-
 libstdc++-v3/configure | 82 +++-
 libstdc++-v3/configure.ac  |  3 +-
 libstdc++-v3/include/std/mutex | 49 +
 5 files changed, 160 insertions(+), 8 deletions(-)

diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
index ad2cb01..9ecfa96 100644
--- a/libstdc++-v3/acinclude.m4
+++ b/libstdc++-v3/acinclude.m4
@@ -4228,6 +4228,37 @@ AC_DEFUN([GLIBCXX_CHECK_PTHREAD_COND_CLOCKWAIT], [
 ])
 
 dnl
+dnl Check whether pthread_mutex_clocklock is available in  for 
std::timed_mutex to use,
+dnl and define _GLIBCXX_USE_PTHREAD_MUTEX_CLOCKLOCK.
+dnl
+AC_DEFUN([GLIBCXX_CHECK_PTHREAD_MUTEX_CLOCKLOCK], [
+
+  AC_LANG_SAVE
+  AC_LANG_CPLUSPLUS
+  ac_save_CXXFLAGS="$CXXFLAGS"
+  CXXFLAGS="$CXXFLAGS -fno-exceptions"
+  ac_save_LIBS="$LIBS"
+  LIBS="$LIBS -lpthread"
+
+  AC_MSG_CHECKING([for pthread_mutex_clocklock])
+  AC_CACHE_VAL(glibcxx_cv_PTHREAD_MUTEX_CLOCKLOCK, [
+GCC_TRY_COMPILE_OR_LINK(
+  [#include ],
+  [pthread_mutex_t mutex; struct timespec ts; int n = 
pthread_mutex_clocklock(, CLOCK_REALTIME, );],
+  [glibcxx_cv_PTHREAD_MUTEX_CLOCKLOCK=yes],
+  [glibcxx_cv_PTHREAD_MUTEX_CLOCKLOCK=no])
+  ])
+  if test $glibcxx_cv_PTHREAD_MUTEX_CLOCKLOCK = yes; then
+AC_DEFINE(_GLIBCXX_USE_PTHREAD_MUTEX_CLOCKLOCK, 1, [Define if 
pthread_mutex_clocklock is available in .])
+  fi
+  AC_MSG_RESULT($glibcxx_cv_PTHREAD_MUTEX_CLOCKLOCK)
+
+  CXXFLAGS="$ac_save_CXXFLAGS"
+  LIBS="$ac_save_LIBS"
+  AC_LANG_RESTORE
+])
+
+dnl
 dnl Check whether sysctl is available in , and define 
_GLIBCXX_USE_SYSCTL_HW_NCPU.
 dnl
 AC_DEFUN([GLIBCXX_CHECK_SYSCTL_HW_NCPU], [
diff --git a/libstdc++-v3/config.h.in b/libstdc++-v3/config.h.in
index 3d13402..9670176 100644
--- a/libstdc++-v3/config.h.in
+++ b/libstdc++-v3/config.h.in
@@ -994,6 +994,9 @@
 /* Define if pthread_cond_clockwait is available in . */
 #undef _GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT
 
+/* Define if pthread_mutex_clocklock is available in . */
+#undef _GLIBCXX_USE_PTHREAD_MUTEX_CLOCKLOCK
+
 /* Define if POSIX read/write locks are available in . */
 #undef _GLIBCXX_USE_PTHREAD_RWLOCK_T
 
diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure
index e646c41..41df34c 100755
--- a/libstdc++-v3/configure
+++ b/libstdc++-v3/configure
@@ -21677,6 +21677,88 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
 
 
+# For pthread_mutex_clocklock
+
+
+
+  ac_ext=cpp
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS 
conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+
+  ac_save_CXXFLAGS="$CXXFLAGS"
+  CXXFLAGS="$CXXFLAGS -fno-exceptions"
+  ac_save_LIBS="$LIBS"
+  LIBS="$LIBS -lpthread"
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for 
pthread_mutex_clocklock" >&5
+$as_echo_n "checking for 

[PATCH 09/11] libstdc++ shared_mutex: Add full steady_clock support to shared_timed_mutex

2019-09-28 Thread Mike Crowe
The pthread_rwlock_clockrdlock and pthread_rwlock_clockwrlock functions
were added to glibc in v2.30. They have also been added to Android
Bionic. If these functions are available in the C library then they can be
used to implement shared_timed_mutex::try_lock_until,
shared_timed_mutex::try_lock_for, shared_timed_mutex::try_lock_shared_until
and shared_timed_mutex::try_lock_shared_for so that they are no longer
unaffected by the system clock being warped. (This is the shared_mutex
equivalent of PR libstdc++/78237 for mutex.)

If the new functions are available then steady_clock is deemed to be the
"best" clock available which means that it is used for the relative
try_lock_for calls and absolute try_lock_until calls using steady_clock and
user-defined clocks. It's not possible to have
_GLIBCXX_USE_PTHREAD_RWLOCK_CLOCKLOCK defined without
_GLIBCXX_USE_PTHREAD_RWLOCK_T, so the requirement that the clock be the
same as condition_variable is maintained. Calls explicitly using
system_clock (aka high_resolution_clock) continue to use CLOCK_REALTIME via
the old pthread_rwlock_timedrdlock and pthread_rwlock_timedwrlock
functions.

If the new functions are not available then system_clock is deemed to be
the "best" clock available which means that the previous suboptimal
behaviour remains.

* libstdc++-v3/acinclude.m4: Define
GLIBCXX_CHECK_PTHREAD_RWLOCK_CLOCKLOCK to check for the presence of
both pthread_rwlock_clockrdlock and pthread_rwlock_clockwrlock.

* config.h.in: Add _GLIBCXX_USE_PTHREAD_RWLOCK_CLOCKLOCK define.

* configure.ac: Call GLIBCXX_USE_PTHREAD_RWLOCK_CLOCKLOCK.

* configure: Add generated part to detect
pthread_rwlock_clockrdlock and pthread_rwlock_clockwrlock
functions.

* include/std/shared_mutex (shared_timed_mutex): Define __clock_t
as the best clock to use for relative waits. (try_lock_until): Use
existing try_lock_until implementation for system_clock (which
matches __clock_t when _GLIBCCXX_USE_PTHREAD_RWLOCK_CLOCKLOCK is
not defined). Add new overload for steady_clock that uses
pthread_rwlock_clockwrlock if it is available. Simplify overload
for non-standard clock to just call try_lock_for with a relative
timeout. (try_lock_shared_until): Likewise.
---
 libstdc++-v3/acinclude.m4 | 33 +++-
 libstdc++-v3/config.h.in  |  4 +-
 libstdc++-v3/configure| 88 -
 libstdc++-v3/configure.ac |  3 +-
 libstdc++-v3/include/std/shared_mutex | 87 ++--
 5 files changed, 198 insertions(+), 17 deletions(-)

diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
index 9ecfa96..d860dbe 100644
--- a/libstdc++-v3/acinclude.m4
+++ b/libstdc++-v3/acinclude.m4
@@ -4259,6 +4259,39 @@ AC_DEFUN([GLIBCXX_CHECK_PTHREAD_MUTEX_CLOCKLOCK], [
 ])
 
 dnl
+dnl Check whether pthread_mutex_clocklock is available in  for 
std::timed_mutex to use,
+dnl and define _GLIBCXX_USE_PTHREAD_MUTEX_CLOCKLOCK.
+dnl
+AC_DEFUN([GLIBCXX_CHECK_PTHREAD_RWLOCK_CLOCKLOCK], [
+
+  AC_LANG_SAVE
+  AC_LANG_CPLUSPLUS
+  ac_save_CXXFLAGS="$CXXFLAGS"
+  CXXFLAGS="$CXXFLAGS -fno-exceptions"
+  ac_save_LIBS="$LIBS"
+  LIBS="$LIBS -lpthread"
+
+  AC_MSG_CHECKING([for pthread_rwlock_clockrdlock, pthread_wlock_clockwrlock])
+  AC_CACHE_VAL(glibcxx_cv_PTHREAD_RWLOCK_CLOCKLOCK, [
+GCC_TRY_COMPILE_OR_LINK(
+  [#include ],
+  [pthread_rwlock_t rwl; struct timespec ts;]
+  [int n = pthread_rwlock_clockrdlock(, CLOCK_REALTIME, );]
+  [int m = pthread_rwlock_clockwrlock(, CLOCK_REALTIME, );],
+  [glibcxx_cv_PTHREAD_RWLOCK_CLOCKLOCK=yes],
+  [glibcxx_cv_PTHREAD_RWLOCK_CLOCKLOCK=no])
+  ])
+  if test $glibcxx_cv_PTHREAD_RWLOCK_CLOCKLOCK = yes; then
+AC_DEFINE(_GLIBCXX_USE_PTHREAD_RWLOCK_CLOCKLOCK, 1, [Define if 
pthread_rwlock_clockrdlock and pthread_rwlock_clockwrlock are available in 
.])
+  fi
+  AC_MSG_RESULT($glibcxx_cv_PTHREAD_RWLOCK_CLOCKLOCK)
+
+  CXXFLAGS="$ac_save_CXXFLAGS"
+  LIBS="$ac_save_LIBS"
+  AC_LANG_RESTORE
+])
+
+dnl
 dnl Check whether sysctl is available in , and define 
_GLIBCXX_USE_SYSCTL_HW_NCPU.
 dnl
 AC_DEFUN([GLIBCXX_CHECK_SYSCTL_HW_NCPU], [
diff --git a/libstdc++-v3/config.h.in b/libstdc++-v3/config.h.in
index 9670176..6935797 100644
--- a/libstdc++-v3/config.h.in
+++ b/libstdc++-v3/config.h.in
@@ -997,6 +997,10 @@
 /* Define if pthread_mutex_clocklock is available in . */
 #undef _GLIBCXX_USE_PTHREAD_MUTEX_CLOCKLOCK
 
+/* Define if pthread_rwlock_clockrdlock and pthread_rwlock_clockwrlock are
+   available in . */
+#undef _GLIBCXX_USE_PTHREAD_RWLOCK_CLOCKLOCK
+
 /* Define if POSIX read/write locks are available in . */
 #undef _GLIBCXX_USE_PTHREAD_RWLOCK_T
 
diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure
index 41df34c..0265c1a 100755
--- a/libstdc++-v3/configure
+++ b/libstdc++-v3/configure
@@ -21760,6 +21760,94 @@ 

[PATCH 07/11] PR libstdc++/91906 Fix timed_mutex::try_lock_until on arbitrary clock

2019-09-28 Thread Mike Crowe
A non-standard clock may tick more slowly than std::chrono::steady_clock.
This means that we risk returning false early when the specified timeout
may not have expired. This can be avoided by looping until the timeout time
as reported by the non-standard clock has been reached.

Unfortunately, we have no way to tell whether the non-standard clock ticks
more quickly that std::chrono::steady_clock. If it does then we risk
returning later than would be expected, but that is unavoidable and
permitted by the standard.

* include/std/mutex (_M_try_lock_until): Loop until the absolute
timeout time is reached as measured against the appropriate clock.
* testsuite/30_threads/timed_mutex/try_lock_until/3.cc:
Also run test using slow_clock to test above fix.
* testsuite/30_threads/recursive_timed_mutex/try_lock_until/3.cc:
Likewise.
---
 libstdc++-v3/include/std/mutex  | 
13 +++--
 libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/try_lock_until/3.cc |  
2 ++
 libstdc++-v3/testsuite/30_threads/timed_mutex/try_lock_until/3.cc   |  
2 ++
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/std/mutex b/libstdc++-v3/include/std/mutex
index e06d286..bb3a41b 100644
--- a/libstdc++-v3/include/std/mutex
+++ b/libstdc++-v3/include/std/mutex
@@ -189,8 +189,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
bool
_M_try_lock_until(const chrono::time_point<_Clock, _Duration>& __atime)
{
- auto __rtime = __atime - _Clock::now();
- return _M_try_lock_for(__rtime);
+  // The user-supplied clock may not tick at the same rate as
+  // steady_clock, so we must loop in order to guarantee that
+  // the timeout has expired before returning false.
+  auto __now = _Clock::now();
+  while (__atime > __now) {
+auto __rtime = __atime - __now;
+if (_M_try_lock_for(__rtime))
+  return true;
+__now = _Clock::now();
+  }
+  return false;
}
 };
 
diff --git 
a/libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/try_lock_until/3.cc 
b/libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/try_lock_until/3.cc
index 4f0b0b5..a845cbf 100644
--- 
a/libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/try_lock_until/3.cc
+++ 
b/libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/try_lock_until/3.cc
@@ -26,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 
 template 
 void test()
@@ -71,4 +72,5 @@ int main()
 {
   test();
   test();
+  test();
 }
diff --git a/libstdc++-v3/testsuite/30_threads/timed_mutex/try_lock_until/3.cc 
b/libstdc++-v3/testsuite/30_threads/timed_mutex/try_lock_until/3.cc
index 69d1ea5..9f34644 100644
--- a/libstdc++-v3/testsuite/30_threads/timed_mutex/try_lock_until/3.cc
+++ b/libstdc++-v3/testsuite/30_threads/timed_mutex/try_lock_until/3.cc
@@ -26,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 
 template 
 void test()
@@ -71,4 +72,5 @@ int main()
 {
   test();
   test();
+  test();
 }
-- 
git-series 0.9.1


[PATCH 00/11] timed_mutex, shared_timed_mutex: Add full steady clock support

2019-09-28 Thread Mike Crowe
glibc v2.30 added the pthread_mutex_clocklock,
pthread_rwlock_clockrdlock and pthread_rwlock_clockwrlock
functions. These accept CLOCK_MONOTONIC, so they can be used to
implement proper steady_clock support in timed_mutex,
recursive_timed_mutex and shared_timed_mutex that is immune to the
system clock being warped.

Unfortunately we can't warp the system clock in the testsuite, so it's
not possible to automatically ensure that the system_clock test cases
result in a wait on CLOCK_REALTIME and steady_clock test cases result
in a wait on CLOCK_MONOTONIC. It's recommended to run the test under
strace(1) and check whether the expected futex calls are made by glibc
or ltrace(1) and check whether the expected pthread calls are
made. The easiest way to do this is to copy and paste the line used to
build the test from the output of running the tests (for example):

 make check-target-libstdc++-v3 
RUNTESTFLAGS="conformance.exp=30_threads/shared_mutex/* -v -v"

to compile the test with only the tests for one clock enabled and then
run it as:

 strace -f ./1.exe

You should see calls to:

 futex(..., FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME, ...)

with large values of tv_sec when using system_clock and calls to:

 futex(..., FUTEX_WAIT_BITSET_PRIVATE, ...)

Alternatively, you can use:

 ltrace -f ./1.exe

and look for calls to pthread_mutex_clocklock,
pthread_rwlock_clockrdlock and pthread_rwlock_clockwrlock with a
parameter of 1 for CLOCK_MONOTONIC and with values of tv_sec based on
the system uptime when using steady_clock.

This series also adds some extra tests and fixes some other minor
problems with the existing implementation and tests.

Mike Crowe (11):
  libstdc++ testsuite: Check return value from timed_mutex::try_lock_until
  libstdc++ testsuite: Add timed_mutex::try_lock_until test
  libstdc++ testsuite: Also test timed_mutex with steady_clock
  libstdc++ testsuite: Also test unique_lock::try_lock_until with steady_clock
  PR libstdc++/78237 Add full steady_clock support to timed_mutex
  libstdc++ testsuite: Move slow_clock to its own header
  PR libstdc++/91906 Fix timed_mutex::try_lock_until on arbitrary clock
  libstdc++ testsuite: Also test shared_timed_mutex with steady_clock
  libstdc++ shared_mutex: Add full steady_clock support to shared_timed_mutex
  libstdc++ timed_mutex: Ensure that try_lock_for waits for long enough
  shared_mutex: Fix try_lock_until and try_lock_shared_until on arbitrary clock

 libstdc++-v3/acinclude.m4   |  
64 +++-
 libstdc++-v3/config.h.in|  
 7 +++-
 libstdc++-v3/configure  | 
170 -
 libstdc++-v3/configure.ac   |  
 6 +++-
 libstdc++-v3/include/std/mutex  |  
60 +
 libstdc++-v3/include/std/shared_mutex   | 
117 +-
 libstdc++-v3/testsuite/30_threads/condition_variable/members/2.cc   |  
17 +---
 libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/try_lock_until/3.cc |  
76 -
 libstdc++-v3/testsuite/30_threads/shared_mutex/try_lock_until/1.cc  |  
87 +-
 libstdc++-v3/testsuite/30_threads/shared_timed_mutex/try_lock/3.cc  |  
17 ---
 libstdc++-v3/testsuite/30_threads/timed_mutex/try_lock_until/3.cc   |  
76 -
 libstdc++-v3/testsuite/30_threads/timed_mutex/try_lock_until/57641.cc   |  
18 +---
 libstdc++-v3/testsuite/30_threads/unique_lock/locking/4.cc  |  
14 --
 libstdc++-v3/testsuite/util/slow_clock.h|  
38 -
 14 files changed, 707 insertions(+), 60 deletions(-)
 create mode 100644 
libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/try_lock_until/3.cc
 create mode 100644 
libstdc++-v3/testsuite/30_threads/shared_mutex/try_lock_until/1.cc
 create mode 100644 
libstdc++-v3/testsuite/30_threads/timed_mutex/try_lock_until/3.cc
 create mode 100644 libstdc++-v3/testsuite/util/slow_clock.h

base-commit: dcfd68ec29a6823f75a52c934fe408ce4b4b6919
-- 
git-series 0.9.1


[SH][committed] Fix PR 80672

2019-09-28 Thread Oleg Endo
Hi,

The attached patch fixes PR 80672.
Tested by building the compiler with "make all-gcc" and manually
invoking it and checking that the option is parsed as expected.

Committed to trunk as r276240, GCC 9 as r276241, GCC 8 as r276242, GCC
7 as r276243.

Cheers,
Oleg


gcc/ChangeLog
PR target/80672
* config/sh/sh.c (parse_validate_atomic_model_option): Use
std::string::compare instead of std::string::find.
Index: gcc/config/sh/sh.c
===
--- gcc/config/sh/sh.c	(revision 276235)
+++ gcc/config/sh/sh.c	(working copy)
@@ -734,7 +734,7 @@
 {
   if (tokens[i] == "strict")
 	ret.strict = true;
-  else if (tokens[i].find ("gbr-offset=") == 0)
+  else if (!tokens[i].compare (0, strlen ("gbr-offset="), "gbr-offset="))
 	{
 	  std::string offset_str = tokens[i].substr (strlen ("gbr-offset="));
 	  ret.tcb_gbr_offset = integral_argument (offset_str.c_str ());


Re: [committed] [PR target/85993] Remove dead conditional in SH target code

2019-09-28 Thread Oleg Endo
On Sun, 2018-07-15 at 14:30 -0600, Jeff Law wrote:
> 
> Per Oleg's comment in the PR, the second block is dead and should be
> removed...
> 
> Committing to the trunk.   While I'm confident this won't change
> anything, my tester will bootstrap sh4 & sh4eb overnight for
> additional
> verification.
> 

Probably irrelevant, but just for the record ...

I've just backported this patch to GCC 7 and GCC 8 branches as r276237
and r276239.

Tested briefly with "make all-gcc".

Cheers,
Oleg



Re: [PR 91853] Prevent IPA-SRA ICEs on type-mismatched calls

2019-09-28 Thread Richard Biener
On September 28, 2019 12:24:40 AM GMT+02:00, Martin Jambor  
wrote:
>Hi,
>
>On Thu, Sep 26 2019, Richard Biener wrote:
>> On Wed, 25 Sep 2019, Martin Jambor wrote:
>>
>>> Hi,
>>> 
>>> PR 91853 and its duplicate PR 91894 show that IPA-SRA can stumble
>when
>>> presented with code with mismatched types, whether because it is a
>K C
>>> or happening through an originally indirect call (or probably also
>>> because of LTO).
>>> 
>>> The problem is that we try to work with a register value - in this
>case
>>> an integer constant - like if it was a pointer to a structure and
>try to
>>> dereference it in the caller, leading to expressions like ADDR_EXPR
>of a
>>> constant zero.  Old IPA-SRA dealt with these simply by checking type
>>> compatibility which is difficult in an LTO-capable IPA pass,
>basically
>>> we would at least have to remember and stream a bitmap for each call
>>> telling which arguments are pointers which looks a bit excessive
>given
>>> that we just don't want to ICE.
>>> 
>>> So this patch attempts to deal with the situation rather than avoid
>it.
>>> When an integer is used instead of a pointer, there is some chance
>that
>>> it actually contains the pointer value and so I create a NOP_EXPR to
>>> convert it to a pointer (which in the testcase is actually a
>widening
>>> conversion).  For other register types, I don't bother and simply
>pull
>>> an undefined pointer default definition SSA name and use that.  I
>wonder
>>> whether I should somehow warn as well.  Hopefully there is no code
>doing
>>> that that can conceivably work - maybe someone coding for x86_16 and
>>> passing a vector of integers as a segment and offset pointer? :-)
>>> 
>>> What do people think?  In any event, this patch passed bootstrap and
>>> testing and deals with the issue, so if it is OK, I'd like to commit
>it
>>> to trunk.
>>
>> Humm...   while I believe this "mostly" matches what we do in
>inlining
>> (but that also has some type verification disabling inlining for
>really
>> odd cases IIRC) I think the appropriate fix is in the IPA-SRA
>> decision stage (at WPA) where we should see that we cannot modify
>> a call in this way.  That of course requires streaming of the actual
>> call stmt (or at least it's "ABI signature"), not sure if you already
>> do that.
>
>No, I don't.  As I wrote above, even though would be enough to know
>which actual arguments are pointers and which are not, I'd rather avoid
>that too if we can.
>
>I am looking into doing something similar that inlining does, but I'd
>very much like to avoid re-creating a variant of PR 70929 for IPA-SRA
>too, so I am looking into that PR.
>
>>
>> So in inlining we do
>>
>> static gimple *
>> setup_one_parameter (copy_body_data *id, tree p, tree value, tree fn,
>>  basic_block bb, tree *vars)
>> {
>> ...
>>   if (value
>>   && value != error_mark_node
>>   && !useless_type_conversion_p (TREE_TYPE (p), TREE_TYPE
>(value)))
>> {
>>   /* If we can match up types by promotion/demotion do so.  */
>>   if (fold_convertible_p (TREE_TYPE (p), value))
>> rhs = fold_convert (TREE_TYPE (p), value);
>>   else
>> {
>>   /* ???  For valid programs we should not end up here.
>>  Still if we end up with truly mismatched types here,
>fall 
>> back
>>  to using a VIEW_CONVERT_EXPR or a literal zero to not
>leak 
>> invalid
>>  GIMPLE to the following passes.  */
>>   if (!is_gimple_reg_type (TREE_TYPE (value))
>>   || TYPE_SIZE (TREE_TYPE (p)) == TYPE_SIZE (TREE_TYPE 
>> (value)))
>> rhs = fold_build1 (VIEW_CONVERT_EXPR, TREE_TYPE (p),
>value);
>>   else
>> rhs = build_zero_cst (TREE_TYPE (p));
>> }
>> }
>>
>> I suggest that if we go a similar way that we copy this behavior
>> rather than inventing sth similar but slightly different.  Maybe
>> split it out as
>>
>> tree
>> force_value_to_type (tree type, tree val)
>
>Makes sense, like the patch below?  It has passed bootstrap and testing
>on an x86_64-linux.
>
>>
>> which you then would need to eventually re-gimplify of course
>> (we could in theory refactor setup_one_parameter to work with
>> GIMPLE...)
>
>If we start with a gimple_val, the code above should at worst produce
>something we can feed into gimple_assign_set_rhs_from_tree, which is
>not
>ideal but is better than full re-gimplification?

Yeah, that should work. 

Patch is OK. 

Thanks, 
Richard. 

>Thanks,
>
>Martin
>
>
>2019-09-27  Martin Jambor  
>
>   PR ipa/91853
>   * tree-inline.c (force_value_to_type): New function.
>   (setup_one_parameter): Use force_value_to_type to convert type.
>   * tree-inline.c (force_value_to_type): Declare.
>   * ipa-param-manipulation.c (ipa_param_adjustments::modify_call): Deal
>   with register type mismatches.
>
>   testsuite/
>   * gcc.dg/ipa/pr91853.c: New test.
>---
> gcc/ipa-param-manipulation.c   | 11 ++--
> 

Re: Fix endian issue in pr91656 testcases

2019-09-28 Thread Richard Biener
On September 28, 2019 8:34:59 AM GMT+02:00, Alan Modra  wrote:
>Tested on powerpc64le-linux and powerpc64-linux.  OK?

Ok. 

Thanks, 
Richard. 

>pr91656-3.c didn't really need to be changed since popcount doesn't
>care which bits are set, but I figured it was better to make the test
>set the low 16 bits of the 64-bit value in both big and litte endian.
>
>   PR testsuite/91676
>   PR rtl-optimization/91656
>   * gcc.dg/torture/pr91656-1.c: Correct for big and pdp endian.
>   * gcc.dg/torture/pr91656-2.c: Likewise.
>   * gcc.dg/torture/pr91656-3.c: Likewise.
>
>diff --git a/gcc/testsuite/gcc.dg/torture/pr91656-1.c
>b/gcc/testsuite/gcc.dg/torture/pr91656-1.c
>index 6c1e73c7f01..fae17de1112 100644
>--- a/gcc/testsuite/gcc.dg/torture/pr91656-1.c
>+++ b/gcc/testsuite/gcc.dg/torture/pr91656-1.c
>@@ -6,7 +6,17 @@ int a, b, c, d, e;
> static __attribute__ ((__noipa__))
> int foo (int i)
> {
>+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
>   __builtin_memmove (, , 1);
>+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
>+  __builtin_memmove ((char *)  + sizeof (i) - 1,
>+   (char *)  + sizeof (e) - 1, 1);
>+#elif __BYTE_ORDER__ == __ORDER_PDP_ENDIAN__
>+  __builtin_memmove ((char *)  + sizeof (i) - 2,
>+   (char *)  + sizeof (e) - 2, 1);
>+#else
>+#error "endian unknown?"
>+#endif
>   if (a > 0)
> i /= e;
>   e /= 5;
>diff --git a/gcc/testsuite/gcc.dg/torture/pr91656-2.c
>b/gcc/testsuite/gcc.dg/torture/pr91656-2.c
>index 90374becae0..29a619b280e 100644
>--- a/gcc/testsuite/gcc.dg/torture/pr91656-2.c
>+++ b/gcc/testsuite/gcc.dg/torture/pr91656-2.c
>@@ -12,7 +12,17 @@ d (u16 g)
> {
>   u64 f = __builtin_bswap64 (c);
>   f = g == a;
>+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
>   __builtin_memmove (, , 1);
>+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
>+  __builtin_memmove ((char *)  + sizeof (f) - 1,
>+   (char *)  + sizeof (e) - 1, 1);
>+#elif __BYTE_ORDER__ == __ORDER_PDP_ENDIAN__
>+  __builtin_memmove ((char *)  + sizeof (f) - 2,
>+   (char *)  + sizeof (e) - 2, 1);
>+#else
>+#error "endian unknown?"
>+#endif
>   e >>= b;
>   return a + f;
> }
>diff --git a/gcc/testsuite/gcc.dg/torture/pr91656-3.c
>b/gcc/testsuite/gcc.dg/torture/pr91656-3.c
>index 8e65d24a21d..f84e51af4a4 100644
>--- a/gcc/testsuite/gcc.dg/torture/pr91656-3.c
>+++ b/gcc/testsuite/gcc.dg/torture/pr91656-3.c
>@@ -10,7 +10,14 @@ int
> d (u16 e, u64 f)
> {
>   b |= e;
>+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
>   __builtin_memset (, e, 2);
>+#elif (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ \
>+   || __BYTE_ORDER__ == __ORDER_PDP_ENDIAN__)
>+  __builtin_memset ((char *)  + sizeof (f) - 2, e, 2);
>+#else
>+#error "endian unknown?"
>+#endif
>   a = (u16) - e >= 2 ? : __builtin_popcountll (f);
>   return a + c;
> }



Fix endian issue in pr91656 testcases

2019-09-28 Thread Alan Modra
Tested on powerpc64le-linux and powerpc64-linux.  OK?

pr91656-3.c didn't really need to be changed since popcount doesn't
care which bits are set, but I figured it was better to make the test
set the low 16 bits of the 64-bit value in both big and litte endian.

PR testsuite/91676
PR rtl-optimization/91656
* gcc.dg/torture/pr91656-1.c: Correct for big and pdp endian.
* gcc.dg/torture/pr91656-2.c: Likewise.
* gcc.dg/torture/pr91656-3.c: Likewise.

diff --git a/gcc/testsuite/gcc.dg/torture/pr91656-1.c 
b/gcc/testsuite/gcc.dg/torture/pr91656-1.c
index 6c1e73c7f01..fae17de1112 100644
--- a/gcc/testsuite/gcc.dg/torture/pr91656-1.c
+++ b/gcc/testsuite/gcc.dg/torture/pr91656-1.c
@@ -6,7 +6,17 @@ int a, b, c, d, e;
 static __attribute__ ((__noipa__))
 int foo (int i)
 {
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
   __builtin_memmove (, , 1);
+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+  __builtin_memmove ((char *)  + sizeof (i) - 1,
+(char *)  + sizeof (e) - 1, 1);
+#elif __BYTE_ORDER__ == __ORDER_PDP_ENDIAN__
+  __builtin_memmove ((char *)  + sizeof (i) - 2,
+(char *)  + sizeof (e) - 2, 1);
+#else
+#error "endian unknown?"
+#endif
   if (a > 0)
 i /= e;
   e /= 5;
diff --git a/gcc/testsuite/gcc.dg/torture/pr91656-2.c 
b/gcc/testsuite/gcc.dg/torture/pr91656-2.c
index 90374becae0..29a619b280e 100644
--- a/gcc/testsuite/gcc.dg/torture/pr91656-2.c
+++ b/gcc/testsuite/gcc.dg/torture/pr91656-2.c
@@ -12,7 +12,17 @@ d (u16 g)
 {
   u64 f = __builtin_bswap64 (c);
   f = g == a;
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
   __builtin_memmove (, , 1);
+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+  __builtin_memmove ((char *)  + sizeof (f) - 1,
+(char *)  + sizeof (e) - 1, 1);
+#elif __BYTE_ORDER__ == __ORDER_PDP_ENDIAN__
+  __builtin_memmove ((char *)  + sizeof (f) - 2,
+(char *)  + sizeof (e) - 2, 1);
+#else
+#error "endian unknown?"
+#endif
   e >>= b;
   return a + f;
 }
diff --git a/gcc/testsuite/gcc.dg/torture/pr91656-3.c 
b/gcc/testsuite/gcc.dg/torture/pr91656-3.c
index 8e65d24a21d..f84e51af4a4 100644
--- a/gcc/testsuite/gcc.dg/torture/pr91656-3.c
+++ b/gcc/testsuite/gcc.dg/torture/pr91656-3.c
@@ -10,7 +10,14 @@ int
 d (u16 e, u64 f)
 {
   b |= e;
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
   __builtin_memset (, e, 2);
+#elif (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ \
+   || __BYTE_ORDER__ == __ORDER_PDP_ENDIAN__)
+  __builtin_memset ((char *)  + sizeof (f) - 2, e, 2);
+#else
+#error "endian unknown?"
+#endif
   a = (u16) - e >= 2 ? : __builtin_popcountll (f);
   return a + c;
 }

-- 
Alan Modra
Australia Development Lab, IBM