Re: [patch, libfortran] Fix EXECUTE_COMMAND_LINE error return

2017-10-09 Thread Janne Blomqvist
On Tue, Oct 10, 2017 at 12:34 AM, Thomas Koenig  wrote:
> Hello world,
>
> currently, EXECUTE_COMMAND_LINE aborts the program if the called program
> is not found, if cmdstat is present, but cmdmsg isn't. This is a 6/7/8
> regression.
>
> This patch fixes the issue by simply removing the erronous call to
> runtime_error.
>
> Regression-tested.  OK for all affected branches?
>
> Regards
>
> Thomas
>
> 2017-10-10  Thomas Koenig  
>
> PR libfortran/82233
> * intrinsics/execute_command_line.c (execute_command_line):
> No call to runtime_error if cmdstat is present.
>
> 2017-10-10  Thomas Koenig  
>
> PR libfortran/82233
> * gfortran.dg/execute_command_line_3.f90: New test.

Ok, thanks for the patch.

-- 
Janne Blomqvist


Re: [PATCH] libstdc++: istreambuf_iterator proxy

2017-10-09 Thread Petr Ovtchenkov
On Sun, 8 Oct 2017 16:59:39 +0200
François Dumont  wrote:

> ...
> >>> We have three issues with istreambuf_iterator:
> >>> - debug-dependent behaviour
> >> Fixed.
> > +   __glibcxx_requires_cond(_M_sbuf,
> > _M_message(__gnu_debug::__msg_inc_istreambuf)
> > ._M_iterator(*this));
> > vs
> >
> > +   __glibcxx_requires_cond(_M_sbuf && !_S_is_eof(_M_sbuf->sgetc()),
> > _M_message(__gnu_debug::__msg_inc_istreambuf)
> > ._M_iterator(*this));
> >
> > and
> >
> > +   __glibcxx_requires_cond(_M_sbuf
> > +   && 
> > !traits_type::eq_int_type(_M_c,traits_type::eof()),
> > _M_message(__gnu_debug::__msg_inc_istreambuf)
> > ._M_iterator(*this));
> > vs
> >
> > +   __glibcxx_requires_cond(_M_sbuf && !_S_is_eof(_M_sbuf->sgetc()),
> > _M_message(__gnu_debug::__msg_inc_istreambuf)
> > ._M_iterator(*this));
> >
> > I'm insist on the first variant. It free from code that may lead to 
> > different
> > behaviour between debug/non-debug (like _M_sbuf->sgetc()).
> 
> The first patch fixed the impact of the Debug mode on the 
> istreambuf_iterator state. This kind of difference is classical with 
> Debug mode, this mode usually introduces additional calls to some 
> operators or in this case to sgetc.
> 

The key is "_M_sbuf->sgetc()" and "_S_is_eof" that may call ->sgetc() too.
This may lead to difference in debug/non-debug behaviour.
Solution without such difference exist and was presented here.


Re: [PATCH] Fix ICEs with ss{e,e2,se3} builtins with -mno-mmx (PR target/82483)

2017-10-09 Thread H.J. Lu
On 10/9/17, Jakub Jelinek  wrote:
> On Mon, Oct 09, 2017 at 09:28:58PM +0200, Uros Bizjak wrote:
>> On Mon, Oct 9, 2017 at 9:16 PM, Jakub Jelinek  wrote:
>> > Hi!
>> >
>> > The following builtins have {SSE,SSE2,SSSE3} CPUID, yet they have
>> > MMX register operands (either input or output or both).
>> > As -mno-mmx doesn't imply -mno-sse, we get ICEs on these though,
>> > because
>> > with MMX disabled it is not possible to emit them.
>> >
>> > The following patch cheats and declares these builtins to require
>> > both the MMX and {SSE,SSE2,SSSE3} ISA, making them unavailable in
>> > -mno-mmx
>> > code, but I think it is the right thing to do, when somebody uses
>> > -mno-mmx,
>> > the intent is usually not to have any instructions touching the MMX
>> > register
>> > file and thus needing EMMS etc.
>> >
>> > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>>
>> Hm, I remember there was similar patch for PR79565 [1], which seems
>> related. Does your patch also fix all builtins that HJ's patch touch?
>
> Ah, I wasn't aware of that patch.  Will look in detail tomorrow.
>
>> [1] https://gcc.gnu.org/ml/gcc-patches/2017-08/msg00751.html
>
> Just quick analysis, while -mno-mmx doesn't imply -mno-sse (that is
> right), it implies -mno-3dnow and -mno-3dnow implies -mno-3dnowa.
> So all the spots that were changed from OPTION_MASK_ISA_3DNOW
> to OPTION_MASK_ISA_3DNOW | OPTION_MASK_ISA_MMX or from
> OPTION_MASK_ISA_3DNOW_A to OPTION_MASK_ISA_3DNOW_A | OPTION_MASK_ISA_MMX
> were useless, we can do what we did before.
> It is just OPTION_MASK_ISA_SSE or higher with OPTION_MASK_ISA_MMX that
> is needed.
> I have no idea why __builtin_ia32_sfence or __builtin_ia32_movntq were
> changed.
> Nor I understand why any sse.md changes are needed, then the builtins
> aren't available, those insns shouldn't be synthetized out of thin air.
> And the i386.c def_builtin change IMNSHO isn't needed either, it is
> a compile time speed/memory optimization not to declare everything
> unconditionally, and the way it works right now is that any of the enabled
> ISAs enables the builtin, meaning that MMX enabled will mean those
> 35 will be declared, even when perhaps SSE isn't enabled, or for
> SSE when MMX isn't enabled, but that isn't that big deal.
>
>

Please free feel to change it as long as there is no regression.

Thanks.


-- 
H.J.


Re: [PATCH][mingw] Enable colorized diagnostics

2017-10-09 Thread Liu Hao

On 2017/10/10 6:25, Manuel López-Ibáñez wrote:
For what is worth, the color output of GCC comes originally from grep, 
and grep does have code for colorizing in Windows: 
http://git.savannah.gnu.org/cgit/grep.git/tree/lib


and there are significant differences with this patch. For once,

   /* $TERM is not normally defined on DOS/Windows, so don't require
  it for highlighting.  But some programs, like Emacs, do define
  it when running Grep as a subprocess, so make sure they don't
  set TERM=dumb.  */
   char const *t = getenv ("TERM");
   return ! (t && strcmp (t, "dumb") == 0);

and they don't need a custom fputs() because their strategy is slightly 
different: They only override colorize_start (print_start_colorize) and 
colorize_stop (print_end_colorize) and convert ANSI sequences to W32 
sequences on the fly. Thus, we wouldn't need to touch pretty-printer.c
Since on *nix it is not when `colorize_start()` is called that the 
terminal color is changed (it is when those ANSI escape codes are 
delivered to the other peer which will translate them), and the string 
passed to `fputs()` is free to deliver multiple escape codes, it is not 
an option unless we output integral diagnostic messages using multiple 
fputs()` calls.


For example,
```
test.c:3:9: warning: 'a' is used uninitialized in this function 
[-Wuninitialized]

```
The words 'warning' and '-Wuninitialized' should be magenta, so there 
are four ANSI escape codes (two to set the color and another two to 
restore the color), and this line of text must be output using five 
individual calls to the `fputs()` function (one for each segment with 
the consistent color), which is not the case (this whole line of text is 
delivered using a single call), so all five segments have to be all in 
magenta or no color at all. This is not a solution.


and all changes will be restricted to diagnostic-color.c (which could be 
split into -posix.c and -w32.c like grep does and be moved into 
host-specific config/ subdir).


Even if the host-specific part is not done, I honestly think it is a 
good idea to match grep's code as much as possible since we may want to 
merge bugfixes between the two and eventually this code may end up in 
gnulib. Moreover, if somebody else implemented color output for another 
OS in grep, it would be very easy to transplant it to GCC (or viceversa) 
if the API remains close.


Cheers,

 Manuel.



--
Best regards,
LH_Mouse



Re: [PATCH][mingw] Enable colorized diagnostics

2017-10-09 Thread Manuel López-Ibáñez

On 09/10/17 23:25, Manuel López-Ibáñez wrote:
Even if the host-specific part is not done, I honestly think it is a good idea 
to match grep's code as much as possible since we may want to merge bugfixes 
between the two and eventually this code may end up in gnulib. Moreover, if 
somebody else implemented color output for another OS in grep, it would be very 
easy to transplant it to GCC (or viceversa) if the API remains close.


Something like the attached should do the trick (I didn't even try to compile 
it and completely untested, so it may need some adjustments).


Cheers,

Manuel.
Index: diagnostic-color.c
===
--- diagnostic-color.c	(revision 253569)
+++ diagnostic-color.c	(working copy)
@@ -19,6 +19,12 @@
 #include "config.h"
 #include "system.h"
 #include "diagnostic-color.h"
+#ifdef __MINGW32__
+#  undef DATADIR /* conflicts with objidl.h, which is included by windows.h */
+#  include 
+static HANDLE hstderr = INVALID_HANDLE_VALUE;
+static SHORT norm_attr;
+#endif
 
 /* Select Graphic Rendition (SGR, "\33[...m") strings.  */
 /* Also Erase in Line (EL) to Right ("\33[K") by default.  */
@@ -104,7 +110,125 @@
 #define SGR_SEQ(str)		SGR_START str SGR_END
 #define SGR_RESET		SGR_SEQ("")
 
+#ifdef __MINGW32__
+/* Convert a color spec, a semi-colon separated list of the form
+   SGR_START"NN;MM;KK;..."SGR_END, where each number is a value of the SGR
+   parameter, into the corresponding Windows console text attribute.
 
+   This function supports a subset of the SGR rendition aspects that
+   the Windows console can display.  */
+static int
+w32_sgr2attr (const char *sgr_seq)
+{
+  const char *s, *p;
+  int code, fg = norm_attr & 15, bg = norm_attr & (15 << 4);
+  int bright = 0, inverse = 0;
+  static const int fg_color[] = {
+0,			/* black */
+FOREGROUND_RED,	/* red */
+FOREGROUND_GREEN,	/* green */
+FOREGROUND_GREEN | FOREGROUND_RED, /* yellow */
+FOREGROUND_BLUE,		   /* blue */
+FOREGROUND_BLUE | FOREGROUND_RED,  /* magenta */
+FOREGROUND_BLUE | FOREGROUND_GREEN, /* cyan */
+FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE /* gray */
+  };
+  static const int bg_color[] = {
+0,			/* black */
+BACKGROUND_RED,	/* red */
+BACKGROUND_GREEN,	/* green */
+BACKGROUND_GREEN | BACKGROUND_RED, /* yellow */
+BACKGROUND_BLUE,		   /* blue */
+BACKGROUND_BLUE | BACKGROUND_RED,  /* magenta */
+BACKGROUND_BLUE | BACKGROUND_GREEN, /* cyan */
+BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE /* gray */
+  };
+
+  sgr_seq = sqr_seq + strlen(SGR_START);
+  
+  for (s = p = sgr_seq; strcmp(s, SGR_END) != 0; p++)
+{
+  if (*p == ';' || strcmp(p, SGR_END) == 0)
+{
+  code = strtol (s, NULL, 10);
+  s = p + (strcmp(p, SGR_END) != 0);
+
+  switch (code)
+{
+case 0:	/* all attributes off */
+  fg = norm_attr & 15;
+  bg = norm_attr & (15 << 4);
+  bright = 0;
+  inverse = 0;
+  break;
+case 1:	/* intensity on */
+  bright = 1;
+  break;
+case 7:	/* inverse video */
+  inverse = 1;
+  break;
+case 22:	/* intensity off */
+  bright = 0;
+  break;
+case 27:	/* inverse off */
+  inverse = 0;
+  break;
+case 30: case 31: case 32: case 33: /* foreground color */
+case 34: case 35: case 36: case 37:
+  fg = fg_color[code - 30];
+  break;
+case 39:	/* default foreground */
+  fg = norm_attr & 15;
+  break;
+case 40: case 41: case 42: case 43: /* background color */
+case 44: case 45: case 46: case 47:
+  bg = bg_color[code - 40];
+  break;
+case 49:	/* default background */
+  bg = norm_attr & (15 << 4);
+  break;
+default:
+  break;
+}
+}
+}
+  if (inverse)
+{
+  int t = fg;
+  fg = (bg >> 4);
+  bg = (t << 4);
+}
+  if (bright)
+fg |= FOREGROUND_INTENSITY;
+
+  return (bg & (15 << 4)) | (fg & 15);
+}
+
+/* Clear to the end of the current line with the default attribute.
+   This is needed for reasons similar to those that require the "EL to
+   Right after SGR" operation on Posix platforms: if we don't do this,
+   setting the 'mt', 'ms', or 'mc' capabilities to use a non-default
+   background color spills that color to the empty space at the end of
+   the last screen line in a match whose line spans multiple screen
+   lines.  */
+static void
+w32_clreol (void)
+{
+  DWORD nchars;
+  COORD start_pos;
+  DWORD written;
+  CONSOLE_SCREEN_BUFFER_INFO csbi;
+
+  GetConsoleScreenBufferInfo (hstderr, );
+  start_pos = csbi.dwCursorPosition;
+  nchars = csbi.dwSize.X - start_pos.X;
+
+  

Re: [PATCH, rs6000] fix-up int128 fold vector multiply tests

2017-10-09 Thread Segher Boessenkool
Hi Will,

On Mon, Oct 09, 2017 at 04:27:54PM -0500, Will Schmidt wrote:
> Fix up a few issues with the tests.
> - add -O2 to int128-p8 test, and firm up the -mcpu options
> - update the set of expected instructions for the int128-p9 test.
> - replace the float128_hw requirement with power8_vector_ok
> for the int128-p9 test.

> -/* { dg-final { scan-assembler-times "\[ \t\]mulld " 6 } } */
> +/* { dg-final { scan-assembler-times "\[ \t\]mulld" 6 } } */

Why this?  (Better/easier would be to use \m and \M btw.)

> diff --git a/gcc/testsuite/gcc.target/powerpc/fold-vec-mult-int128-p9.c 
> b/gcc/testsuite/gcc.target/powerpc/fold-vec-mult-int128-p9.c
> index e81ea5f..a226ae0 100644
> --- a/gcc/testsuite/gcc.target/powerpc/fold-vec-mult-int128-p9.c
> +++ b/gcc/testsuite/gcc.target/powerpc/fold-vec-mult-int128-p9.c
> @@ -1,10 +1,10 @@
>  /* Verify that overloaded built-ins for vec_mul with __int128
> inputs produce the right results.  */
>  
>  /* { dg-do compile } */
> -/* { dg-require-effective-target powerpc_float128_hw_ok } */
> +/* { dg-require-effective-target powerpc_p8vector_ok } */
>  /* { dg-require-effective-target int128 } */
>  /* { dg-skip-if "do not override -mcpu" { powerpc*-*-* } { "-mcpu=*" } { 
> "-mcpu=power9" } } */
>  /* { dg-options "-mcpu=power9 -O2" } */
>  /* { dg-additional-options "-maix64" { target powerpc-ibm-aix* } } */

This looks curious, too.  With the change it will no longer work if you
built GCC with a version of binutils that doesn't support p9, I think?
Not that people should do that.


Segher


[PATCH] rs6000: Move processor_costs to header

2017-10-09 Thread Segher Boessenkool
This moves the processor_costs structure declaration to the rs6000.h
header file, so that things in other files can use it (not just things
in rs6000.c).

Tested as usual; committing.


2010-10-09  Segher Boessenkool  

* config/rs6000/rs6000.c (processor_costs): Move to ...
* config/rs6000/rs6000.h: ... here.
(rs6000_cost): Declare.

---
 gcc/config/rs6000/rs6000.c | 23 +--
 gcc/config/rs6000/rs6000.h | 23 +++
 2 files changed, 24 insertions(+), 22 deletions(-)

diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index 104f2ed..f98ef93 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -637,31 +637,10 @@ mode_supports_vsx_dform_quad (machine_mode mode)
 }
 
 
-/* Target cpu costs.  */
-
-struct processor_costs {
-  const int mulsi;   /* cost of SImode multiplication.  */
-  const int mulsi_const;  /* cost of SImode multiplication by constant.  */
-  const int mulsi_const9; /* cost of SImode mult by short constant.  */
-  const int muldi;   /* cost of DImode multiplication.  */
-  const int divsi;   /* cost of SImode division.  */
-  const int divdi;   /* cost of DImode division.  */
-  const int fp;  /* cost of simple SFmode and DFmode insns.  */
-  const int dmul;/* cost of DFmode multiplication (and fmadd).  */
-  const int sdiv;/* cost of SFmode division (fdivs).  */
-  const int ddiv;/* cost of DFmode division (fdiv).  */
-  const int cache_line_size;/* cache line size in bytes. */
-  const int l1_cache_size; /* size of l1 cache, in kilobytes.  */
-  const int l2_cache_size; /* size of l2 cache, in kilobytes.  */
-  const int simultaneous_prefetches; /* number of parallel prefetch
-   operations.  */
-  const int sfdf_convert;  /* cost of SF->DF conversion.  */
-};
+/* Processor costs (relative to an add) */
 
 const struct processor_costs *rs6000_cost;
 
-/* Processor costs (relative to an add) */
-
 /* Instruction size costs on 32bit processors.  */
 static const
 struct processor_costs size32_cost = {
diff --git a/gcc/config/rs6000/rs6000.h b/gcc/config/rs6000/rs6000.h
index 6021972..21e536b 100644
--- a/gcc/config/rs6000/rs6000.h
+++ b/gcc/config/rs6000/rs6000.h
@@ -2065,6 +2065,29 @@ extern scalar_int_mode rs6000_pmode;
 #define REVERSE_CONDITION(CODE, MODE) rs6000_reverse_condition (MODE, CODE)
 
 
+/* Target cpu costs.  */
+
+struct processor_costs {
+  const int mulsi;   /* cost of SImode multiplication.  */
+  const int mulsi_const;  /* cost of SImode multiplication by constant.  */
+  const int mulsi_const9; /* cost of SImode mult by short constant.  */
+  const int muldi;   /* cost of DImode multiplication.  */
+  const int divsi;   /* cost of SImode division.  */
+  const int divdi;   /* cost of DImode division.  */
+  const int fp;  /* cost of simple SFmode and DFmode insns.  */
+  const int dmul;/* cost of DFmode multiplication (and fmadd).  */
+  const int sdiv;/* cost of SFmode division (fdivs).  */
+  const int ddiv;/* cost of DFmode division (fdiv).  */
+  const int cache_line_size;/* cache line size in bytes. */
+  const int l1_cache_size; /* size of l1 cache, in kilobytes.  */
+  const int l2_cache_size; /* size of l2 cache, in kilobytes.  */
+  const int simultaneous_prefetches; /* number of parallel prefetch
+   operations.  */
+  const int sfdf_convert;  /* cost of SF->DF conversion.  */
+};
+
+extern const struct processor_costs *rs6000_cost;
+
 /* Control the assembler format that we output.  */
 
 /* A C string constant describing how to begin a comment in the target
-- 
1.8.3.1



Re: Restore functional DONT_USE_BUILTIN_SETJMP support

2017-10-09 Thread Eric Botcazou
> You're right, not clear why I didn't spot it on Aarch64.  Hunk reverted.

The attached patch replaces it with an ad-hoc definition of setjmp, like the 
ones used for the coverage routines.  Tested on Aarch64/Linux with and without 
--enable-sjlj-exceptions and on IA-64/Linux without --enable-sjlj-exceptions.

Applied on the mainline as obvious.


2017-10-09  Eric Botcazou  

* except.c (setjmp_fn): New global variable.
(init_eh): Initialize it if DONT_USE_BUILTIN_SETJMP is defined.
(sjlj_emit_function_enter): Call it instead of BUILTIN_SETJMP if
DONT_USE_BUILTIN_SETJMP is defined.

-- 
Eric BotcazouIndex: except.c
===
--- except.c	(revision 253530)
+++ except.c	(working copy)
@@ -147,7 +147,9 @@ along with GCC; see the file COPYING3.
 
 static GTY(()) int call_site_base;
 
-static GTY (()) hash_map *type_to_runtime_map;
+static GTY(()) hash_map *type_to_runtime_map;
+
+static GTY(()) tree setjmp_fn;
 
 /* Describe the SjLj_Function_Context structure.  */
 static GTY(()) tree sjlj_fc_type_node;
@@ -331,6 +333,16 @@ init_eh (void)
   sjlj_fc_jbuf_ofs
 	= (tree_to_uhwi (DECL_FIELD_OFFSET (f_jbuf))
 	   + tree_to_uhwi (DECL_FIELD_BIT_OFFSET (f_jbuf)) / BITS_PER_UNIT);
+
+#ifdef DONT_USE_BUILTIN_SETJMP
+  tmp = build_function_type_list (integer_type_node, TREE_TYPE (f_jbuf),
+  NULL);
+  setjmp_fn = build_decl (BUILTINS_LOCATION, FUNCTION_DECL,
+			  get_identifier ("setjmp"), tmp);
+  TREE_PUBLIC (setjmp_fn) = 1;
+  DECL_EXTERNAL (setjmp_fn) = 1;
+  DECL_ASSEMBLER_NAME (setjmp_fn);
+#endif
 }
 }
 
@@ -1176,8 +1188,7 @@ sjlj_emit_function_enter (rtx_code_label
   addr = convert_memory_address (ptr_mode, addr);
   tree addr_tree = make_tree (ptr_type_node, addr);
 
-  tree fn = builtin_decl_implicit (BUILT_IN_SETJMP);
-  tree call_expr = build_call_expr (fn, 1, addr_tree);
+  tree call_expr = build_call_expr (setjmp_fn, 1, addr_tree);
   rtx x = expand_call (call_expr, NULL_RTX, false);
 
   emit_cmp_and_jump_insns (x, const0_rtx, NE, 0,


Re: [PATCH] Add a warning for invalid function casts

2017-10-09 Thread Bernd Edlinger
On 10/09/17 20:34, Martin Sebor wrote:
> On 10/09/2017 11:50 AM, Bernd Edlinger wrote:
>> On 10/09/17 18:44, Martin Sebor wrote:
>>> On 10/07/2017 10:48 AM, Bernd Edlinger wrote:
 Hi!

 I think I have now something useful, it has a few more heuristics
 added, to reduce the number of false-positives so that it
 is able to find real bugs, for instance in openssl it triggers
 at a function cast which has already a TODO on it.

 The heuristics are:
 - handle void (*)(void) as a wild-card function type.
 - ignore volatile, const qualifiers on parameters/return.
 - handle any pointers as equivalent.
 - handle integral types, enums, and booleans of same precision
    and signedness as equivalent.
 - stop parameter validation at the first "...".
>>>
>>> These sound quite reasonable to me.  I have a reservation about
>>> just one of them, and some comments about other aspects of the
>>> warning.  Sorry if this seems like a lot.  I'm hoping you'll
>>> find the feedback constructive.
>>>
>>> I don't think using void(*)(void) to suppress the warning is
>>> a robust solution because it's not safe to call a function that
>>> takes arguments through such a pointer (especially not if one
>>> or more of the arguments is a pointer).  Depending on the ABI,
>>> calling a function that expects arguments with none could also
>>> mess up the stack as the callee may pop arguments that were
>>> never passed to it.
>>>
>>
>> This is of course only a heuristic, and if there is no warning
>> that does not mean any guarantee that there can't be a problem
>> at runtime.  The heuristic is only meant to separate the
>> bad from the very bad type-cast.  In my personal opinion there
>> is not a single good type cast.
> 
> I agree.  Since the warning uses one kind of a cast as an escape
> mechanism from the checking it should be one whose result can
> the most likely be used to call the function without undefined
> behavior.
> 
> Since it's possible to call any function through a pointer to
> a function with no arguments (simply by providing arguments of
> matching types) it's a reasonable candidate.
> 
> On the other hand, since it is not safe to call an arbitrary
> function through void (*)(void), it's not as good a candidate.
> 
> Another reason why I think a protoype-less function is a good
> choice is because the alias and ifunc attributes already use it
> as an escape mechanism from their type incompatibility warning.
> 

I know of pre-existing code-bases where a type-cast to type:
void (*) (void);

.. is already used as a generic function pointer: libffi and
libgo, I would not want to break these.

Actually when I have a type:
X (*) (...);

I would like to make sure that the warning checks that
only functions returning X are assigned.

and for X (*) (Y, );

I would like to check that anything returning X with
first argument of type Y is assigned.

There are code bases where such a scheme is used.
For instance one that I myself maintain: the OPC/UA AnsiC Stack,
where I have this type definition:

typedef OpcUa_StatusCode (OpcUa_PfnInvokeService)(OpcUa_Endpoint 
hEndpoint, ...);

And this plays well together with this warning, because only
functions are assigned that match up to the ...);
Afterwards this pointer is cast back to the original signature,
so everything is perfectly fine.

Regarding the cast from pointer to member to function, I see also a
warning without -Wpedantic:
Warnung: converting from »void (S::*)(int*)« to »void (*)(int*)« 
[-Wpmf-conversions]
F *pf = (F*)::foo;
^~~

And this one is even default-enabled, so I think that should be
more than sufficient.

I also changed the heuristic, so that your example with the enum should
now work.  I did not add it to the test case, because it would
break with -fshort-enums :(

Attached I have an updated patch that extends this warning to the
pointer-to-member function cast, and relaxes the heuristic on the
benign integral type differences a bit further.


Is it OK for trunk after bootstrap and reg-testing?


Thanks
Bernd.
gcc:
2017-10-06  Bernd Edlinger  

* doc/invoke.texi: Document -Wcast-function-type.
* recog.h (stored_funcptr): Change signature.
* tree-dump.c (dump_node): Avoid warning.
* typed-splay-tree.h (typed_splay_tree): Avoid warning.

libcpp:
2017-10-06  Bernd Edlinger  

* internal.h (maybe_print_line): Change signature.

c-family:
2017-10-06  Bernd Edlinger  

* c.opt (Wcast-function-type): New warning option.
* c-lex.c (get_fileinfo): Avoid warning.
* c-ppoutput.c (scan_translation_unit_directives_only): Remove cast.

c:
2017-10-06  Bernd Edlinger  

* c-typeck.c (c_abi_equiv_type_p, c_safe_function_type_cast_p): New.
(build_c_cast): Implement -Wcast_function_type.

cp:
2017-10-06  Bernd 

Re: [PATCH][mingw] Enable colorized diagnostics

2017-10-09 Thread Manuel López-Ibáñez

On 08/10/17 12:39, Liu Hao wrote:

On 2017/9/28 4:09, Joseph Myers wrote:

On Thu, 28 Sep 2017, Liu Hao wrote:


Colorized diagnostics used to be disabled for MinGW targets (on which
the macro `_WIN32` is defined), and this patch enables it.


I'd hope this is all to do with MinGW host, and nothing to do with the
target.


Ping? Are there any more opinions about this?


For what is worth, the color output of GCC comes originally from grep, and grep 
does have code for colorizing in Windows: 
http://git.savannah.gnu.org/cgit/grep.git/tree/lib


and there are significant differences with this patch. For once,

  /* $TERM is not normally defined on DOS/Windows, so don't require
 it for highlighting.  But some programs, like Emacs, do define
 it when running Grep as a subprocess, so make sure they don't
 set TERM=dumb.  */
  char const *t = getenv ("TERM");
  return ! (t && strcmp (t, "dumb") == 0);

and they don't need a custom fputs() because their strategy is slightly 
different: They only override colorize_start (print_start_colorize) and 
colorize_stop (print_end_colorize) and convert ANSI sequences to W32 sequences 
on the fly. Thus, we wouldn't need to touch pretty-printer.c and all changes 
will be restricted to diagnostic-color.c (which could be split into -posix.c 
and -w32.c like grep does and be moved into host-specific config/ subdir).


Even if the host-specific part is not done, I honestly think it is a good idea 
to match grep's code as much as possible since we may want to merge bugfixes 
between the two and eventually this code may end up in gnulib. Moreover, if 
somebody else implemented color output for another OS in grep, it would be very 
easy to transplant it to GCC (or viceversa) if the API remains close.


Cheers,

Manuel.



Re: [PATCH] Enable ifunc attribute by default for ARM GNU/Linux

2017-10-09 Thread Joseph Myers
On Mon, 9 Oct 2017, Adhemerval Zanella wrote:

>  *-*-linux*)
>   case ${target} in
> - aarch64*-* | i[34567]86-* | powerpc*-* | s390*-* | sparc*-* | x86_64-*)
> + aarch64*-* | i[34567]86-* | powerpc*-* | s390*-* | sparc*-* | x86_64-* 
> | arm*-*)

I think the cases here are meant to be in alphabetical order.

-- 
Joseph S. Myers
jos...@codesourcery.com


Re: [C++ PATCH] hash-table for extern-c fns.

2017-10-09 Thread Nathan Sidwell

On 10/09/2017 11:57 AM, Jason Merrill wrote:

On Fri, Oct 6, 2017 at 10:18 AM, Nathan Sidwell  wrote:

This patch converts the extern "C" function map to use a hash table, in the
same way as I've just changed namespace bindings.



Hmm, why do we only check extern "C" conflicts for functions?


I suspect a bug.  I noticed it as existing behaviour and was puzzled the first 
time around rearranging this code, but didn't want to get distracted from the 
big picture.


nathan

--
Nathan Sidwell


Re: [PATCH, rs6000] testcase coverage for vec_cmp builtins

2017-10-09 Thread Segher Boessenkool
On Mon, Oct 09, 2017 at 03:20:46PM -0500, Will Schmidt wrote:
> Add testcase coverage for the vec_cmp builtins.
> 
> Tested on P6 and newer.   OK for trunk? 


That looks fine.  Okay.  Thanks!


Segher


> [testsuite]
>   * gcc.target/powerpc/fold-vec-cmp-char.c: New.
>   * gcc.target/powerpc/fold-vec-cmp-double.c: New.
>   * gcc.target/powerpc/fold-vec-cmp-float.c: New.
>   * gcc.target/powerpc/fold-vec-cmp-int.c: New.
>   * gcc.target/powerpc/fold-vec-cmp-longlong.c: New.
>   * gcc.target/powerpc/fold-vec-cmp-short.c: New.


Re: [PATCH, rs6000] testcase coverage for vec_splat_uX

2017-10-09 Thread Segher Boessenkool
On Mon, Oct 09, 2017 at 03:18:26PM -0500, Will Schmidt wrote:
> Add testcase coverage for vec_splat_{u8,s8,u16,s16,u32,s32} built-ins.

> [testsuite]
> 
> |---* gcc.target/powerpc/fold-vec-splat-16.c: New
> |---* gcc.target/powerpc/fold-vec-splat-32.c: New.
> |---* gcc.target/powerpc/fold-vec-splat-8.c: New.

That look fine, please commit.  Thanks!


Segher


Re: [PATCH, rs6000] Testcase coverage for vec_splats

2017-10-09 Thread Segher Boessenkool
Hi Will,

On Mon, Oct 09, 2017 at 03:15:56PM -0500, Will Schmidt wrote:
> +/* { dg-final { scan-assembler-times "xscvdpspn|xscvdpsp" 1 } } */
> +/* { dg-final { scan-assembler-times "vspltw|xxspltw" 1 } } */

The second of these (xscvdpsp) will match whenever the first (xscvdpspn)
does.  Maybe you should use something like {\mxscvdpspn?\M} ?

Okay with that fixed.  Thanks!


Segher


[patch, libfortran] Fix EXECUTE_COMMAND_LINE error return

2017-10-09 Thread Thomas Koenig

Hello world,

currently, EXECUTE_COMMAND_LINE aborts the program if the called program
is not found, if cmdstat is present, but cmdmsg isn't. This is a 6/7/8
regression.

This patch fixes the issue by simply removing the erronous call to
runtime_error.

Regression-tested.  OK for all affected branches?

Regards

Thomas

2017-10-10  Thomas Koenig  

PR libfortran/82233
* intrinsics/execute_command_line.c (execute_command_line):
No call to runtime_error if cmdstat is present.

2017-10-10  Thomas Koenig  

PR libfortran/82233
* gfortran.dg/execute_command_line_3.f90: New test.
Index: intrinsics/execute_command_line.c
===
--- intrinsics/execute_command_line.c	(Revision 253525)
+++ intrinsics/execute_command_line.c	(Arbeitskopie)
@@ -125,15 +125,9 @@ execute_command_line (const char *command, bool wa
   free (cmd);
 
   /* Now copy back to the Fortran string if needed.  */
-  if (cmdstat && *cmdstat > EXEC_NOERROR)
-{
-  if (cmdmsg)
-	fstrcpy (cmdmsg, cmdmsg_len, cmdmsg_values[*cmdstat],
+  if (cmdstat && *cmdstat > EXEC_NOERROR && cmdmsg)
+fstrcpy (cmdmsg, cmdmsg_len, cmdmsg_values[*cmdstat],
 		strlen (cmdmsg_values[*cmdstat]));
-  else
-	runtime_error ("Failure in EXECUTE_COMMAND_LINE: %s",
-		   cmdmsg_values[*cmdstat]);
-}
 }
 
 
! { dg-do  run }
! PR 82233 - there were program aborts for some of these commands.
! Original test case by Urban Jost.
program boom
implicit none
integer   :: i,j 
character(len=256):: msg
character(len=:), allocatable :: command
   command='notthere'
   msg='' ! seems to only be defined if exitstatus.ne.0
   ! ok -- these work
   call execute_command_line(command , wait=.false., exitstat=i, cmdstat=j, cmdmsg=msg)
   if (j /= 0 .or. msg /= '') call abort
   call execute_command_line(command ,   exitstat=i, cmdstat=j, cmdmsg=msg )
   if (j /= 3 .or. msg /= "Invalid command line" ) call abort
   msg = ''
   call execute_command_line(command , wait=.false., exitstat=i,cmdmsg=msg )
   print *,msg
   if (msg /= '') call abort
   call execute_command_line(command ,   exitstat=i, cmdstat=j )
   if (j /= 3) call abort
   call execute_command_line(command , wait=.false., exitstat=i)

end program boom


[PATCH, rs6000] fix-up int128 fold vector multiply tests

2017-10-09 Thread Will Schmidt
Hi

[PATCH, rs6000] fix-up int128 fold vector multiply tests
 
Fix up a few issues with the tests.
- add -O2 to int128-p8 test, and firm up the -mcpu options
- update the set of expected instructions for the int128-p9 test.
- replace the float128_hw requirement with power8_vector_ok
for the int128-p9 test.

sniff-tested P6 and newer.
OK for trunk?
Thanks,
-Will

2017-10-09  Will Schmidt 
* gcc.target/powerpc/fold-vec-mult-int128-p8.c: Update options
* gcc.target/powerpc/fold-vec-mult-int128-p9.c: Update expected
instruction list.

diff --git a/gcc/testsuite/gcc.target/powerpc/fold-vec-mult-int128-p8.c 
b/gcc/testsuite/gcc.target/powerpc/fold-vec-mult-int128-p8.c
index 97d6b945..5ced2cd 100644
--- a/gcc/testsuite/gcc.target/powerpc/fold-vec-mult-int128-p8.c
+++ b/gcc/testsuite/gcc.target/powerpc/fold-vec-mult-int128-p8.c
@@ -3,11 +3,12 @@
 
 /* { dg-do compile } */
 /* { dg-require-effective-target powerpc_p8vector_ok } */
 /* { dg-require-effective-target int128 } */
 /* { dg-require-effective-target lp64 } */
-/* { dg-options "-mpower8-vector" } */
+/* { dg-skip-if "do not override -mcpu" { powerpc*-*-* } { "-mcpu=*" } { 
"-mcpu=power8" } } */
+/* { dg-options "-mpower8-vector -mcpu=power8 -O2" } */
 /* { dg-additional-options "-maix64" { target powerpc-ibm-aix* } } */
 
 #include "altivec.h"
 
 vector signed __int128
@@ -20,7 +21,7 @@ vector unsigned __int128
 test2 (vector unsigned __int128 x, vector unsigned __int128 y)
 {
   return vec_mul (x, y);
 }
 
-/* { dg-final { scan-assembler-times "\[ \t\]mulld " 6 } } */
+/* { dg-final { scan-assembler-times "\[ \t\]mulld" 6 } } */
 /* { dg-final { scan-assembler-times "\[ \t\]mulhdu" 2 } } */
diff --git a/gcc/testsuite/gcc.target/powerpc/fold-vec-mult-int128-p9.c 
b/gcc/testsuite/gcc.target/powerpc/fold-vec-mult-int128-p9.c
index e81ea5f..a226ae0 100644
--- a/gcc/testsuite/gcc.target/powerpc/fold-vec-mult-int128-p9.c
+++ b/gcc/testsuite/gcc.target/powerpc/fold-vec-mult-int128-p9.c
@@ -1,10 +1,10 @@
 /* Verify that overloaded built-ins for vec_mul with __int128
inputs produce the right results.  */
 
 /* { dg-do compile } */
-/* { dg-require-effective-target powerpc_float128_hw_ok } */
+/* { dg-require-effective-target powerpc_p8vector_ok } */
 /* { dg-require-effective-target int128 } */
 /* { dg-skip-if "do not override -mcpu" { powerpc*-*-* } { "-mcpu=*" } { 
"-mcpu=power9" } } */
 /* { dg-options "-mcpu=power9 -O2" } */
 /* { dg-additional-options "-maix64" { target powerpc-ibm-aix* } } */
 
@@ -20,6 +20,7 @@ vector unsigned __int128
 test2 (vector unsigned __int128 x, vector unsigned __int128 y)
 {
   return vec_mul (x, y);
 }
 
-/* { dg-final { scan-assembler-times "\[ \t\]xsmulqp" 2 } } */
+/* { dg-final { scan-assembler-times "\[ \t\]mulld" 4 } } */
+/* { dg-final { scan-assembler-times "\[ \t\]mulhdu" 2 } } */




[Ada] Small optimizations in Sem_Type.Covers

2017-10-09 Thread Pierre-Marie de Rodat
The Sem_Type.Covers predicate is by far the topmost subprogram in the profile
of unoptimized compilations in Ada.  This change contains a series of small
optimizations that save about 2% of the instruction count on x86-64:

  1. Inline 3 more predicates from einfo,
  2. Simplify a convoluted condition dealing with Standard_Void_Type,
  3. Move up cheap tests on T2 so that they are executed before more costly
 tests on T1,
  4. Move the Is_Private_Type test from Full_View_Covers to the main body
 and remove tests on base types that were already done in the main body.

The main saving stems from 4. because tests on In_Instance are now guarded
by the Is_Private_Type predicate and In_Instance is quite costly since it
climbs the scope chain on each invocation.

No functional changes.

Tested on x86_64-pc-linux-gnu, committed on trunk

2017-10-09  Eric Botcazou  

* einfo.ads (Is_Boolean_Type): Add pragma Inline.
(Is_Entity_Name): Likewise.
(Is_String_Type): Likewise.
* sem_type.adb (Full_View_Covers): Do not test Is_Private_Type here
and remove useless comparisons on the base types.
(Covers): Use simple tests for Standard_Void_Type.  Move up cheap tests
on T2.  Always test Is_Private_Type before Full_View_Covers.

Index: einfo.ads
===
--- einfo.ads   (revision 253559)
+++ einfo.ads   (working copy)
@@ -9470,9 +9470,12 @@
 
pragma Inline (Base_Type);
pragma Inline (Is_Base_Type);
+   pragma Inline (Is_Boolean_Type);
pragma Inline (Is_Controlled);
+   pragma Inline (Is_Entity_Name);
pragma Inline (Is_Package_Or_Generic_Package);
pragma Inline (Is_Packed_Array);
+   pragma Inline (Is_String_Type);
pragma Inline (Is_Subprogram_Or_Generic_Subprogram);
pragma Inline (Is_Volatile);
pragma Inline (Is_Wrapper_Package);
Index: sem_type.adb
===
--- sem_type.adb(revision 253546)
+++ sem_type.adb(working copy)
@@ -761,15 +761,19 @@
 
   function Full_View_Covers (Typ1, Typ2 : Entity_Id) return Boolean is
   begin
- return
-   Is_Private_Type (Typ1)
- and then
-  ((Present (Full_View (Typ1))
- and then Covers (Full_View (Typ1), Typ2))
-or else (Present (Underlying_Full_View (Typ1))
-  and then Covers (Underlying_Full_View (Typ1), Typ2))
-or else Base_Type (Typ1) = Typ2
-or else Base_Type (Typ2) = Typ1);
+ if Present (Full_View (Typ1))
+   and then Covers (Full_View (Typ1), Typ2)
+ then
+return True;
+
+ elsif Present (Underlying_Full_View (Typ1))
+   and then Covers (Underlying_Full_View (Typ1), Typ2)
+ then
+return True;
+
+ else
+return False;
+ end if;
   end Full_View_Covers;
 
   -
@@ -825,7 +829,7 @@
   --  Standard_Void_Type is a special entity that has some, but not all,
   --  properties of types.
 
-  if (T1 = Standard_Void_Type) /= (T2 = Standard_Void_Type) then
+  if T1 = Standard_Void_Type or else T2 = Standard_Void_Type then
  return False;
   end if;
 
@@ -892,8 +896,8 @@
 or else (T2 = Universal_Realand then Is_Real_Type (T1))
 or else (T2 = Universal_Fixed   and then Is_Fixed_Point_Type (T1))
 or else (T2 = Any_Fixed and then Is_Fixed_Point_Type (T1))
+or else (T2 = Any_Character and then Is_Character_Type (T1))
 or else (T2 = Any_Stringand then Is_String_Type (T1))
-or else (T2 = Any_Character and then Is_Character_Type (T1))
 or else (T2 = Any_Accessand then Is_Access_Type (T1))
   then
  return True;
@@ -916,9 +920,9 @@
   --  task_type or protected_type that implements the interface.
 
   elsif Ada_Version >= Ada_2005
+and then Is_Concurrent_Type (T2)
 and then Is_Class_Wide_Type (T1)
 and then Is_Interface (Etype (T1))
-and then Is_Concurrent_Type (T2)
 and then Interface_Present_In_Ancestor
(Typ => BT2, Iface => Etype (T1))
   then
@@ -928,9 +932,9 @@
   --  object T2 implementing T1.
 
   elsif Ada_Version >= Ada_2005
+and then Is_Tagged_Type (T2)
 and then Is_Class_Wide_Type (T1)
 and then Is_Interface (Etype (T1))
-and then Is_Tagged_Type (T2)
   then
  if Interface_Present_In_Ancestor (Typ   => T2,
Iface => Etype (T1))
@@ -1183,19 +1187,16 @@
   --  whether a partial and a full view match. Verify that types are
   --  legal, to prevent cascaded errors.
 
-  elsif In_Instance
-and then (Full_View_Covers (T1, T2) or else Full_View_Covers (T2, T1))
-  then
- 

[Ada] Missing error on implicit copy of limited value in expression function

2017-10-09 Thread Pierre-Marie de Rodat
This patch corrects an omission on the legality check of an allocator whose
expression is of a limited type, when the allocator is the expression of an
expression function.

Compiling t3.adb must yield:

  t3.adb:4:13: warning: not dispatching (must be defined in a package spec)
  t3.adb:5:07: initialization not allowed for limited types

---
procedure T3 is
   type X_T is tagged limited null record;
   type A_T is access X_T'Class;
   function Clone (X : X_T) return A_T is
 (new X_T'Class' (X_T'Class (X)));
   X : X_T;
   A : A_T := Clone (X);
begin
   null;
end T3;

Tested on x86_64-pc-linux-gnu, committed on trunk

2017-10-09  Ed Schonberg  

* sem_res.adb (Resolve_Allocator): Reject properly an allocator that
attempts to copy a limited value, when the allocator is the expression
in an expression function.

Index: sem_res.adb
===
--- sem_res.adb (revision 253563)
+++ sem_res.adb (working copy)
@@ -4834,10 +4834,18 @@
  --  are explicitly marked as coming from source but do not need to be
  --  checked for limited initialization. To exclude this case, ensure
  --  that the parent of the allocator is a source node.
+ --  The return statement constructed for an Expression_Function does
+ --  not come from source but requires a limited check.
 
  if Is_Limited_Type (Etype (E))
and then Comes_From_Source (N)
-   and then Comes_From_Source (Parent (N))
+   and then
+ (Comes_From_Source (Parent (N))
+   or else
+ (Ekind (Current_Scope) = E_Function
+   and then Nkind
+ (Original_Node (Unit_Declaration_Node (Current_Scope)))
+   = N_Expression_Function))
and then not In_Instance_Body
  then
 if not OK_For_Limited_Init (Etype (E), Expression (E)) then


[Ada] Update the categorization of N_Call_Marker nodes

2017-10-09 Thread Pierre-Marie de Rodat
This patch update the categorization of node N_Call_Marker's fields. No change
in behaviour, no need for a test.

Tested on x86_64-pc-linux-gnu, committed on trunk

2017-10-09  Hristian Kirtchev  

* sinfo.ads: Update table Is_Syntactic_Field to reflect the nature of
semantic field Target of node N_Call_Marker.

Index: exp_aggr.adb
===
--- exp_aggr.adb(revision 253567)
+++ exp_aggr.adb(working copy)
@@ -4125,25 +4125,6 @@
-- Convert_To_Assignments --

 
-   function Is_Build_In_Place_Aggregate_Return (N : Node_Id) return Boolean is
-  P : Node_Id := Parent (N);
-   begin
-  while Nkind (P) = N_Qualified_Expression loop
- P := Parent (P);
-  end loop;
-
-  if Nkind (P) = N_Simple_Return_Statement then
- null;
-  elsif Nkind (Parent (P)) = N_Extended_Return_Statement then
- P := Parent (P);
-  else
- return False;
-  end if;
-
-  return Is_Build_In_Place_Function
-(Return_Applies_To (Return_Statement_Entity (P)));
-   end Is_Build_In_Place_Aggregate_Return;
-
procedure Convert_To_Assignments (N : Node_Id; Typ : Entity_Id) is
   Loc  : constant Source_Ptr := Sloc (N);
   T: Entity_Id;
@@ -4176,8 +4157,9 @@
 Unc_Decl :=
   not Is_Entity_Name (Object_Definition (Parent_Node))
 or else (Nkind (N) = N_Aggregate
-   and then Has_Discriminants
- (Entity (Object_Definition (Parent_Node
+  and then
+Has_Discriminants
+  (Entity (Object_Definition (Parent_Node
 or else Is_Class_Wide_Type
   (Entity (Object_Definition (Parent_Node)));
  end if;
@@ -6671,8 +6653,8 @@
--  individual assignments to the given components.
 
procedure Expand_N_Extension_Aggregate (N : Node_Id) is
+  A   : constant Node_Id:= Ancestor_Part (N);
   Loc : constant Source_Ptr := Sloc (N);
-  A   : constant Node_Id:= Ancestor_Part (N);
   Typ : constant Entity_Id  := Etype (N);
 
begin
@@ -7476,6 +7458,33 @@
   return False;
end Has_Default_Init_Comps;
 
+   
+   -- Is_Build_In_Place_Aggregate_Return --
+   
+
+   function Is_Build_In_Place_Aggregate_Return (N : Node_Id) return Boolean is
+  P : Node_Id := Parent (N);
+
+   begin
+  while Nkind (P) = N_Qualified_Expression loop
+ P := Parent (P);
+  end loop;
+
+  if Nkind (P) = N_Simple_Return_Statement then
+ null;
+
+  elsif Nkind (Parent (P)) = N_Extended_Return_Statement then
+ P := Parent (P);
+
+  else
+ return False;
+  end if;
+
+  return
+Is_Build_In_Place_Function
+  (Return_Applies_To (Return_Statement_Entity (P)));
+   end Is_Build_In_Place_Aggregate_Return;
+
--
-- Is_Delayed_Aggregate --
--
Index: exp_ch3.adb
===
--- exp_ch3.adb (revision 253567)
+++ exp_ch3.adb (working copy)
@@ -1712,7 +1712,8 @@
   Set_Tag   : Entity_Id := Empty;
 
   function Build_Assignment
-(Id : Entity_Id; Default : Node_Id) return List_Id;
+(Id  : Entity_Id;
+ Default : Node_Id) return List_Id;
   --  Build an assignment statement that assigns the default expression to
   --  its corresponding record component if defined. The left-hand side of
   --  the assignment is marked Assignment_OK so that initialization of
@@ -1785,10 +1786,11 @@
   --
 
   function Build_Assignment
-(Id : Entity_Id; Default : Node_Id) return List_Id
+(Id  : Entity_Id;
+ Default : Node_Id) return List_Id
   is
  Default_Loc : constant Source_Ptr := Sloc (Default);
- Typ   : constant Entity_Id := Underlying_Type (Etype (Id));
+ Typ : constant Entity_Id  := Underlying_Type (Etype (Id));
 
  Adj_Call : Node_Id;
  Exp  : Node_Id   := Default;
@@ -1871,7 +1873,7 @@
 
  if Kind = N_Attribute_Reference
and then Nam_In (Attribute_Name (Default), Name_Unchecked_Access,
-Name_Unrestricted_Access)
+  Name_Unrestricted_Access)
and then Is_Entity_Name (Prefix (Default))
and then Is_Type (Entity (Prefix (Default)))
and then Entity (Prefix (Default)) = Rec_Type
@@ -1915,9 +1917,8 @@
 Expression =>
   Unchecked_Convert_To (RTE (RE_Tag),
 New_Occurrence_Of
-  (Node
-

[Ada] Crash on potential access-before-elaboration in ZFP

2017-10-09 Thread Pierre-Marie de Rodat
This patch update the mechanism which retrieves the enclosing scope of a node
to account for blocks produces by exception handler expansion. These blocks are
not scoping constructs and should not be considered. As a result, an access-
before-elaboration check will no longer cause a crash on ZFP.


-- Source --


--  pack.ads

package Pack is
   procedure Force_Body;
end Pack;

--  pack.adb

with Ada.Text_IO; use Ada.Text_IO;

package body Pack is
   procedure Force_Body is begin null; end Force_Body;

   package Nested is
  function Func (Val : Integer) return Integer;
   end Nested;

   package body Nested is
  procedure Proc is
 Val : Integer;

  begin
 Val := Func (1);
 Put_Line ("ERROR: Program_Error not raised");
  exception
 when Program_Error =>
Put_Line ("OK");
 when others =>
Put_Line ("ERROR: unexpected exception");
  end Proc;

  package Elaborator is
  end Elaborator;

  package body Elaborator is
  begin
 Proc;
  end Elaborator;

  function Func (Val : Integer) return Integer is
  begin
 return Val + 1;
  end Func;
   end Nested;
end Pack;

-
-- Compilation --
-

$ gcc -c -gnatws --RTS=zfp pack.adb

Tested on x86_64-pc-linux-gnu, committed on trunk

2017-10-09  Hristian Kirtchev  

* sem_unit.adb (Find_Enclosing_Scope): Do not treat a block statement
as a scoping construct when it is byproduct of exception handling.

Index: sem_util.adb
===
--- sem_util.adb(revision 253567)
+++ sem_util.adb(working copy)
@@ -7929,13 +7929,21 @@
 
 --  Special cases
 
---  Blocks, loops, and return statements have artificial scopes
+--  Blocks carry either a source or an internally-generated scope,
+--  unless the block is a byproduct of exception handling.
 
-when N_Block_Statement
-   | N_Loop_Statement
-=>
+when N_Block_Statement =>
+   if not Exception_Junk (Par) then
+  return Entity (Identifier (Par));
+   end if;
+
+--  Loops carry an internally-generated scope
+
+when N_Loop_Statement =>
return Entity (Identifier (Par));
 
+--  Extended return statements carry an internally-generated scope
+
 when N_Extended_Return_Statement =>
return Return_Statement_Entity (Par);
 
@@ -19511,13 +19519,13 @@
  N := Next (Actual_Id);
 
  if Nkind (N) = N_Parameter_Association then
+
 --  In case of a build-in-place call, the call will no longer be a
 --  call; it will have been rewritten.
 
-if Nkind_In (Parent (Actual_Id),
- N_Entry_Call_Statement,
- N_Function_Call,
- N_Procedure_Call_Statement)
+if Nkind_In (Parent (Actual_Id), N_Entry_Call_Statement,
+ N_Function_Call,
+ N_Procedure_Call_Statement)
 then
return First_Named_Actual (Parent (Actual_Id));
 else
@@ -23257,16 +23265,15 @@
  return "unknown subprogram";
   end if;
 
+  --  If the subprogram is a child unit, use its simple name to start the
+  --  construction of the fully qualified name.
+
   if Nkind (Ent) = N_Defining_Program_Unit_Name then
-
- --  If the subprogram is a child unit, use its simple name to
- --  start the construction of the fully qualified name.
-
  Append_Entity_Name (Buf, Defining_Identifier (Ent));
-
   else
  Append_Entity_Name (Buf, Ent);
   end if;
+
   return +Buf;
end Subprogram_Name;
 


[PATCH, rs6000] Correct unaligned_load vector cost for Power9

2017-10-09 Thread Pat Haugen
Power9 has efficient unaligned load insns. The following patch fixes the
cost to reflect that. There was no similar code for the unaligned_store
case.  Bootstrap/regtest on powerpc64le-linux with no new regressions.
Ok for trunk?

-Pat


2017-10-09  Pat Haugen  

* config/rs6000/power9.c (rs6000_builtin_vectorization_cost): Remove
TARGET_P9_VECTOR code for unaligned_load case.


Index: gcc/config/rs6000/rs6000.c
===
--- gcc/config/rs6000/rs6000.c  (revision 253547)
+++ gcc/config/rs6000/rs6000.c  (working copy)
@@ -5438,9 +5438,6 @@ rs6000_builtin_vectorization_cost (enum
 return 3;

   case unaligned_load:
-   if (TARGET_P9_VECTOR)
- return 3;
-
if (TARGET_EFFICIENT_UNALIGNED_VSX)
  return 1;



[Ada] Crash on child unit name with -gnatdJ

2017-10-09 Thread Pierre-Marie de Rodat
When the debugging switch -gnatdJ is present, warning messages include the
name of the unit within which the warning is generated. This patch fixes
a crash in the compiler when a warning appears within a child unit.

The command

  gcc -c -gnatdJ test-a.ads

must yield; 

test-a.ads:6:17: warning: Test.A: unused variable "X"

---
package Test is
end Test;
---
with Test;

package Test.A is

function P return Natural is (3) with
Pre => (for all X in Natural => True);

end Test.A;

Tested on x86_64-pc-linux-gnu, committed on trunk

2017-10-09  Ed Schonberg  

* sem_util.adb (Subprogram_Name): If this is a child unit, use the name
of the Defining_Program_Unit_Name, which is an identifier, in order to
construct the string for the fully qualified name.

Index: sem_util.adb
===
--- sem_util.adb(revision 253559)
+++ sem_util.adb(working copy)
@@ -23257,7 +23257,16 @@
  return "unknown subprogram";
   end if;
 
-  Append_Entity_Name (Buf, Ent);
+  if Nkind (Ent) = N_Defining_Program_Unit_Name then
+
+ --  If the subprogram is a child unit, use its simple name to
+ --  start the construction of the fully qualified name.
+
+ Append_Entity_Name (Buf, Defining_Identifier (Ent));
+
+  else
+ Append_Entity_Name (Buf, Ent);
+  end if;
   return +Buf;
end Subprogram_Name;
 


[Ada] Check elaboration requirement for SPARK in the static model

2017-10-09 Thread Pierre-Marie de Rodat
This patch ensures that the Elaborate[_All] requirement imposed on the context
of a unit in SPARK code is verified only when the static model is in effect.


-- Source --


--  server.ads

package Server with SPARK_Mode is
   function Read return Integer;
end Server;

--  server.adb

package body Server with SPARK_Mode is
   function Read return Integer is
   begin
  return 0;
   end Read;
end Server;

--  client.ads

package Client with SPARK_Mode is
   function Prf return Boolean;
end Client;

--  client.adb

with Server;

package body Client with SPARK_Mode is
   function Prf return Boolean is
   begin
  return Server.Read = 0;
   end Prf;
end Client;

-
-- Compilation --
-

$ gcc -c client.adb
$ gcc -c client.adb -gnatE

Tested on x86_64-pc-linux-gnu, committed on trunk

2017-10-09  Hristian Kirtchev  

* sem_elab.adb (Static_Elaboration_Checks): Elaboration requirements
are verified only in the static model.

Index: sem_elab.adb
===
--- sem_elab.adb(revision 253564)
+++ sem_elab.adb(working copy)
@@ -5516,12 +5516,18 @@
 
   Req_Met := False;
 
+  --  Elaboration requirements are verified only when the static model is
+  --  in effect because this diagnostic is graph-dependent.
+
+  if not Static_Elaboration_Checks then
+ return;
+
   --  If the target is within the main unit, either at the source level or
   --  through an instantiation, then there is no real requirement to meet
   --  because the main unit cannot force its own elaboration by means of an
   --  Elaborate[_All] pragma. Treat this case as valid coverage.
 
-  if In_Extended_Main_Code_Unit (Target_Id) then
+  elsif In_Extended_Main_Code_Unit (Target_Id) then
  Req_Met := True;
 
   --  Otherwise the target resides in an external unit


[Ada] Support for reverse iteration on formal containers

2017-10-09 Thread Pierre-Marie de Rodat
This patch adds support for reverse iterations over formal containers,
analogous to what is supported on arrays and predefined containers.

Executing:

  gnatmake -q foo
  foo

must yield;

 1 2 3 4 5 6 7 8 9 10
 10 9 8 7 6 5 4 3 2 1
 10 9 8 7 6 5 4 3 2 1

---
with Ada.Text_IO; use Ada.Text_IO;

procedure Foo is
   type Int_Range is record
  First, Last : Integer;
   end record
  with Iterable => (First => First,
Next => Next,
Previous => Previous,
Last => Last,
Has_Element => Has_Element,
Element => Element);

   function First (IR : Int_Range) return Integer is (IR.First);
   function Last (IR : Int_Range) return Integer is (IR.Last);
   function Next (IR : Int_Range; N : Integer) return Integer is (N + 1);
   function Previous (IR : Int_Range; N : Integer) return Integer is (N - 1);
   function Has_Element (IR : Int_Range; N : Integer) return Boolean is
 (N in IR.First ..IR.Last);
   function Element (IR : Int_Range; N : Integer) return Integer is (N);

   IR : Int_Range := (1, 10);
begin
   for I of IR loop
  Put (I'Img);
   end loop;
   New_Line;

   for I in reverse IR loop
  Put (I'Img);
   end loop;
   New_Line;

   for I of reverse IR loop
  Put (I'Img);
   end loop;
end Foo;

Tested on x86_64-pc-linux-gnu, committed on trunk

2017-10-09  Ed Schonberg  

* sem_ch5.adb (Analyze_Iterator_Specification,
Check_Reverse_Iteration): Check that the domain of iteration supports
reverse iteration when it is a formal container.  This requires the
presence of a Previous primitive in the Iterable aspect.
* sem_ch13.adb (Resolve_Iterable_Operation): Verify legality of
primitives Last and Previous to support reverse iteration over formal
containers.
(Validate_Iterable_Aspect): Add check for reverse iteration operations.
* exp_ch5.adb (Build_Formal_Container_Iteration): Add proper expansion
for reverse iteration using primitives Last and Previous in generated
loop.

Index: exp_ch5.adb
===
--- exp_ch5.adb (revision 253566)
+++ exp_ch5.adb (working copy)
@@ -178,14 +178,27 @@
   Loc  : constant Source_Ptr := Sloc (N);
   Stats: constant List_Id:= Statements (N);
   Typ  : constant Entity_Id  := Base_Type (Etype (Container));
-  First_Op : constant Entity_Id  :=
-   Get_Iterable_Type_Primitive (Typ, Name_First);
-  Next_Op  : constant Entity_Id  :=
-   Get_Iterable_Type_Primitive (Typ, Name_Next);
 
+  First_Op : Entity_Id;
+  Next_Op  : Entity_Id;
+
   Has_Element_Op : constant Entity_Id :=
Get_Iterable_Type_Primitive (Typ, Name_Has_Element);
begin
+  --  Use the proper set of primitives depending on the direction of
+  --  iteration. The legality of a reverse iteration has been checked
+  --  during analysis.
+
+  if Reverse_Present (Iterator_Specification (Iteration_Scheme (N))) then
+ First_Op := Get_Iterable_Type_Primitive (Typ, Name_Last);
+ Next_Op  := Get_Iterable_Type_Primitive (Typ, Name_Previous);
+
+  else
+ First_Op := Get_Iterable_Type_Primitive (Typ, Name_First);
+ Next_Op  := Get_Iterable_Type_Primitive (Typ, Name_Next);
+ null;
+  end if;
+
   --  Declaration for Cursor
 
   Init :=
@@ -198,7 +211,7 @@
   Parameter_Associations => New_List (
 Convert_To_Iterable_Type (Container, Loc;
 
-  --  Statement that advances cursor in loop
+  --  Statement that advances (in the right direction) cursor in loop
 
   Advance :=
 Make_Assignment_Statement (Loc,
Index: sem_ch13.adb
===
--- sem_ch13.adb(revision 253563)
+++ sem_ch13.adb(working copy)
@@ -13200,10 +13200,13 @@
 
  Ent := Entity (N);
  F1 := First_Formal (Ent);
- if Nam = Name_First then
 
---  First (Container) => Cursor
+ if Nam = Name_First
+   or else Nam = Name_Last
+ then
 
+--  First or Last (Container) => Cursor
+
 if Etype (Ent) /= Cursor then
Error_Msg_N ("primitive for First must yield a curosr", N);
 end if;
@@ -13221,6 +13224,19 @@
Error_Msg_N ("no match for Next iterable primitive", N);
 end if;
 
+ elsif Nam = Name_Previous then
+
+--  Previous (Container, Cursor) => Cursor
+
+F2 := Next_Formal (F1);
+
+if Etype (F2) /= Cursor
+  or else Etype (Ent) /= Cursor
+  or else Present (Next_Formal (F2))
+then
+   Error_Msg_N ("no match for Previous iterable primitive", N);
+end if;
+
   

[PATCH, rs6000] testcase coverage for vec_cmp builtins

2017-10-09 Thread Will Schmidt
Hi, 

Add testcase coverage for the vec_cmp builtins.

Tested on P6 and newer.   OK for trunk? 

Thanks,
-Will

[testsuite]
* gcc.target/powerpc/fold-vec-cmp-char.c: New.
* gcc.target/powerpc/fold-vec-cmp-double.c: New.
* gcc.target/powerpc/fold-vec-cmp-float.c: New.
* gcc.target/powerpc/fold-vec-cmp-int.c: New.
* gcc.target/powerpc/fold-vec-cmp-longlong.c: New.
* gcc.target/powerpc/fold-vec-cmp-short.c: New.



diff --git a/gcc/testsuite/gcc.target/powerpc/fold-vec-cmp-char.c 
b/gcc/testsuite/gcc.target/powerpc/fold-vec-cmp-char.c
new file mode 100644
index 000..3a1aa60
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/fold-vec-cmp-char.c
@@ -0,0 +1,86 @@
+/* Verify that overloaded built-ins for vec_cmp{eq,ge,gt,le,lt,ne} with
+   char inputs produce the right code.  */
+
+/* { dg-do compile } */
+/* { dg-require-effective-target powerpc_p8vector_ok } */
+/* { dg-options "-mpower8-vector -O2" } */
+
+#include 
+
+vector bool char
+test3_eq (vector signed char x, vector signed char y)
+{
+  return vec_cmpeq (x, y);
+}
+
+vector bool char
+test6_eq (vector unsigned char x, vector unsigned char y)
+{
+  return vec_cmpeq (x, y);
+}
+
+vector bool char
+test3_ge (vector signed char x, vector signed char y)
+{
+  return vec_cmpge (x, y);
+}
+
+vector bool char
+test6_ge (vector unsigned char x, vector unsigned char y)
+{
+  return vec_cmpge (x, y);
+}
+
+vector bool char
+test3_gt (vector signed char x, vector signed char y)
+{
+  return vec_cmpgt (x, y);
+}
+
+vector bool char
+test6_gt (vector unsigned char x, vector unsigned char y)
+{
+  return vec_cmpgt (x, y);
+}
+
+vector bool char
+test3_le (vector signed char x, vector signed char y)
+{
+  return vec_cmple (x, y);
+}
+
+vector bool char
+test6_le (vector unsigned char x, vector unsigned char y)
+{
+  return vec_cmple (x, y);
+}
+
+vector bool char
+test3_lt (vector signed char x, vector signed char y)
+{
+  return vec_cmplt (x, y);
+}
+
+vector bool char
+test6_lt (vector unsigned char x, vector unsigned char y)
+{
+  return vec_cmplt (x, y);
+}
+
+vector bool char
+test3_ne (vector signed char x, vector signed char y)
+{
+  return vec_cmpne (x, y);
+}
+
+vector bool char
+test6_ne (vector unsigned char x, vector unsigned char y)
+{
+  return vec_cmpne (x, y);
+}
+
+/* { dg-final { scan-assembler-times "vcmpequb" 4 } } */
+/* { dg-final { scan-assembler-times "vcmpgtsb" 4 } } */
+/* { dg-final { scan-assembler-times "vcmpgtub" 4 } } */
+/* { dg-final { scan-assembler-times "xxlnor" 6 } } */
+
diff --git a/gcc/testsuite/gcc.target/powerpc/fold-vec-cmp-double.c 
b/gcc/testsuite/gcc.target/powerpc/fold-vec-cmp-double.c
new file mode 100644
index 000..9d56862
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/fold-vec-cmp-double.c
@@ -0,0 +1,51 @@
+/* Verify that overloaded built-ins for vec_cmp with
+   double inputs for VSX produce the right code.  */
+
+/* { dg-do compile } */
+/* { dg-require-effective-target powerpc_vsx_ok } */
+/* { dg-options "-mvsx -O2" } */
+
+#include 
+
+vector bool long long
+test2_eq (vector double x, vector double y)
+{
+  return vec_cmpeq (x, y);
+}
+
+vector bool long long
+test2_ge (vector double x, vector double y)
+{
+  return vec_cmpge (x, y);
+}
+
+vector bool long long
+test2_gt (vector double x, vector double y)
+{
+  return vec_cmpgt (x, y);
+}
+
+vector bool long long
+test2_le (vector double x, vector double y)
+{
+  return vec_cmple (x, y);
+}
+
+vector bool long long
+test2_lt (vector double x, vector double y)
+{
+  return vec_cmplt (x, y);
+}
+
+   vector bool long long
+test2_ne (vector double x, vector double y)
+{
+  return vec_cmpne (x, y);
+}
+
+/* { dg-final { scan-assembler-times "xvcmpeqdp" 2 } } */
+/* { dg-final { scan-assembler-times "xvcmpgtdp" 2 } } */
+/* { dg-final { scan-assembler-times "xvcmpnedp" 0 } } */
+/* { dg-final { scan-assembler-times "xvcmpgedp" 2 } } */
+/* { dg-final { scan-assembler-times "fcmpu" 0 } } */
+
diff --git a/gcc/testsuite/gcc.target/powerpc/fold-vec-cmp-float.c 
b/gcc/testsuite/gcc.target/powerpc/fold-vec-cmp-float.c
new file mode 100644
index 000..b75250a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/fold-vec-cmp-float.c
@@ -0,0 +1,51 @@
+/* Verify that overloaded built-ins for vec_cmp with float
+   inputs for VSX produce the right code.  */
+
+/* { dg-do compile } */
+/* { dg-require-effective-target powerpc_vsx_ok } */
+/* { dg-options "-mvsx -O2" } */
+
+#include 
+
+vector bool int
+test1_eq (vector float x, vector float y)
+{
+  return vec_cmpeq (x, y);
+}
+
+vector bool int
+test1_ge (vector float x, vector float y)
+{
+  return vec_cmpge (x, y);
+}
+
+vector bool int
+test1_gt (vector float x, vector float y)
+{
+  return vec_cmpgt (x, y);
+}
+
+vector bool int
+test1_le (vector float x, vector float y)
+{
+  return vec_cmple (x, y);
+}
+
+vector bool int
+test1_lt (vector float x, vector float y)
+{
+  return vec_cmplt (x, y);
+}
+
+vector bool int
+test1_ne (vector float x, 

[Ada] Spurious warnings with dynamic elab checks

2017-10-09 Thread Pierre-Marie de Rodat
This patch classifies 'Access, variable assignments, and variable references as
static model-only scenarios because they are graph-dependent and do not produce
any checks. No need for a test.

Tested on x86_64-pc-linux-gnu, committed on trunk

2017-10-09  Hristian Kirtchev  

* sem_elab.adb (Is_Suitable_Access): This scenario is now only relevant
in the static model.
(Is_Suitable_Variable_Assignment): This scenario is now only relevant
in the static model.
(Is_Suitable_Variable_Reference): This scenario is now only relevant in
the static model.

Index: sem_elab.adb
===
--- sem_elab.adb(revision 253563)
+++ sem_elab.adb(working copy)
@@ -4995,11 +4995,27 @@
   Subp_Id : Entity_Id;
 
begin
-  if Nkind (N) /= N_Attribute_Reference then
+  --  This scenario is relevant only when the static model is in effect
+  --  because it is graph-dependent and does not involve any run-time
+  --  checks. Allowing it in the dynamic model would create confusing
+  --  noise.
+
+  if not Static_Elaboration_Checks then
  return False;
 
-  --  Internally-generated attributes are assumed to be ABE safe
+  --  Nothing to do when switch -gnatd.U (ignore 'Access) is in effect
 
+  elsif Debug_Flag_Dot_UU then
+ return False;
+
+  --  Nothing to do when the scenario is not an attribute reference
+
+  elsif Nkind (N) /= N_Attribute_Reference then
+ return False;
+
+  --  Nothing to do for internally-generated attributes because they are
+  --  assumed to be ABE safe.
+
   elsif not Comes_From_Source (N) then
  return False;
   end if;
@@ -5031,16 +5047,10 @@
 
   return
 
---  This particular scenario is relevant only in the static model when
---  switch -gnatd.U (ignore 'Access) is not in effect.
+--  The prefix must denote a source entry, operator, or subprogram
+--  which is not imported.
 
-Static_Elaboration_Checks
-  and then not Debug_Flag_Dot_UU
-
-  --  The prefix must denote an entry, operator, or subprogram which is
-  --  not imported.
-
-  and then Comes_From_Source (Subp_Id)
+Comes_From_Source (Subp_Id)
   and then Is_Subprogram_Or_Entry (Subp_Id)
   and then not Is_Bodiless_Subprogram (Subp_Id)
 
@@ -5109,11 +5119,22 @@
   Var_Unit_Id : Entity_Id;
 
begin
-  if Nkind (N) /= N_Assignment_Statement then
+  --  This scenario is relevant only when the static model is in effect
+  --  because it is graph-dependent and does not involve any run-time
+  --  checks. Allowing it in the dynamic model would create confusing
+  --  noise.
+
+  if not Static_Elaboration_Checks then
  return False;
 
-  --  Internally-generated assigments are assumed to be ABE safe
+  --  Nothing to do when the scenario is not an assignment
 
+  elsif Nkind (N) /= N_Assignment_Statement then
+ return False;
+
+  --  Nothing to do for internally-generated assignments because they are
+  --  assumed to be ABE safe.
+
   elsif not Comes_From_Source (N) then
  return False;
 
@@ -5161,10 +5182,10 @@
   --  To qualify, the assignment must meet the following prerequisites:
 
   return
-Comes_From_Source (Var_Id)
 
-  --  The variable must be susceptible to warnings
+--  The variable must be a source entity and susceptible to warnings
 
+Comes_From_Source (Var_Id)
   and then not Has_Warnings_Off (Var_Id)
 
   --  The variable must be declared in the spec of compilation unit U
@@ -5232,14 +5253,23 @@
--  Start of processing for Is_Suitable_Variable_Reference
 
begin
+  --  This scenario is relevant only when the static model is in effect
+  --  because it is graph-dependent and does not involve any run-time
+  --  checks. Allowing it in the dynamic model would create confusing
+  --  noise.
+
+  if not Static_Elaboration_Checks then
+ return False;
+
   --  Attributes and operator sumbols are not considered to be suitable
   --  references to variables even though they are part of predicate
   --  Is_Entity_Name.
 
-  if not Nkind_In (N, N_Expanded_Name, N_Identifier) then
+  elsif not Nkind_In (N, N_Expanded_Name, N_Identifier) then
  return False;
 
-  --  Internally generated references are assumed to be ABE safe
+  --  Nothing to do for internally-generated references because they are
+  --  assumed to be ABE safe.
 
   elsif not Comes_From_Source (N) then
  return False;


[PATCH, rs6000] testcase coverage for vec_splat_uX

2017-10-09 Thread Will Schmidt
Hi, 
  
Add testcase coverage for vec_splat_{u8,s8,u16,s16,u32,s32} built-ins.

Tested on P6 and newer.   OK for trunk? 

Thanks, 
-Will


[testsuite]

|---* gcc.target/powerpc/fold-vec-splat-16.c: New
|---* gcc.target/powerpc/fold-vec-splat-32.c: New.
|---* gcc.target/powerpc/fold-vec-splat-8.c: New.


diff --git a/gcc/testsuite/gcc.target/powerpc/fold-vec-splat-16.c 
b/gcc/testsuite/gcc.target/powerpc/fold-vec-splat-16.c
new file mode 100644
index 000..bb4a8d2
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/fold-vec-splat-16.c
@@ -0,0 +1,46 @@
+/* Verify that overloaded built-ins for vec_splat with int
+   inputs produce the right code.  */
+
+/* { dg-do compile } */
+/* { dg-require-effective-target powerpc_vsx_ok } */
+/* { dg-options "-mvsx -O2" } */
+
+#include 
+
+vector signed short
+testss_1 ()
+{
+  return vec_splat_s16 (5);
+}
+
+vector signed short
+testss_2 ()
+{
+  return vec_splat_s16 (-5);
+}
+
+vector signed short
+testss_3 ()
+{
+  return vec_splat_s16 (15);
+}
+
+vector unsigned short
+testus_1 ()
+{
+  return vec_splat_u16 (5);
+}
+
+vector unsigned short
+testus_2 ()
+{
+  return vec_splat_u16 (-5);
+}
+
+vector unsigned short
+testus_3 ()
+{
+  return vec_splat_u16 (15);
+}
+
+/* { dg-final { scan-assembler-times "vspltish" 6 } } */
diff --git a/gcc/testsuite/gcc.target/powerpc/fold-vec-splat-32.c 
b/gcc/testsuite/gcc.target/powerpc/fold-vec-splat-32.c
new file mode 100644
index 000..f59849e
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/fold-vec-splat-32.c
@@ -0,0 +1,46 @@
+/* Verify that overloaded built-ins for vec_splat with int
+   inputs produce the right code.  */
+
+/* { dg-do compile } */
+/* { dg-require-effective-target powerpc_altivec_ok } */
+/* { dg-options "-maltivec -O2" } */
+
+#include 
+
+vector signed int
+testsi_1 ()
+{
+  return vec_splat_s32 (5);
+}
+
+vector signed int
+testsi_2 ()
+{
+  return vec_splat_s32 (-5);
+}
+
+vector signed int
+testsi_3 ()
+{
+ return vec_splat_s32 (15);
+}
+
+vector unsigned int
+testui_1 ()
+{
+  return vec_splat_u32 (5);
+}
+
+vector unsigned int
+testui_2 ()
+{
+  return vec_splat_u32 (-5);
+}
+
+vector unsigned int
+testui_3 ()
+{
+  return vec_splat_u32 (15);
+}
+
+/* { dg-final { scan-assembler-times "vspltisw" 6 } } */
diff --git a/gcc/testsuite/gcc.target/powerpc/fold-vec-splat-8.c 
b/gcc/testsuite/gcc.target/powerpc/fold-vec-splat-8.c
new file mode 100644
index 000..679fcb3
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/fold-vec-splat-8.c
@@ -0,0 +1,46 @@
+/* Verify that overloaded built-ins for vec_splat with int
+   inputs produce the right code.  */
+
+/* { dg-do compile } */
+/* { dg-require-effective-target powerpc_altivec_ok } */
+/* { dg-options "-maltivec -O2" } */
+
+#include 
+
+vector signed char
+testsc_1 ()
+{
+  return vec_splat_s8 (5);
+}
+
+vector signed char
+testsc_2 ()
+{
+  return vec_splat_s8 (-5);
+}
+
+vector signed char
+testsc_3 ()
+{
+  return vec_splat_s8 (15);
+}
+
+vector unsigned char
+testuc_1 ()
+{
+  return vec_splat_u8 (5);
+}
+
+vector unsigned char
+testuc_2 ()
+{
+  return vec_splat_u8 (-5);
+}
+
+vector unsigned char
+testuc_3 ()
+{
+  return vec_splat_u8 (15);
+}
+
+/* { dg-final { scan-assembler-times "vspltisb" 6 } } */




[PATCH, rs6000] Testcase coverage for vec_splats

2017-10-09 Thread Will Schmidt
[PATCH, rs6000] Testcase coverage for vec_splats

Add testcase coverage for bec_splat built-ins.
Tested across power6 and newer. 
OK for trunk?

Thanks, 
-Will

[testsuite]
* gcc.target/powerpc/fold-vec-splats-char.c: New.
* gcc.target/powerpc/fold-vec-splats-floatdouble.c: New.
* gcc.target/powerpc/fold-vec-splats-int.c: New.
* gcc.target/powerpc/fold-vec-splats-longlong.c: New.
* gcc.target/powerpc/fold-vec-splats-short.c: New.

diff --git a/gcc/testsuite/gcc.target/powerpc/fold-vec-splats-char.c 
b/gcc/testsuite/gcc.target/powerpc/fold-vec-splats-char.c
new file mode 100644
index 000..8f21153
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/fold-vec-splats-char.c
@@ -0,0 +1,22 @@
+/* Verify that overloaded built-ins for vec_splats() with char
+   inputs produce the right code.  */
+
+/* { dg-do compile } */
+/* { dg-require-effective-target powerpc_altivec_ok } */
+/* { dg-options "-maltivec -O2 " } */
+
+#include 
+
+vector signed char
+test1s (signed char x)
+{
+  return vec_splats (x);
+}
+
+vector unsigned char
+test1u (unsigned char x)
+{
+  return vec_splats (x);
+}
+
+/* { dg-final { scan-assembler-times "vspltb" 2 } } */
diff --git a/gcc/testsuite/gcc.target/powerpc/fold-vec-splats-floatdouble.c 
b/gcc/testsuite/gcc.target/powerpc/fold-vec-splats-floatdouble.c
new file mode 100644
index 000..859bb38
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/fold-vec-splats-floatdouble.c
@@ -0,0 +1,27 @@
+/* Verify that overloaded built-ins for vec_splat with float and
+   double inputs for VSX produce the right code.  */
+
+/* { dg-do compile } */
+/* { dg-require-effective-target powerpc_vsx_ok } */
+/* { dg-options "-mvsx -O1" } */
+
+#include 
+
+vector float
+test1d (float x)
+{
+  return vec_splats (x);
+}
+
+vector double
+test1f (double x)
+{
+  return vec_splats (x);
+}
+
+// float test generates the permute instruction.
+/* { dg-final { scan-assembler-times "xxpermdi" 1 } } */
+
+// double test generates a convert (double to single non-signalling) followed 
by a splat.
+/* { dg-final { scan-assembler-times "xscvdpspn|xscvdpsp" 1 } } */
+/* { dg-final { scan-assembler-times "vspltw|xxspltw" 1 } } */
diff --git a/gcc/testsuite/gcc.target/powerpc/fold-vec-splats-int.c 
b/gcc/testsuite/gcc.target/powerpc/fold-vec-splats-int.c
new file mode 100644
index 000..6671523
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/fold-vec-splats-int.c
@@ -0,0 +1,22 @@
+/* Verify that overloaded built-ins for vec_splat with int
+   inputs produce the right code.  */
+
+/* { dg-do compile { target { powerpc*-*-linux* && lp64 } } } */
+/* { dg-require-effective-target powerpc_altivec_ok } */
+/* { dg-options "-maltivec -O2 " } */
+
+#include 
+
+vector signed int
+test3s (signed int x)
+{
+  return vec_splats (x);
+}
+
+vector unsigned int
+test3u (unsigned int x)
+{
+  return vec_splats (x);
+}
+
+/* { dg-final { scan-assembler-times {\mvspltw\M|\mxxspltw\M} 2 } } */
diff --git a/gcc/testsuite/gcc.target/powerpc/fold-vec-splats-longlong.c 
b/gcc/testsuite/gcc.target/powerpc/fold-vec-splats-longlong.c
new file mode 100644
index 000..c5884ba
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/fold-vec-splats-longlong.c
@@ -0,0 +1,22 @@
+/* Verify that overloaded built-ins for vec_splat with long long
+   inputs produce the right code.  */
+
+/* { dg-do compile { target { powerpc*-*-linux* && lp64 } } } */
+/* { dg-require-effective-target powerpc_vsx_ok } */
+/* { dg-options "-mvsx -O2" } */
+
+#include 
+
+vector signed long long
+test3s (signed long long x)
+{
+  return vec_splats (x);
+}
+
+vector unsigned long long
+test3u (unsigned long long x)
+{
+  return vec_splats (x);
+}
+
+/* { dg-final { scan-assembler-times "xxpermdi" 2 } } */
diff --git a/gcc/testsuite/gcc.target/powerpc/fold-vec-splats-short.c 
b/gcc/testsuite/gcc.target/powerpc/fold-vec-splats-short.c
new file mode 100644
index 000..18102ac
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/fold-vec-splats-short.c
@@ -0,0 +1,23 @@
+/* Verify that overloaded built-ins for vec_splat with short
+   inputs produce the right code.  */
+
+/* { dg-do compile } */
+/* { dg-require-effective-target powerpc_altivec_ok } */
+/* { dg-options "-maltivec -O2" } */
+
+#include 
+
+vector signed short
+test3s (signed short x)
+{
+  return vec_splats (x);
+}
+
+vector unsigned short
+test3u (unsigned short x)
+{
+  return vec_splats (x);
+}
+
+/* { dg-final { scan-assembler-times "vsplth" 2 } } */
+




Re: [patch] configure option to override TARGET_LIBC_PROVIDES_SSP

2017-10-09 Thread Sandra Loosemore

On 10/09/2017 09:13 AM, Joseph Myers wrote:

The install.texi documentation for --disable-libssp only says "Specify
that the run-time libraries for stack smashing protection should not be
built.".  I think it needs updating to mention these additional effects as
well.


Oops.  :")  How about this version?

-Sandra


2017-10-09  Sandra Loosemore  

	gcc/
	* configure.ac (--enable-libssp): New.
	(gcc_cv_libc_provides_ssp): Check for explicit setting before
	trying to determine target-specific default.  Adjust indentation.
	* configure: Regenerated.
	* doc/install.texi (Configuration): Expand --disable-libssp
	documentation.
Index: gcc/configure.ac
===
--- gcc/configure.ac	(revision 253502)
+++ gcc/configure.ac	(working copy)
@@ -5751,10 +5751,25 @@ if test x$gcc_cv_solaris_crts = xyes; th
   	[Define if the system-provided CRTs are present on Solaris.])
 fi
 
+AC_ARG_ENABLE(libssp,
+[AS_HELP_STRING([--enable-libssp], [enable linking against libssp])],
+[case "${enableval}" in
+  yes|no)
+;;
+  *)
+AC_MSG_ERROR(unknown libssp setting $enableval)
+;;
+esac], [])
+
 # Test for stack protector support in target C library.
 AC_CACHE_CHECK(__stack_chk_fail in target C library,
-  gcc_cv_libc_provides_ssp,
-  [gcc_cv_libc_provides_ssp=no
+  gcc_cv_libc_provides_ssp,
+  [gcc_cv_libc_provides_ssp=no
+  if test "x$enable_libssp" = "xno"; then
+gcc_cv_libc_provides_ssp=yes
+  elif test "x$enable_libssp" = "xyes"; then
+gcc_cv_libc_provides_ssp=no
+  else
 case "$target" in
*-*-musl*)
 	 # All versions of musl provide stack protector
@@ -5791,8 +5806,9 @@ AC_CACHE_CHECK(__stack_chk_fail in targe
 	 AC_CHECK_FUNC(__stack_chk_fail,[gcc_cv_libc_provides_ssp=yes],
[echo "no __stack_chk_fail on this target"])
 ;;
-  *) gcc_cv_libc_provides_ssp=no ;;
-esac])
+   *) gcc_cv_libc_provides_ssp=no ;;
+esac
+  fi])
 
 if test x$gcc_cv_libc_provides_ssp = xyes; then
   AC_DEFINE(TARGET_LIBC_PROVIDES_SSP, 1,
Index: gcc/doc/install.texi
===
--- gcc/doc/install.texi	(revision 253502)
+++ gcc/doc/install.texi	(working copy)
@@ -1665,7 +1665,8 @@ not be built.
 
 @item --disable-libssp
 Specify that the run-time libraries for stack smashing protection
-should not be built.
+should not be built or linked against.  On many targets library support
+is provided by the C library instead.
 
 @item --disable-libquadmath
 Specify that the GCC quad-precision math library should not be built.


[Ada] Internal error on expression function in ghost package

2017-10-09 Thread Pierre-Marie de Rodat
This patch corrects an issue whereby an expression function within a ghost
package would cause orphaned freeze nodes.


-- Source --


--  p.ads

package P
  with SPARK_Mode
is
   type Rec is record
  I : Integer;
   end record;
   package Inner with Ghost is
  function F (I : Integer) return Integer is (I);
  function Zero (B : Rec) return Integer;
   end Inner;
   procedure Proc (B : Rec);
end P;

--  p.adb

package body P
  with SPARK_Mode
is
   package body Inner is
  function Zero (B : Rec) return Integer is
  begin
 return 0;
  end;
   end Inner;
   procedure Proc (B : Rec) is
   begin
   if B.I = 0 then
  raise Program_Error;
   end if;
   end;
end P;

--  buffers.ads

with Ada.Containers.Functional_Vectors;
package Buffers
  with SPARK_Mode
is
   subtype Resource is Natural range 0 .. 1000;
   subtype Num is Natural range 0 .. 6;
   subtype Index is Num range 1 .. 6;
   type Data is array (Index) of Resource;
   type Buffer is record
  D : Data;
  K : Index;
   end record;
   package Models with Ghost is
  package Seqs is new Ada.Containers.Functional_Vectors (Index, Resource);
  use Seqs;
  function Rotate_Right (S : Sequence) return Sequence is
(Add (Remove (S, First), Get (S, First)));
  function Model (B : Buffer) return Sequence;
   end Models;
   use Models;
   use Models.Seqs;
   procedure Bump (B : in out Buffer) with
 Post => Model(B) = Model(B);
end Buffers;

--  buffers.adb

with Ada.Containers.Functional_Vectors;
package body Buffers
  with SPARK_Mode
is
   package body Models is
  function Model (B : Buffer) return Sequence is
 S : Sequence;
  begin
 for J in B.K .. Index'Last loop
S := Add (S, B.D(J));
 end loop;
 for J in Index'First .. B.K-1 loop
S := Add (S, B.D(J));
 end loop;
 return S;
  end Model;
   end Models;
   procedure Bump (B : in out Buffer) is
   begin
  if B.K = Index'Last then
 B.K := Index'First;
  else
 B.K := B.K + 1;
  end if;
   end Bump;
end Buffers;


-- Compilation and output --


& gcc -c buffers.adb
& gcc -c p.adb

Tested on x86_64-pc-linux-gnu, committed on trunk

2017-10-09  Justin Squirek  

* sem_ch3.adb (Analyze_Declarations): Add check for ghost packages
before analyzing a given scope due to an expression function.
(Uses_Unseen_Lib_Unit_Priv): Rename to Uses_Unseen_Priv.

Index: sem_ch3.adb
===
--- sem_ch3.adb (revision 253559)
+++ sem_ch3.adb (working copy)
@@ -2233,9 +2233,11 @@
   --  Utility to resolve the expressions of aspects at the end of a list of
   --  declarations.
 
-  function Uses_Unseen_Lib_Unit_Priv (Pkg : Entity_Id) return Boolean;
-  --  Check if an inner package has entities within it that rely on library
-  --  level private types where the full view has not been seen.
+  function Uses_Unseen_Priv (Pkg : Entity_Id) return Boolean;
+  --  Check if a nested package has entities within it that rely on library
+  --  level private types where the full view has not been seen for the
+  --  purposes of checking if it is acceptable to freeze an expression
+  --  function at the point of declaration.
 
   -
   -- Adjust_Decl --
@@ -2540,11 +2542,11 @@
  end loop;
   end Resolve_Aspects;
 
-  ---
-  -- Uses_Unseen_Lib_Unit_Priv --
-  ---
+  --
+  -- Uses_Unseen_Priv --
+  --
 
-  function Uses_Unseen_Lib_Unit_Priv (Pkg : Entity_Id) return Boolean is
+  function Uses_Unseen_Priv (Pkg : Entity_Id) return Boolean is
  Curr : Entity_Id;
 
   begin
@@ -2572,7 +2574,7 @@
  end if;
 
  return False;
-  end Uses_Unseen_Lib_Unit_Priv;
+  end Uses_Unseen_Priv;
 
   --  Local variables
 
@@ -2753,8 +2755,9 @@
 
  elsif not Analyzed (Next_Decl) and then Is_Body (Next_Decl)
and then ((Nkind (Next_Decl) /= N_Subprogram_Body
-  or else not Was_Expression_Function (Next_Decl))
- or else not Uses_Unseen_Lib_Unit_Priv (Current_Scope))
+   or else not Was_Expression_Function (Next_Decl))
+  or else (not Is_Ignored_Ghost_Entity (Current_Scope)
+and then not Uses_Unseen_Priv (Current_Scope)))
  then
 --  When a controlled type is frozen, the expander generates stream
 --  and controlled-type support routines. If the freeze is caused


[Ada] Rewrite check for SPARK RM 7.1.3(10)

2017-10-09 Thread Pierre-Marie de Rodat
The evolution of SPARK RM 7.1.3(10) rule was not followed by code that
implements it. The current wording is:

   "If a procedure has an in mode parameter of an effectively volatile type,
then the Effective_Reads aspect of any corresponding actual parameter
shall be False."

and the current code checks exactly that.


-- Source --


--  ineffective_actual.ads

with System;

package Ineffective_Actual
with
   SPARK_Mode
is
   type VT is 
  record
 Int : Integer;
  end record
   with Volatile;

   The_Volatile_Data : VT
   with
  Volatile,
  Async_Readers=> True,
  Async_Writers=> True,
  Effective_Reads  => False,
  Effective_Writes => False,
  Address => System'To_Address (16#1234_5678#);

   procedure Harmless_Reader (Data : in VT);

   procedure Do_Something;

end Ineffective_Actual;

--  ineffective_actual.adb

package body Ineffective_Actual
with
   SPARK_Mode
is
   procedure Harmless_Reader (Data : in VT)
   with
  SPARK_Mode => Off
   is
  I : Integer;
   begin
  I := Data.Int;
   end Harmless_Reader;

   procedure Do_Something
   is
   begin
  Harmless_Reader (The_Volatile_Data);
   end Do_Something;
end Ineffective_Actual;


-- Compilation and output --


& gcc -c ineffective_actual.adb
& gcc -c -gnatd.F ineffective_actual.adb

Tested on x86_64-pc-linux-gnu, committed on trunk

2017-10-09  Piotr Trojanek  

* sem_res.adb (Property_Error): Remove.
(Resolve_Actuals): check for SPARK RM 7.1.3(10) rewritten to match the
current wording of the rule.

Index: sem_res.adb
===
--- sem_res.adb (revision 253559)
+++ sem_res.adb (working copy)
@@ -3178,14 +3178,6 @@
   --  an instance of the default expression. The insertion is always
   --  a named association.
 
-  procedure Property_Error
-(Var  : Node_Id;
- Var_Id   : Entity_Id;
- Prop_Nam : Name_Id);
-  --  Emit an error concerning variable Var with entity Var_Id that has
-  --  enabled property Prop_Nam when it acts as an actual parameter in a
-  --  call and the corresponding formal parameter is of mode IN.
-
   function Same_Ancestor (T1, T2 : Entity_Id) return Boolean;
   --  Check whether T1 and T2, or their full views, are derived from a
   --  common type. Used to enforce the restrictions on array conversions
@@ -3634,23 +3626,6 @@
  Prev := Actval;
   end Insert_Default;
 
-  
-  -- Property_Error --
-  
-
-  procedure Property_Error
-(Var  : Node_Id;
- Var_Id   : Entity_Id;
- Prop_Nam : Name_Id)
-  is
-  begin
- Error_Msg_Name_1 := Prop_Nam;
- Error_Msg_NE
-   ("external variable & with enabled property % cannot appear as "
-& "actual in procedure call (SPARK RM 7.1.3(10))", Var, Var_Id);
- Error_Msg_N ("\\corresponding formal parameter has mode In", Var);
-  end Property_Error;
-
   ---
   -- Same_Ancestor --
   ---
@@ -4659,26 +4634,28 @@
   Flag_Effectively_Volatile_Objects (A);
end if;
 
-   --  Detect an external variable with an enabled property that
-   --  does not match the mode of the corresponding formal in a
-   --  procedure call. Functions are not considered because they
-   --  cannot have effectively volatile formal parameters in the
-   --  first place.
+   --  An effectively volatile variable cannot act as an actual
+   --  parameter in a procedure call when the variable has enabled
+   --  property Effective_Reads and the corresponding formal is of
+   --  mode IN (SPARK RM 7.1.3(10)).
 
if Ekind (Nam) = E_Procedure
  and then Ekind (F) = E_In_Parameter
  and then Is_Entity_Name (A)
- and then Present (Entity (A))
- and then Ekind (Entity (A)) = E_Variable
then
   A_Id := Entity (A);
 
-  if Async_Readers_Enabled (A_Id) then
- Property_Error (A, A_Id, Name_Async_Readers);
-  elsif Effective_Reads_Enabled (A_Id) then
- Property_Error (A, A_Id, Name_Effective_Reads);
-  elsif Effective_Writes_Enabled (A_Id) then
- Property_Error (A, A_Id, Name_Effective_Writes);
+  if Ekind (A_Id) = E_Variable
+and then Is_Effectively_Volatile (Etype (A_Id))
+and then Effective_Reads_Enabled (A_Id)
+  then
+ Error_Msg_NE
+   ("effectively volatile variable & cannot 

[Ada] Spurious error in use of homograph of type name in predicate

2017-10-09 Thread Pierre-Marie de Rodat
This patch fixes a spurious error in an expression for a dynamic predicate,
when the name of (a homograph of) the type to which the predicate applies
is used in a context where the name cannot denote a current occurrence.

The following must compile quietly:

   gcc -c conv.ads

---
with Typ; use Typ;
package Conv  with SPARK_Mode is
private
   type U is new Typ.U with record
  X : Integer;
   end record
 with Dynamic_Predicate => Typ.U(U).Get > 0;
end Conv;
---
package Typ is
   type U is tagged private;
   function Get (V : U) return Integer;
private
   type U is tagged record
  Y : Integer;
   end record;

   function Get (V : U) return Integer is (V.Y);
end Typ;

Tested on x86_64-pc-linux-gnu, committed on trunk

2017-10-09  Ed Schonberg  

* sem_ch13.adb (Replace_Type_Ref): In the expression for a dynamic
predicate, do not replace an identifier that matches the type if the
identifier is a selector in a selected component, because this
indicates a reference to some homograph of the type itself, and  not to
the current occurence in the predicate.

Index: sem_ch13.adb
===
--- sem_ch13.adb(revision 253546)
+++ sem_ch13.adb(working copy)
@@ -4415,15 +4415,6 @@
 
 if Present (Default_Element) then
Analyze (Default_Element);
-
-   if Is_Entity_Name (Default_Element)
- and then not Covers (Entity (Default_Element), Ret_Type)
- and then False
-   then
-  Illegal_Indexing
-("wrong return type for indexing function");
-  return;
-   end if;
 end if;
 
 --  For variable_indexing the return type must be a reference type
@@ -12670,10 +12661,18 @@
 
return Skip;
 
---  Otherwise do the replacement and we are done with this node
+--  Otherwise do the replacement if this is not a qualified
+--  reference to a homograph of the type itself. Note that the
+--  current instance could not appear in such a context, e.g.
+--  the prefix of a type conversion.
 
 else
-   Replace_Type_Reference (N);
+   if Nkind (Parent (N)) /= N_Selected_Component
+ or else N /= Selector_Name (Parent (N))
+   then
+  Replace_Type_Reference (N);
+   end if;
+
return Skip;
 end if;
 
@@ -12682,7 +12681,7 @@
 
  elsif Nkind (N) = N_Selected_Component then
 
---  If selector name is not our type, keeping going (we might still
+--  If selector name is not our type, keep going (we might still
 --  have an occurrence of the type in the prefix).
 
 if Nkind (Selector_Name (N)) /= N_Identifier


[Ada] Spurious error with predicate and class-wide object

2017-10-09 Thread Pierre-Marie de Rodat
This patch removes a spurious error on a call to a function that applies
to a predicated tagged type, when the actual in the call is class-wide.
The argument must be converted to be type-specific, given that the predicate
function is not dispatching and cannot accept a class-wide actual.

Executing:

   gnatmake -q -gnata main
   main

must yield:

   Predicate checked
   Predicate checked
   Predicate checked
   Predicate checked
   Predicate checked
   Predicate checked

---
with Predicate_Ints; use Predicate_Ints;
procedure Main is
  Thing1 : Int := (0, 100, 50);
  Thing2 : Approx_Int := (0, 100, 50, 13);
begin
  Call_Bump (Thing1);
  Call_Bump (Thing2);
end;
---
package Predicate_Ints is

   type Int is tagged record
  Min, Max, Value : Integer;
   end record
 with Predicate => Value in Min .. Max and then Checked;

   procedure Bump (Arg : in out Int);
   procedure Call_Bump (Arg : in out Int'Class);

   function Checked  return Boolean;

   type Approx_Int is new Int with record
  Precision : Natural;
   end record;

end Predicate_Ints;
---
with Text_IO; use Text_IO;
package body Predicate_Ints is
   function Checked return Boolean is
   begin
  Put_Line ("Predicate checked");
  return True;
   end;
   
   procedure Bump (Arg : in out Int) is
   begin
  Arg.Value := Arg.Value + 1;
   end Bump;

   procedure Call_Bump (Arg : in out Int'Class) is
   begin
  Arg.Bump;
   end Call_Bump;

end Predicate_Ints;

Tested on x86_64-pc-linux-gnu, committed on trunk

2017-10-09  Ed Schonberg  

* exp_util.adb (Make_Predicate_Call): If the type of the expression to
which the predicate check applies is tagged, convert the expression to
that type. This is in most cases a no-op, but is relevant if the
expression is clas-swide, because the predicate function being invoked
is not a primitive of the type and cannot take a class-wide actual.

Index: exp_util.adb
===
--- exp_util.adb(revision 253559)
+++ exp_util.adb(working copy)
@@ -9305,11 +9305,23 @@
 
   --  Case of calling normal predicate function
 
-  Call :=
-Make_Function_Call (Loc,
-  Name   => New_Occurrence_Of (Func_Id, Loc),
-  Parameter_Associations => New_List (Relocate_Node (Expr)));
+  --  If the type is tagged, the expression may be class-wide, in which
+  --  case it has to be converted to its root type, given that the
+  --  generated predicate function is not dispatching.
 
+  if Is_Tagged_Type (Typ) then
+ Call :=
+   Make_Function_Call (Loc,
+ Name   => New_Occurrence_Of (Func_Id, Loc),
+ Parameter_Associations =>
+   New_List (Convert_To (Typ, Relocate_Node (Expr;
+  else
+ Call :=
+   Make_Function_Call (Loc,
+ Name   => New_Occurrence_Of (Func_Id, Loc),
+ Parameter_Associations => New_List (Relocate_Node (Expr)));
+  end if;
+
   Restore_Ghost_Mode (Saved_GM);
 
   return Call;


[Ada] Suppress generation of ABE checks in GNATprove mode

2017-10-09 Thread Pierre-Marie de Rodat
This patch suppresses the generation of ABE checks when compiling for GNATprove
because a) the checks are not needed and b) the checks involve raise statements
which are not supported by GNATprove. No need for a test.

Tested on x86_64-pc-linux-gnu, committed on trunk

2017-10-09  Hristian Kirtchev  

* sem_elab.adb (Install_ABE_Check): Do not generate an ABE check for
GNATprove.
(Install_ABE_Failure): Do not generate an ABE failure for GNATprove.

Index: sem_elab.adb
===
--- sem_elab.adb(revision 253559)
+++ sem_elab.adb(working copy)
@@ -4199,9 +4199,15 @@
   Scop_Id : Entity_Id;
 
begin
+  --  Nothing to do when compiling for GNATprove because raise statements
+  --  are not supported.
+
+  if GNATprove_Mode then
+ return;
+
   --  Nothing to do when the compilation will not produce an executable
 
-  if Serious_Errors_Detected > 0 then
+  elsif Serious_Errors_Detected > 0 then
  return;
 
   --  Nothing to do for a compilation unit because there is no executable
@@ -4325,9 +4331,15 @@
--  Start for processing for Install_ABE_Check
 
begin
+  --  Nothing to do when compiling for GNATprove because raise statements
+  --  are not supported.
+
+  if GNATprove_Mode then
+ return;
+
   --  Nothing to do when the compilation will not produce an executable
 
-  if Serious_Errors_Detected > 0 then
+  elsif Serious_Errors_Detected > 0 then
  return;
 
   --  Nothing to do when the target is a protected subprogram because the
@@ -4381,9 +4393,15 @@
   Scop_Id : Entity_Id;
 
begin
+  --  Nothing to do when compiling for GNATprove because raise statements
+  --  are not supported.
+
+  if GNATprove_Mode then
+ return;
+
   --  Nothing to do when the compilation will not produce an executable
 
-  if Serious_Errors_Detected > 0 then
+  elsif Serious_Errors_Detected > 0 then
  return;
 
   --  Do not install an ABE check for a compilation unit because there is


Re: [PATCH] Fix ICEs with ss{e,e2,se3} builtins with -mno-mmx (PR target/82483)

2017-10-09 Thread Jakub Jelinek
On Mon, Oct 09, 2017 at 09:28:58PM +0200, Uros Bizjak wrote:
> On Mon, Oct 9, 2017 at 9:16 PM, Jakub Jelinek  wrote:
> > Hi!
> >
> > The following builtins have {SSE,SSE2,SSSE3} CPUID, yet they have
> > MMX register operands (either input or output or both).
> > As -mno-mmx doesn't imply -mno-sse, we get ICEs on these though, because
> > with MMX disabled it is not possible to emit them.
> >
> > The following patch cheats and declares these builtins to require
> > both the MMX and {SSE,SSE2,SSSE3} ISA, making them unavailable in -mno-mmx
> > code, but I think it is the right thing to do, when somebody uses -mno-mmx,
> > the intent is usually not to have any instructions touching the MMX register
> > file and thus needing EMMS etc.
> >
> > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> 
> Hm, I remember there was similar patch for PR79565 [1], which seems
> related. Does your patch also fix all builtins that HJ's patch touch?

Ah, I wasn't aware of that patch.  Will look in detail tomorrow.

> [1] https://gcc.gnu.org/ml/gcc-patches/2017-08/msg00751.html

Just quick analysis, while -mno-mmx doesn't imply -mno-sse (that is
right), it implies -mno-3dnow and -mno-3dnow implies -mno-3dnowa.
So all the spots that were changed from OPTION_MASK_ISA_3DNOW
to OPTION_MASK_ISA_3DNOW | OPTION_MASK_ISA_MMX or from
OPTION_MASK_ISA_3DNOW_A to OPTION_MASK_ISA_3DNOW_A | OPTION_MASK_ISA_MMX
were useless, we can do what we did before.
It is just OPTION_MASK_ISA_SSE or higher with OPTION_MASK_ISA_MMX that
is needed.
I have no idea why __builtin_ia32_sfence or __builtin_ia32_movntq were
changed.
Nor I understand why any sse.md changes are needed, then the builtins
aren't available, those insns shouldn't be synthetized out of thin air.
And the i386.c def_builtin change IMNSHO isn't needed either, it is
a compile time speed/memory optimization not to declare everything
unconditionally, and the way it works right now is that any of the enabled
ISAs enables the builtin, meaning that MMX enabled will mean those
35 will be declared, even when perhaps SSE isn't enabled, or for
SSE when MMX isn't enabled, but that isn't that big deal.

Jakub


[PATCH 3/3] Add targetm.insn_cost hook

2017-10-09 Thread Segher Boessenkool
This adds a new hook that the insn_cost function uses if a target has
implemented it (it uses the old pattern_cost nee insn_rtx_cost if not).

I'll commit this now; it was okayed by Jeff at
https://gcc.gnu.org/ml/gcc-patches/2017-08/msg00204.html .


Segher


2017-10-09  Segher Boessenkool  

* target.def (insn_cost): New hook.
* doc/tm.texi.in (TARGET_INSN_COST): New hook.
* doc/tm.texi: Regenerate.
* rtlanal.c (insn_cost): Use the new hook.

---
 gcc/doc/tm.texi| 12 
 gcc/doc/tm.texi.in |  2 ++
 gcc/rtlanal.c  |  3 +++
 gcc/target.def | 14 ++
 4 files changed, 31 insertions(+)

diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index 8f503e1..0377217 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -6652,6 +6652,18 @@ should probably only be given to addresses with 
different numbers of
 registers on machines with lots of registers.
 @end deftypefn
 
+@deftypefn {Target Hook} int TARGET_INSN_COST (rtx_insn *@var{insn}, bool 
@var{speed})
+This target hook describes the relative costs of RTL instructions.
+
+In implementing this hook, you can use the construct
+@code{COSTS_N_INSNS (@var{n})} to specify a cost equal to @var{n} fast
+instructions.
+
+When optimizing for code size, i.e.@: when @code{speed} is
+false, this target hook should be used to estimate the relative
+size cost of an expression, again relative to @code{COSTS_N_INSNS}.
+@end deftypefn
+
 @deftypefn {Target Hook} {unsigned int} TARGET_MAX_NOCE_IFCVT_SEQ_COST (edge 
@var{e})
 This hook returns a value in the same units as @code{TARGET_RTX_COSTS},
 giving the maximum acceptable cost for a sequence generated by the RTL
diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in
index 15b3f1f..d2cf68f 100644
--- a/gcc/doc/tm.texi.in
+++ b/gcc/doc/tm.texi.in
@@ -4600,6 +4600,8 @@ Define this macro if a non-short-circuit operation 
produced by
 
 @hook TARGET_ADDRESS_COST
 
+@hook TARGET_INSN_COST
+
 @hook TARGET_MAX_NOCE_IFCVT_SEQ_COST
 
 @hook TARGET_NOCE_CONVERSION_PROFITABLE_P
diff --git a/gcc/rtlanal.c b/gcc/rtlanal.c
index f01eab5..eadf691 100644
--- a/gcc/rtlanal.c
+++ b/gcc/rtlanal.c
@@ -5329,6 +5329,9 @@ pattern_cost (rtx pat, bool speed)
 int
 insn_cost (rtx_insn *insn, bool speed)
 {
+  if (targetm.insn_cost)
+return targetm.insn_cost (insn, speed);
+
   return pattern_cost (PATTERN (insn), speed);
 }
 
diff --git a/gcc/target.def b/gcc/target.def
index 80ef746..aac5d27 100644
--- a/gcc/target.def
+++ b/gcc/target.def
@@ -3715,6 +3715,20 @@ registers on machines with lots of registers.",
  int, (rtx address, machine_mode mode, addr_space_t as, bool speed),
  default_address_cost)
 
+/* Compute a cost for INSN.  */
+DEFHOOK
+(insn_cost,
+ "This target hook describes the relative costs of RTL instructions.\n\
+\n\
+In implementing this hook, you can use the construct\n\
+@code{COSTS_N_INSNS (@var{n})} to specify a cost equal to @var{n} fast\n\
+instructions.\n\
+\n\
+When optimizing for code size, i.e.@: when @code{speed} is\n\
+false, this target hook should be used to estimate the relative\n\
+size cost of an expression, again relative to @code{COSTS_N_INSNS}.",
+ int, (rtx_insn *insn, bool speed), NULL)
+
 /* Give a cost, in RTX Costs units, for an edge.  Like BRANCH_COST, but with
well defined units.  */
 DEFHOOK
-- 
1.8.3.1



[PATCH 2/3] combine: Use insn_cost instead of pattern_cost everywhere

2017-10-09 Thread Segher Boessenkool
Committing to trunk.


Segher


2017-10-09  Segher Boessenkool  

* combine.c (combine_validate_cost): Compute the new insn_cost,
not just pattern_cost.
(try_combine): Adjust comment.

---
 gcc/combine.c | 31 +--
 1 file changed, 25 insertions(+), 6 deletions(-)

diff --git a/gcc/combine.c b/gcc/combine.c
index c5f6a00..9a006be 100644
--- a/gcc/combine.c
+++ b/gcc/combine.c
@@ -856,7 +856,7 @@ combine_validate_cost (rtx_insn *i0, rtx_insn *i1, rtx_insn 
*i2, rtx_insn *i3,
   int new_i2_cost, new_i3_cost;
   int old_cost, new_cost;
 
-  /* Lookup the original insn_rtx_costs.  */
+  /* Lookup the original insn_costs.  */
   i2_cost = INSN_COST (i2);
   i3_cost = INSN_COST (i3);
 
@@ -888,11 +888,23 @@ combine_validate_cost (rtx_insn *i0, rtx_insn *i1, 
rtx_insn *i2, rtx_insn *i3,
 old_cost -= i1_cost;
 
 
-  /* Calculate the replacement pattern_costs.  */
-  new_i3_cost = pattern_cost (newpat, optimize_this_for_speed_p);
+  /* Calculate the replacement insn_costs.  */
+  rtx tmp = PATTERN (i3);
+  PATTERN (i3) = newpat;
+  int tmpi = INSN_CODE (i3);
+  INSN_CODE (i3) = -1;
+  new_i3_cost = insn_cost (i3, optimize_this_for_speed_p);
+  PATTERN (i3) = tmp;
+  INSN_CODE (i3) = tmpi;
   if (newi2pat)
 {
-  new_i2_cost = pattern_cost (newi2pat, optimize_this_for_speed_p);
+  tmp = PATTERN (i2);
+  PATTERN (i2) = newi2pat;
+  tmpi = INSN_CODE (i2);
+  INSN_CODE (i2) = -1;
+  new_i2_cost = insn_cost (i2, optimize_this_for_speed_p);
+  PATTERN (i2) = tmp;
+  INSN_CODE (i2) = tmpi;
   new_cost = (new_i2_cost > 0 && new_i3_cost > 0)
 ? new_i2_cost + new_i3_cost : 0;
 }
@@ -907,7 +919,14 @@ combine_validate_cost (rtx_insn *i0, rtx_insn *i1, 
rtx_insn *i2, rtx_insn *i3,
   int old_other_cost, new_other_cost;
 
   old_other_cost = INSN_COST (undobuf.other_insn);
-  new_other_cost = pattern_cost (newotherpat, optimize_this_for_speed_p);
+  tmp = PATTERN (undobuf.other_insn);
+  PATTERN (undobuf.other_insn) = newotherpat;
+  tmpi = INSN_CODE (undobuf.other_insn);
+  INSN_CODE (undobuf.other_insn) = -1;
+  new_other_cost = insn_cost (undobuf.other_insn,
+ optimize_this_for_speed_p);
+  PATTERN (undobuf.other_insn) = tmp;
+  INSN_CODE (undobuf.other_insn) = tmpi;
   if (old_other_cost > 0 && new_other_cost > 0)
{
  old_cost += old_other_cost;
@@ -4108,7 +4127,7 @@ try_combine (rtx_insn *i3, rtx_insn *i2, rtx_insn *i1, 
rtx_insn *i0,
}
 }
 
-  /* Only allow this combination if insn_rtx_costs reports that the
+  /* Only allow this combination if insn_cost reports that the
  replacement instructions are cheaper than the originals.  */
   if (!combine_validate_cost (i0, i1, i2, i3, newpat, newi2pat, other_pat))
 {
-- 
1.8.3.1



[PATCH 1/3] Replace insn_rtx_cost with insn_cost and pattern_cost

2017-10-09 Thread Segher Boessenkool
This replaces insn_rtx_cost with insn_cost if an insn is readily
available, and with pattern_cost otherwise.

Okayed by Jeff in https://gcc.gnu.org/ml/gcc-patches/2017-08/msg00203.html
and I'll commit it now.


Segher


2017-10-09  Segher Boessenkool  

* cfgrtl.c (rtl_account_profile_record): Replace insn_rtx_cost with
insn_cost.
* combine.c (uid_insn_cost): Adjust comment.
(combine_validate_cost): Adjust comment.  Use pattern_cost instead
of insn_rtx_cost
(combine_instructions): Use insn_cost instead of insn_rtx_cost.
* dse.c (find_shift_sequence): Ditto.
* ifcvt.c (cheap_bb_rtx_cost_p): Ditto.
(bb_valid_for_noce_process_p): Use pattern_cost.
* rtl.h (insn_rtx_cost): Delete.
(pattern_cost): New prototype.
(insn_cost): New prototype.
* rtlanal.c (insn_rtx_cost): Rename to...
(pattern_cost): ... this.
(insn_cost): New.

---
 gcc/cfgrtl.c  |  7 +++
 gcc/combine.c | 17 -
 gcc/dse.c |  2 +-
 gcc/ifcvt.c   | 12 ++--
 gcc/rtl.h |  3 ++-
 gcc/rtlanal.c | 13 +++--
 6 files changed, 31 insertions(+), 23 deletions(-)

diff --git a/gcc/cfgrtl.c b/gcc/cfgrtl.c
index 6ef47b7..739d1bb 100644
--- a/gcc/cfgrtl.c
+++ b/gcc/cfgrtl.c
@@ -5039,14 +5039,13 @@ rtl_account_profile_record (basic_block bb, int 
after_pass,
   FOR_BB_INSNS (bb, insn)
 if (INSN_P (insn))
   {
-   record->size[after_pass]
- += insn_rtx_cost (PATTERN (insn), false);
+   record->size[after_pass] += insn_cost (insn, false);
if (bb->count.initialized_p ())
  record->time[after_pass]
-   += insn_rtx_cost (PATTERN (insn), true) * bb->count.to_gcov_type ();
+   += insn_cost (insn, true) * bb->count.to_gcov_type ();
else if (profile_status_for_fn (cfun) == PROFILE_GUESSED)
  record->time[after_pass]
-   += insn_rtx_cost (PATTERN (insn), true) * bb->frequency;
+   += insn_cost (insn, true) * bb->frequency;
   }
 }
 
diff --git a/gcc/combine.c b/gcc/combine.c
index 3b98ff4..c5f6a00 100644
--- a/gcc/combine.c
+++ b/gcc/combine.c
@@ -311,7 +311,7 @@ static bool optimize_this_for_speed_p;
 
 static int max_uid_known;
 
-/* The following array records the insn_rtx_cost for every insn
+/* The following array records the insn_cost for every insn
in the instruction stream.  */
 
 static int *uid_insn_cost;
@@ -841,7 +841,7 @@ do_SUBST_LINK (struct insn_link **into, struct insn_link 
*newval)
 #define SUBST_LINK(oldval, newval) do_SUBST_LINK (, newval)
 
 /* Subroutine of try_combine.  Determine whether the replacement patterns
-   NEWPAT, NEWI2PAT and NEWOTHERPAT are cheaper according to insn_rtx_cost
+   NEWPAT, NEWI2PAT and NEWOTHERPAT are cheaper according to insn_cost
than the original sequence I0, I1, I2, I3 and undobuf.other_insn.  Note
that I0, I1 and/or NEWI2PAT may be NULL_RTX.  Similarly, NEWOTHERPAT and
undobuf.other_insn may also both be NULL_RTX.  Return false if the cost
@@ -888,11 +888,11 @@ combine_validate_cost (rtx_insn *i0, rtx_insn *i1, 
rtx_insn *i2, rtx_insn *i3,
 old_cost -= i1_cost;
 
 
-  /* Calculate the replacement insn_rtx_costs.  */
-  new_i3_cost = insn_rtx_cost (newpat, optimize_this_for_speed_p);
+  /* Calculate the replacement pattern_costs.  */
+  new_i3_cost = pattern_cost (newpat, optimize_this_for_speed_p);
   if (newi2pat)
 {
-  new_i2_cost = insn_rtx_cost (newi2pat, optimize_this_for_speed_p);
+  new_i2_cost = pattern_cost (newi2pat, optimize_this_for_speed_p);
   new_cost = (new_i2_cost > 0 && new_i3_cost > 0)
 ? new_i2_cost + new_i3_cost : 0;
 }
@@ -907,7 +907,7 @@ combine_validate_cost (rtx_insn *i0, rtx_insn *i1, rtx_insn 
*i2, rtx_insn *i3,
   int old_other_cost, new_other_cost;
 
   old_other_cost = INSN_COST (undobuf.other_insn);
-  new_other_cost = insn_rtx_cost (newotherpat, optimize_this_for_speed_p);
+  new_other_cost = pattern_cost (newotherpat, optimize_this_for_speed_p);
   if (old_other_cost > 0 && new_other_cost > 0)
{
  old_cost += old_other_cost;
@@ -1208,10 +1208,9 @@ combine_instructions (rtx_insn *f, unsigned int nregs)
  set_nonzero_bits_and_sign_copies (XEXP (links, 0), NULL_RTX,
insn);
 
-   /* Record the current insn_rtx_cost of this instruction.  */
+   /* Record the current insn_cost of this instruction.  */
if (NONJUMP_INSN_P (insn))
- INSN_COST (insn) = insn_rtx_cost (PATTERN (insn),
-   optimize_this_for_speed_p);
+ INSN_COST (insn) = insn_cost (insn, optimize_this_for_speed_p);
if (dump_file)
  {
fprintf (dump_file, "insn_cost %d for ", INSN_COST (insn));
diff --git a/gcc/dse.c b/gcc/dse.c
index cff3ac4..563ca9f 100644
--- 

Re: [PATCH] libstdc++: istreambuf_iterator proxy

2017-10-09 Thread Petr Ovtchenkov
On Sun, 8 Oct 2017 16:59:39 +0200
François Dumont  wrote:

> ...
> >>
> >> Consider this code:
> >>
> >>     std::istringstream inf("abc");
> >>     std::istreambuf_iterator j(inf), eof;
> >>     std::istreambuf_iterator i = j++;
> >>
> >>     assert( *i == 'a' );
> >>
> >> At this point it looks like i is pointing to 'a' but then when you do:
> >>
> >> std::string str(i, eof);
> >>
> >> you have:
> >> assert( str == "ac" );
> > No. I mean that in last (my) suggestion ([PATCH])
> >
> > std::istreambuf_iterator i = j++;
> >
> > is impossible ("impossible" is in aggree with standard).
> > So test test01() in 2.cc isn't correct.
> 
> It is correct as this constructor:
> +  /// Construct start of streambuf iterator.
> +  istreambuf_iterator(const proxy& __prx) _GLIBCXX_USE_NOEXCEPT
> +  : _M_sbuf(__prx._M_sbuf)
> +  { }
> 
> is defined by the Standard. This is why the llvm test is fine too.

Yes, you right here.

But in

+  std::istringstream inf("abc");
+  std::istreambuf_iterator j(inf);
+  std::istreambuf_iterator i = j++;
+
+  VERIFY( i != std::istreambuf_iterator() );
+  VERIFY( *i == 'b' );
+  VERIFY( *j++ == 'b' );

the last two lines

+  VERIFY( *i == 'b' );
+  VERIFY( *j++ == 'b' );

is a check of the implementation-specific behaviour, because of

  ++r ... any copies of the previous
  value of r are no longer
  required either to be
  dereferenceable or to be in
  the domain of ==.
  ...
  (void)r++equivalent to (void)++r

(i is a copy of "previous" value of j)


From other side, for ctor from proxy

   istreambuf_iterator(const proxy& p) noexcept;
5  Effects: Initializes sbuf_ with p.sbuf_.

that mean that reference of istreambuf_iterator to basic_streambuf
(sbuf_) has some meaning. proxy may be dereferenced or used
to produce istreambuf_iterator that may be used for == (but not
for dereference itself ;)).



Re: [PATCH] Fix ICEs with ss{e,e2,se3} builtins with -mno-mmx (PR target/82483)

2017-10-09 Thread Uros Bizjak
On Mon, Oct 9, 2017 at 9:16 PM, Jakub Jelinek  wrote:
> Hi!
>
> The following builtins have {SSE,SSE2,SSSE3} CPUID, yet they have
> MMX register operands (either input or output or both).
> As -mno-mmx doesn't imply -mno-sse, we get ICEs on these though, because
> with MMX disabled it is not possible to emit them.
>
> The following patch cheats and declares these builtins to require
> both the MMX and {SSE,SSE2,SSSE3} ISA, making them unavailable in -mno-mmx
> code, but I think it is the right thing to do, when somebody uses -mno-mmx,
> the intent is usually not to have any instructions touching the MMX register
> file and thus needing EMMS etc.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

Hm, I remember there was similar patch for PR79565 [1], which seems
related. Does your patch also fix all builtins that HJ's patch touch?

[1] https://gcc.gnu.org/ml/gcc-patches/2017-08/msg00751.html

Uros.

> 2017-10-09  Jakub Jelinek  
>
> PR target/82483
> * config/i386/i386.c (ix86_init_mmx_sse_builtins): Add
> OPTION_MASK_ISA_MMX for __builtin_ia32_maskmovq,
> __builtin_ia32_vec_ext_v4hi and __builtin_ia32_vec_set_v4hi.
> (ix86_expand_builtin): Treat OPTION_MASK_ISA_MMX similarly
> to OPTION_MASK_ISA_AVX512VL - builtins that have both
> OPTION_MASK_ISA_MMX and some other bit set require both
> mmx and the ISAs without the mmx bit.
> * config/i386/i386-builtin.def (__builtin_ia32_cvtps2pi,
> __builtin_ia32_cvttps2pi, __builtin_ia32_cvtpi2ps,
> __builtin_ia32_pavgb, __builtin_ia32_pavgw, __builtin_ia32_pmulhuw,
> __builtin_ia32_pmaxub, __builtin_ia32_pmaxsw, __builtin_ia32_pminub,
> __builtin_ia32_pminsw, __builtin_ia32_psadbw, __builtin_ia32_pmovmskb,
> __builtin_ia32_pshufw, __builtin_ia32_cvtpd2pi,
> __builtin_ia32_cvttpd2pi, __builtin_ia32_cvtpi2pd,
> __builtin_ia32_pmuludq, __builtin_ia32_pabsb, __builtin_ia32_pabsw,
> __builtin_ia32_pabsd, __builtin_ia32_phaddw, __builtin_ia32_phaddd,
> __builtin_ia32_phaddsw, __builtin_ia32_phsubw, __builtin_ia32_phsubd,
> __builtin_ia32_phsubsw, __builtin_ia32_pmaddubsw,
> __builtin_ia32_pmulhrsw, __builtin_ia32_pshufb, __builtin_ia32_psignb,
> __builtin_ia32_psignw, __builtin_ia32_psignd): Add 
> OPTION_MASK_ISA_MMX.
>
> * gcc.target/i386/pr82483.c: New test.
>
> --- gcc/config/i386/i386.c.jj   2017-10-09 09:41:21.0 +0200
> +++ gcc/config/i386/i386.c  2017-10-09 10:54:05.763679093 +0200
> @@ -32988,7 +32988,9 @@ ix86_init_mmx_sse_builtins (void)
> UNSIGNED_FTYPE_VOID, IX86_BUILTIN_STMXCSR);
>
>/* SSE or 3DNow!A */
> -  def_builtin (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A,
> +  def_builtin (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A
> +  /* As it uses V4HImode, we have to require -mmmx too.  */
> +  | OPTION_MASK_ISA_MMX,
>"__builtin_ia32_maskmovq", VOID_FTYPE_V8QI_V8QI_PCHAR,
>IX86_BUILTIN_MASKMOVQ);
>
> @@ -33426,7 +33428,9 @@ ix86_init_mmx_sse_builtins (void)
>def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v8hi",
>  HI_FTYPE_V8HI_INT, IX86_BUILTIN_VEC_EXT_V8HI);
>
> -  def_builtin_const (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A,
> +  def_builtin_const (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A
> +/* As it uses V4HImode, we have to require -mmmx too.  */
> +| OPTION_MASK_ISA_MMX,
>  "__builtin_ia32_vec_ext_v4hi",
>  HI_FTYPE_V4HI_INT, IX86_BUILTIN_VEC_EXT_V4HI);
>
> @@ -33450,7 +33454,9 @@ ix86_init_mmx_sse_builtins (void)
>def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_set_v8hi",
>  V8HI_FTYPE_V8HI_HI_INT, IX86_BUILTIN_VEC_SET_V8HI);
>
> -  def_builtin_const (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A,
> +  def_builtin_const (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A
> +/* As it uses V4HImode, we have to require -mmmx too.  */
> +| OPTION_MASK_ISA_MMX,
>  "__builtin_ia32_vec_set_v4hi",
>  V4HI_FTYPE_V4HI_HI_INT, IX86_BUILTIN_VEC_SET_V4HI);
>
> @@ -37914,18 +37920,23 @@ ix86_expand_builtin (tree exp, rtx targe
>   Originally the builtin was not created if it wasn't applicable to the
>   current ISA based on the command line switches.  With function specific
>   options, we need to check in the context of the function making the call
> - whether it is supported.  Treat AVX512VL specially.  For other flags,
> + whether it is supported.  Treat AVX512VL and MMX specially.  For other 
> flags,
>   if isa includes more than one ISA bit, treat those are requiring any
>   of them.  For AVX512VL, require both AVX512VL and the non-AVX512VL
> - ISAs.  Similarly for 

[PATCH] Improve AVX512* vperm[ti]2* (PR target/82460)

2017-10-09 Thread Jakub Jelinek
Hi!

The vpermt2* and vpermi2* instructions are pretty much the same (at least
when not using non-{z} masking), so by treating them as something
significantly different we generate often very bad code.

The following patch attempts to treat them the same (except for non-{z}
masking), so that the RA can choose whatever is more appropriate.
E.g. in the pr82460-2.c testcase we used to emit vpermt2b which destroys
the index operand, even when we actually need the same index in every
iteration, which means we have to copy it over from some other reg.
While on the pr82460-1.c testcase, there are cases when we want the result
to be in %zmm0, but because we were tied to one choice we had to move the
result from %zmm1 to %zmm0.  Also, the way vpermi2* with non-{z} masking
was emitted had various issues, the RA isn't able to emit two input operands
with different modes both tied to the same "0" constraint, so a match_dup
for the output was used, but that means the middle-end would see an
uninitialized pseudo, clear it and generate say for:
__m512i
f5 (__m512i x, __m512i y, char *z, __mmask64 w)
{
  return _mm512_mask2_permutex2var_epi32 (y, x, w, _mm512_loadu_si512 (z));
}
code like:
vmovdqa64   %zmm0, %zmm2
kmovw   %esi, %k1
vpermi2d(%rdi), %zmm1, %zmm2{%k1}
vmovdqa64   %zmm2, %zmm0
while with the patch we can emit:
kmovw   %esi, %k1
vpermi2d(%rdi), %zmm1, %zmm0{%k1}
ubstead,  So that we don't have too many patterns, I've added 2 mode
iterators for this case which allowed to merge each 3
define_expand/define_insn we had into one (except for the non-{z} masking
we need one define_insn for integral vectors where we can use match_dup
and one for floating vectors where we need to subreg it).

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2017-10-09  Jakub Jelinek  

PR target/82460
* config/i386/sse.md (UNSPEC_VPERMI2, UNSPEC_VPERMI2_MASK): Remove.
(VPERMI2, VPERMI2I): New mode iterators.
(_vpermi2var3_maskz): Remove 3 define_expand patterns.
(_vpermi2var3): Remove 3 define_insn
patterns.
(_vpermi2var3_mask): New define_expand using VPERMI2
mode iterator.  Remove 3 old define_insn patterns.
(*_vpermi2var3_mask): 2 new define_insn patterns.
(_vpermt2var3_maskz): Adjust 1 define_expand to use
VPERMI2 mode iterator, remove the other two expanders.
(_vpermt2var3): Adjust 1 define_insn
to use VPERMI2 mode iterator, add another alternative for vpermi2*
instructions, remove the other two patterns.
(_vpermt2var3_mask): Adjust 1 define_insn to use VPERMI2
mode iterator, remove the other two patterns.
* config/i386/i386.c (ix86_expand_vec_perm_vpermi2): Renamed to ...
(ix86_expand_vec_perm_vpermt2): ... this.  Swap mask and op0
arguments, use gen_*vpermt2* expanders instead of gen_*vpermi2*
and adjust argument order accordingly.
(ix86_expand_vec_perm): Adjust caller.
(expand_vec_perm_1): Likewise.
(expand_vec_perm_vpermi2_vpshub2): Rename to ...
(expand_vec_perm_vpermt2_vpshub2): ... this.
(ix86_expand_vec_perm_const_1): Adjust caller.
(ix86_vectorize_vec_perm_const_ok): Adjust comments.

* gcc.target/i386/pr82460-1.c: New test.
* gcc.target/i386/pr82460-2.c: New test.
* gcc.target/i386/avx512f-vpermt2pd-1.c: Adjust scan-assembler*
regexps to allow vpermt2* to vpermi2* replacement or vice versa
where possible.
* gcc.target/i386/avx512vl-vpermt2pd-1.c: Likewise.
* gcc.target/i386/avx512f-vpermt2d-1.c: Likewise.
* gcc.target/i386/vect-pack-trunc-2.c: Likewise.
* gcc.target/i386/avx512vl-vpermt2ps-1.c: Likewise.
* gcc.target/i386/avx512vl-vpermt2q-1.c: Likewise.
* gcc.target/i386/avx512f-vpermt2ps-1.c: Likewise.
* gcc.target/i386/avx512vl-vpermt2d-1.c: Likewise.
* gcc.target/i386/avx512bw-vpermt2w-1.c: Likewise.
* gcc.target/i386/avx512vbmi-vpermt2b-1.c: Likewise.
* gcc.target/i386/avx512f-vpermt2q-1.c: Likewise.

--- gcc/config/i386/sse.md.jj   2017-10-04 16:45:19.0 +0200
+++ gcc/config/i386/sse.md  2017-10-09 17:44:38.342212895 +0200
@@ -83,9 +83,7 @@ (define_c_enum "unspec" [
   UNSPEC_VSIBADDR
 
   ;; For AVX512F support
-  UNSPEC_VPERMI2
   UNSPEC_VPERMT2
-  UNSPEC_VPERMI2_MASK
   UNSPEC_UNSIGNED_FIX_NOTRUNC
   UNSPEC_UNSIGNED_PCMP
   UNSPEC_TESTM
@@ -18105,96 +18103,48 @@ (define_insn "_vpermil
(set_attr "prefix" "")
(set_attr "mode" "")])
 
-(define_expand "_vpermi2var3_maskz"
-  [(match_operand:VI48F 0 "register_operand")
-   (match_operand:VI48F 1 "register_operand")
-   (match_operand: 2 "register_operand")
-   (match_operand:VI48F 3 "nonimmediate_operand")
-   (match_operand: 4 "register_operand")]
-  "TARGET_AVX512F"
-{
-  emit_insn (gen__vpermi2var3_maskz_1 (
- 

[C++ Patch] PR 82307

2017-10-09 Thread Mukesh Kapoor

Hi,

This patch fixes https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82307.
For an unscoped enum with a fixed underlying type, the function 
type_promotes_to() does not always return the same type as the 
underlying type. The fix is to use the underlying type of the enum 
instead of creating a new one by calling c_common_type_for_size().


Bootstrapped and tested with 'make check' on x86_64-linux. New test case 
added.


Mukesh

Index: gcc/cp/cvt.c
===
--- gcc/cp/cvt.c(revision 253551)
+++ gcc/cp/cvt.c(working copy)
@@ -1854,11 +1854,16 @@
   tree prom = type;
   if (TREE_CODE (prom) == ENUMERAL_TYPE)
prom = ENUM_UNDERLYING_TYPE (prom);
-  if (TYPE_UNSIGNED (prom)
- && ! int_fits_type_p (TYPE_MAX_VALUE (prom), totype))
-   prom = c_common_type_for_size (precision, 1);
-  else
-   prom = totype;
+  // If an unscoped enum has fixed underlying type,
+  // use that type (bug 82307)
+  if (!ENUM_FIXED_UNDERLYING_TYPE_P (type) || SCOPED_ENUM_P (type))
+   {
+ if (TYPE_UNSIGNED (prom)
+ && ! int_fits_type_p (TYPE_MAX_VALUE (prom), totype))
+   prom = c_common_type_for_size (precision, 1);
+ else
+   prom = totype;
+   }
   if (SCOPED_ENUM_P (type))
{
  if (abi_version_crosses (6)
Index: gcc/testsuite/g++.dg/cpp0x/pr_82307.C
===
--- gcc/testsuite/g++.dg/cpp0x/pr_82307.C   (revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/pr_82307.C   (working copy)
@@ -0,0 +1,24 @@
+// PR c++/82307
+// { dg-do compile { target c++11 } }
+
+#include 
+#include 
+
+enum : unsigned long long { VAL };
+
+const char* foo( unsigned long long )
+{
+  return "unsigned long long";
+}
+
+const char* foo( int )
+{
+  return "int";
+}
+
+int main( void )
+{
+  if (strcmp(foo(VAL), "unsigned long long") != 0)
+abort();
+}
+


[PATCH] Fix ICEs with ss{e,e2,se3} builtins with -mno-mmx (PR target/82483)

2017-10-09 Thread Jakub Jelinek
Hi!

The following builtins have {SSE,SSE2,SSSE3} CPUID, yet they have
MMX register operands (either input or output or both).
As -mno-mmx doesn't imply -mno-sse, we get ICEs on these though, because
with MMX disabled it is not possible to emit them.

The following patch cheats and declares these builtins to require
both the MMX and {SSE,SSE2,SSSE3} ISA, making them unavailable in -mno-mmx
code, but I think it is the right thing to do, when somebody uses -mno-mmx,
the intent is usually not to have any instructions touching the MMX register
file and thus needing EMMS etc.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2017-10-09  Jakub Jelinek  

PR target/82483
* config/i386/i386.c (ix86_init_mmx_sse_builtins): Add
OPTION_MASK_ISA_MMX for __builtin_ia32_maskmovq,
__builtin_ia32_vec_ext_v4hi and __builtin_ia32_vec_set_v4hi.
(ix86_expand_builtin): Treat OPTION_MASK_ISA_MMX similarly
to OPTION_MASK_ISA_AVX512VL - builtins that have both
OPTION_MASK_ISA_MMX and some other bit set require both
mmx and the ISAs without the mmx bit.
* config/i386/i386-builtin.def (__builtin_ia32_cvtps2pi,
__builtin_ia32_cvttps2pi, __builtin_ia32_cvtpi2ps,
__builtin_ia32_pavgb, __builtin_ia32_pavgw, __builtin_ia32_pmulhuw,
__builtin_ia32_pmaxub, __builtin_ia32_pmaxsw, __builtin_ia32_pminub,
__builtin_ia32_pminsw, __builtin_ia32_psadbw, __builtin_ia32_pmovmskb,
__builtin_ia32_pshufw, __builtin_ia32_cvtpd2pi,
__builtin_ia32_cvttpd2pi, __builtin_ia32_cvtpi2pd,
__builtin_ia32_pmuludq, __builtin_ia32_pabsb, __builtin_ia32_pabsw,
__builtin_ia32_pabsd, __builtin_ia32_phaddw, __builtin_ia32_phaddd,
__builtin_ia32_phaddsw, __builtin_ia32_phsubw, __builtin_ia32_phsubd,
__builtin_ia32_phsubsw, __builtin_ia32_pmaddubsw,
__builtin_ia32_pmulhrsw, __builtin_ia32_pshufb, __builtin_ia32_psignb,
__builtin_ia32_psignw, __builtin_ia32_psignd): Add OPTION_MASK_ISA_MMX.

* gcc.target/i386/pr82483.c: New test.

--- gcc/config/i386/i386.c.jj   2017-10-09 09:41:21.0 +0200
+++ gcc/config/i386/i386.c  2017-10-09 10:54:05.763679093 +0200
@@ -32988,7 +32988,9 @@ ix86_init_mmx_sse_builtins (void)
UNSIGNED_FTYPE_VOID, IX86_BUILTIN_STMXCSR);
 
   /* SSE or 3DNow!A */
-  def_builtin (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A,
+  def_builtin (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A
+  /* As it uses V4HImode, we have to require -mmmx too.  */
+  | OPTION_MASK_ISA_MMX,
   "__builtin_ia32_maskmovq", VOID_FTYPE_V8QI_V8QI_PCHAR,
   IX86_BUILTIN_MASKMOVQ);
 
@@ -33426,7 +33428,9 @@ ix86_init_mmx_sse_builtins (void)
   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v8hi",
 HI_FTYPE_V8HI_INT, IX86_BUILTIN_VEC_EXT_V8HI);
 
-  def_builtin_const (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A,
+  def_builtin_const (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A
+/* As it uses V4HImode, we have to require -mmmx too.  */
+| OPTION_MASK_ISA_MMX,
 "__builtin_ia32_vec_ext_v4hi",
 HI_FTYPE_V4HI_INT, IX86_BUILTIN_VEC_EXT_V4HI);
 
@@ -33450,7 +33454,9 @@ ix86_init_mmx_sse_builtins (void)
   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_set_v8hi",
 V8HI_FTYPE_V8HI_HI_INT, IX86_BUILTIN_VEC_SET_V8HI);
 
-  def_builtin_const (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A,
+  def_builtin_const (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A
+/* As it uses V4HImode, we have to require -mmmx too.  */
+| OPTION_MASK_ISA_MMX,
 "__builtin_ia32_vec_set_v4hi",
 V4HI_FTYPE_V4HI_HI_INT, IX86_BUILTIN_VEC_SET_V4HI);
 
@@ -37914,18 +37920,23 @@ ix86_expand_builtin (tree exp, rtx targe
  Originally the builtin was not created if it wasn't applicable to the
  current ISA based on the command line switches.  With function specific
  options, we need to check in the context of the function making the call
- whether it is supported.  Treat AVX512VL specially.  For other flags,
+ whether it is supported.  Treat AVX512VL and MMX specially.  For other 
flags,
  if isa includes more than one ISA bit, treat those are requiring any
  of them.  For AVX512VL, require both AVX512VL and the non-AVX512VL
- ISAs.  Similarly for 64BIT, but we shouldn't be building such builtins
+ ISAs.  Likewise for MMX, require both MMX and the non-MMX ISAs.
+ Similarly for 64BIT, but we shouldn't be building such builtins
  at all, -m64 is a whole TU option.  */
   if (((ix86_builtins_isa[fcode].isa
-   & ~(OPTION_MASK_ISA_AVX512VL | OPTION_MASK_ISA_64BIT))
+   & ~(OPTION_MASK_ISA_AVX512VL | OPTION_MASK_ISA_MMX
+   | OPTION_MASK_ISA_64BIT))

[PATCH, i386]: Remove reversed jcc insn patterns

2017-10-09 Thread Uros Bizjak
Hello!

Similar to Segher's rs6000 patch [1], attached patch removes redundant
reversed jcc insn patterns.

2017-10-09  Uros Bizjak  

* config/i386/i386.md (*jcc_2): Remove insn pattern.
(*jcc_0_r_i387): Ditto.
(*jccxf_r_i387): Ditto.
(*jcc_r_i387): Ditto.
(*jccu_r_i387): Ditto.
(*jcc__r_i387): Ditto.
(*jcc): Rename from *jcc_1.

[1] https://gcc.gnu.org/ml/gcc-patches/2017-10/msg00451.html

Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}. I have
also compared several Polyhedron asm dumps before and after the patch,
and there were no differences (with -m32 -march=i386, w/ and w/o
-ffast-math).

Committed to mainline SVN.

Uros.
diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
index 99497a9..1a794c0 100644
--- a/gcc/config/i386/i386.md
+++ b/gcc/config/i386/i386.md
@@ -11963,7 +11963,7 @@
 ;; Basic conditional jump instructions.
 ;; We ignore the overflow flag for signed branch instructions.
 
-(define_insn "*jcc_1"
+(define_insn "*jcc"
   [(set (pc)
(if_then_else (match_operator 1 "ix86_comparison_operator"
  [(reg FLAGS_REG) (const_int 0)])
@@ -11983,26 +11983,6 @@
  (const_int 6)))
(set_attr "maybe_prefix_bnd" "1")])
 
-(define_insn "*jcc_2"
-  [(set (pc)
-   (if_then_else (match_operator 1 "ix86_comparison_operator"
- [(reg FLAGS_REG) (const_int 0)])
- (pc)
- (label_ref (match_operand 0]
-  ""
-  "%!%+j%c1\t%l0"
-  [(set_attr "type" "ibr")
-   (set_attr "modrm" "0")
-   (set (attr "length")
-   (if_then_else
- (and (ge (minus (match_dup 0) (pc))
-  (const_int -126))
-  (lt (minus (match_dup 0) (pc))
-  (const_int 128)))
- (const_int 2)
- (const_int 6)))
-   (set_attr "maybe_prefix_bnd" "1")])
-
 ;; In general it is not safe to assume too much about CCmode registers,
 ;; so simplify-rtx stops when it sees a second one.  Under certain
 ;; conditions this is safe on x86, so help combine not create
@@ -12069,19 +12049,6 @@
   "TARGET_80387 && !TARGET_CMOVE"
   "#")
 
-(define_insn "*jcc_0_r_i387"
-  [(set (pc)
-   (if_then_else (match_operator:CCFP 0 "ix86_fp_comparison_operator"
-   [(match_operand:X87MODEF 1 "register_operand" "f")
-(match_operand:X87MODEF 2 "const0_operand")])
- (pc)
- (label_ref (match_operand 3
-   (clobber (reg:CCFP FPSR_REG))
-   (clobber (reg:CCFP FLAGS_REG))
-   (clobber (match_scratch:HI 4 "=a"))]
-  "TARGET_80387 && !TARGET_CMOVE"
-  "#")
-
 (define_insn "*jccxf_i387"
   [(set (pc)
(if_then_else (match_operator:CCFP 0 "ix86_fp_comparison_operator"
@@ -12095,19 +12062,6 @@
   "TARGET_80387 && !TARGET_CMOVE"
   "#")
 
-(define_insn "*jccxf_r_i387"
-  [(set (pc)
-   (if_then_else (match_operator:CCFP 0 "ix86_fp_comparison_operator"
-   [(match_operand:XF 1 "register_operand" "f")
-(match_operand:XF 2 "register_operand" "f")])
- (pc)
- (label_ref (match_operand 3
-   (clobber (reg:CCFP FPSR_REG))
-   (clobber (reg:CCFP FLAGS_REG))
-   (clobber (match_scratch:HI 4 "=a"))]
-  "TARGET_80387 && !TARGET_CMOVE"
-  "#")
-
 (define_insn "*jcc_i387"
   [(set (pc)
(if_then_else (match_operator:CCFP 0 "ix86_fp_comparison_operator"
@@ -12121,19 +12075,6 @@
   "TARGET_80387 && !TARGET_CMOVE"
   "#")
 
-(define_insn "*jcc_r_i387"
-  [(set (pc)
-   (if_then_else (match_operator:CCFP 0 "ix86_fp_comparison_operator"
-   [(match_operand:MODEF 1 "register_operand" "f")
-(match_operand:MODEF 2 "nonimmediate_operand" "fm")])
- (pc)
- (label_ref (match_operand 3
-   (clobber (reg:CCFP FPSR_REG))
-   (clobber (reg:CCFP FLAGS_REG))
-   (clobber (match_scratch:HI 4 "=a"))]
-  "TARGET_80387 && !TARGET_CMOVE"
-  "#")
-
 (define_insn "*jccu_i387"
   [(set (pc)
(if_then_else (match_operator:CCFPU 0 "ix86_fp_comparison_operator"
@@ -12147,19 +12088,6 @@
   "TARGET_80387 && !TARGET_CMOVE"
   "#")
 
-(define_insn "*jccu_r_i387"
-  [(set (pc)
-   (if_then_else (match_operator:CCFPU 0 "ix86_fp_comparison_operator"
-   [(match_operand:X87MODEF 1 "register_operand" "f")
-(match_operand:X87MODEF 2 "register_operand" "f")])
- (pc)
- (label_ref (match_operand 3
-   (clobber (reg:CCFP FPSR_REG))
-   (clobber (reg:CCFP FLAGS_REG))
-   (clobber (match_scratch:HI 4 "=a"))]
-  "TARGET_80387 && !TARGET_CMOVE"
-  "#")
-
 (define_split
   [(set (pc)
(if_then_else (match_operator 0 "ix86_fp_comparison_operator"
@@ -12219,23 +12147,6 @@
|| optimize_function_for_size_p (cfun))"
   "#")
 
-(define_insn "*jcc__r_i387"
-  [(set (pc)
-   (if_then_else
- (match_operator:CCFP 0 "ix86_swapped_fp_comparison_operator"
-   

[PATCH] Enable ifunc attribute by default for ARM GNU/Linux

2017-10-09 Thread Adhemerval Zanella
Similar to other architectures with IFUNC binutils/glibc support, this
patch enables the ifunc attribute for ARM GNU/Linux.  Although not
required for build master GLIBC, the intention is to allow refactor
its assembly implementation to C [1].

Tested compilation of glibc (in conjunction with a glibc patch to
support using the attribute on ARM) with build-many-glibcs.py (with
a patch to add a armv7 variant which enables multiarch).  I have
not run the GCC tests for ARM.

Adhemerval Zanella  

* config.gcc (default_gnu_indirect_function): Default to yes for
arm*-*-linux* with glibc.

[1] https://sourceware.org/ml/libc-alpha/2017-10/msg00334.html
---
 gcc/ChangeLog  | 5 +
 gcc/config.gcc | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/gcc/config.gcc b/gcc/config.gcc
index 91a55e8..26aa8f6 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -3104,7 +3104,7 @@ case ${target} in
 ;;
 *-*-linux*)
case ${target} in
-   aarch64*-* | i[34567]86-* | powerpc*-* | s390*-* | sparc*-* | x86_64-*)
+   aarch64*-* | i[34567]86-* | powerpc*-* | s390*-* | sparc*-* | x86_64-* 
| arm*-*)
default_gnu_indirect_function=yes
;;
esac
-- 
2.7.4



[Ada] Suppress checks within finalizers

2017-10-09 Thread Pierre-Marie de Rodat
This patch suppresses checks within finalizer routines, because they can't
fail. No change in behavior; no test available. This is just an internal
cleanup.

Tested on x86_64-pc-linux-gnu, committed on trunk

2017-10-09  Bob Duff  

* exp_ch7.adb (Create_Finalizer): Suppress checks within the finalizer.

Index: exp_ch7.adb
===
--- exp_ch7.adb (revision 253546)
+++ exp_ch7.adb (working copy)
@@ -1955,7 +1955,7 @@
Insert_After (Finalizer_Insert_Nod, Fin_Body);
 end if;
 
-Analyze (Fin_Body);
+Analyze (Fin_Body, Suppress => All_Checks);
  end if;
   end Create_Finalizer;
 


Re: [PATCH] Add a warning for invalid function casts

2017-10-09 Thread Martin Sebor

On 10/09/2017 11:50 AM, Bernd Edlinger wrote:

On 10/09/17 18:44, Martin Sebor wrote:

On 10/07/2017 10:48 AM, Bernd Edlinger wrote:

Hi!

I think I have now something useful, it has a few more heuristics
added, to reduce the number of false-positives so that it
is able to find real bugs, for instance in openssl it triggers
at a function cast which has already a TODO on it.

The heuristics are:
- handle void (*)(void) as a wild-card function type.
- ignore volatile, const qualifiers on parameters/return.
- handle any pointers as equivalent.
- handle integral types, enums, and booleans of same precision
   and signedness as equivalent.
- stop parameter validation at the first "...".


These sound quite reasonable to me.  I have a reservation about
just one of them, and some comments about other aspects of the
warning.  Sorry if this seems like a lot.  I'm hoping you'll
find the feedback constructive.

I don't think using void(*)(void) to suppress the warning is
a robust solution because it's not safe to call a function that
takes arguments through such a pointer (especially not if one
or more of the arguments is a pointer).  Depending on the ABI,
calling a function that expects arguments with none could also
mess up the stack as the callee may pop arguments that were
never passed to it.



This is of course only a heuristic, and if there is no warning
that does not mean any guarantee that there can't be a problem
at runtime.  The heuristic is only meant to separate the
bad from the very bad type-cast.  In my personal opinion there
is not a single good type cast.


I agree.  Since the warning uses one kind of a cast as an escape
mechanism from the checking it should be one whose result can
the most likely be used to call the function without undefined
behavior.

Since it's possible to call any function through a pointer to
a function with no arguments (simply by providing arguments of
matching types) it's a reasonable candidate.

On the other hand, since it is not safe to call an arbitrary
function through void (*)(void), it's not as good a candidate.

Another reason why I think a protoype-less function is a good
choice is because the alias and ifunc attributes already use it
as an escape mechanism from their type incompatibility warning.

Martin



Re: [COMMITTED][testsuite] Fix ssa-dse-26.c

2017-10-09 Thread Jeff Law
On 10/09/2017 05:01 AM, Wilco Dijkstra wrote:
> Add missing -fno-short-enums to ensure this test passes on arm-none-eabi
> which uses short enums.
> 
> Committed as obvious in r253540.
> 
> ChangeLog:
> 2017-10-09  Wilco Dijkstra  
> 
> * gcc.dg/tree-ssa/ssa-dse-26.c (dg-options): Add -fno-short-enums.
> 
THanks.  Sorry for the breakage.

Jeff


Re: [PATCH] Fortran -- Handle BOZ in accordance with F2008/2015.

2017-10-09 Thread Steve Kargl
On Mon, Oct 09, 2017 at 06:48:33PM +0200, Dominique d'Humières wrote:
> 
> > Le 7 oct. 2017 à 17:48, Steve Kargl  a 
> > écrit :
> > 
> > On Sat, Oct 07, 2017 at 12:37:03PM +0200, Dominique d'Humières wrote:
> >> (4) Compiling
> >> 
> >> print *, INT(z'',4)
> >> end
> >> 
> >> gives
> >> 
> >> print *, INT(z'',4)
> >> 1
> >> Error: Arithmetic overflow converting INTEGER(-1) to INTEGER(4)
> >> at (1). This check can be disabled with the option '-fno-range-check’
> >> 
> >> Should not it be -1?
> > 
> > Maybe. :-)
> > 
> > See my note to Jerry about needing to implement F2015 16.3.3 correctly.
> > Upon sleeping on this deficiency, I realized that 16.3.3 without stating
> > allows one to set the sign-bit.  We find in 16.3.1 the statement
> 
> s/16/13/?

Yes.  F2008 is 13.  F2015 is 16.

> > 
> >   The interpretation of a negative integer as a sequence of bits
> >   is processor dependent.
> > 
> > There is the bit model and integer model numbers.  F2015 contrasts the
> > models and concludes with 
> > 
> >   In particular, whereas the models are identical for r = 2 and
> >   $w_{z-1}$ = 0, they do not correspond for r = 2 or $w_{z-1} = 1$
> >   and the interpretation of bits in such objects is processor dependent.
> 
> I am not sure this is relevant.  The problem here is not about bit
> interpretation, but how you fill 32 bits with a 32-bit pattern.
> 
> IMO 'INT(z'',4)' should return an integer(4) with all its
> bits set to one.

Yes, of course, but one of those bits is a sign-bit.  What gfortran
does at the moment is take a boz, converts it to an mpz_t entity
and sets the kind to gfc_max_integer_kind.  The mpz_t entity is 
nonnegative.   When the boz is used in the context of an INTEGER,
gfortran does a conversion (if necessary), and then typically calls
range_check().  gfortran will issue an error.  However, because 
the interpretation of a sing-bit is processori dependent, the error
is not needed nor desired for under F2008 and F2015.  Likewise, I
think the error can be removed for nan = real(z'fff',4).

> 
> (7) libgomp/testsuite/libgomp.fortran/aligned1.f03 should be changed as 
> gcc/testsuite/gfortran.dg/graphite/id-26.f03:
> 
> --- ../_clean/libgomp/testsuite/libgomp.fortran/aligned1.f03  2017-09-28 
> 11:35:02.0 +0200
> +++ libgomp/testsuite/libgomp.fortran/aligned1.f032017-10-09 
> 18:29:25.0 +0200
> @@ -52,11 +52,11 @@
>! Attempt to create 64-byte aligned allocatable
>do i = 1, 64
>  allocate (c(1023 + i))
> -if (iand (loc (c(1)), 63) == 0) exit
> +if (iand (int(loc (c(1)), 8), 63_8) == 0) exit
>  deallocate (c)
>  allocate (b(i)%a(1023 + i))
>  allocate (c(1023 + i))
> -if (iand (loc (c(1)), 63) == 0) exit
> +if (iand (int(loc (c(1)), 8), 63_8) == 0) exit
>  deallocate (c)
>end do
>if (allocated (c)) then
> 
> otherwise it fails with -m64.

I don't use -m32 and -m64.  Using these options with the testsuite
is silly.  Once, my patch hits the tree if this failure is still
present, then you can fix it with 

if (iand (int(loc (c(1)), kind(63)), 63) == 0) exit

Note, loc() returns an integer with a kind defined by 
gfc_index_integer_kind = get_int_kind_from_name (PTRDIFF_TYPE);

I'm not surprised that PTRDIFF_TYPE may change depending of the
underlying pointer type.
 
> (8) In gfortran.dg/unf_io_convert_2.f90, why is
> 
> integer(1), parameter :: b1 = z'11’, …

This is a GNU Fortran extension.  I retained the extension
as I worked on the patch.  b1 is a named constant, and the
rhs side is an initialization expression that reduces to a
constant.   Here, the constant is a boz and one can easily 
grab the type and kind from the LHS.  Note, this patch isn't
strictly needed any longer, because I've found a way to allow
a BOZ to be used in an array constructor (another dubious
extension).

> 
> valid, but not
> 
> integer(1) :: b1
> b1 = z’11’
> 

GNU Fortran has a dubious extension that allows a BOZ in
an expression.  This may be an accident from my ~13 year
old decision (primary -r95643) to convert a boz to
integer(gfc_max_integer_kind) when a boz is matched.  A boz
is a typeless and kindless entity (in F2008 and F2015).  The
RHS of an expression is evaluated without reference to the LHS.
What type and kind should be used for z'11'.  For

b1 = z'11' + 0

I allow mixed-mode math to convert z'11' to the type and kind
of 0.  This expression is basically b1 = int(int(z'11',kind(0))+0,kind(b1)).

If we want to retain the extension the resolve.c probably
needs an update to handle UNARY_PLUS and UNARY_MINUS.

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


Re: [PATCH] Add a warning for invalid function casts

2017-10-09 Thread Bernd Edlinger
On 10/09/17 18:44, Martin Sebor wrote:
> On 10/07/2017 10:48 AM, Bernd Edlinger wrote:
>> Hi!
>>
>> I think I have now something useful, it has a few more heuristics
>> added, to reduce the number of false-positives so that it
>> is able to find real bugs, for instance in openssl it triggers
>> at a function cast which has already a TODO on it.
>>
>> The heuristics are:
>> - handle void (*)(void) as a wild-card function type.
>> - ignore volatile, const qualifiers on parameters/return.
>> - handle any pointers as equivalent.
>> - handle integral types, enums, and booleans of same precision
>>    and signedness as equivalent.
>> - stop parameter validation at the first "...".
> 
> These sound quite reasonable to me.  I have a reservation about
> just one of them, and some comments about other aspects of the
> warning.  Sorry if this seems like a lot.  I'm hoping you'll
> find the feedback constructive.
> 
> I don't think using void(*)(void) to suppress the warning is
> a robust solution because it's not safe to call a function that
> takes arguments through such a pointer (especially not if one
> or more of the arguments is a pointer).  Depending on the ABI,
> calling a function that expects arguments with none could also
> mess up the stack as the callee may pop arguments that were
> never passed to it.
> 

This is of course only a heuristic, and if there is no warning
that does not mean any guarantee that there can't be a problem
at runtime.  The heuristic is only meant to separate the
bad from the very bad type-cast.  In my personal opinion there
is not a single good type cast.

> Instead, I think the warning should be suppressed for casts to
> function types without a prototype.  Calling those is (or should
> for the most part be) safe and they are the natural way to express
> that we don't care about type safety.
> 
> Let me also clarify that I understand bullet 4 correctly.
> In my tests the warning triggers on enum/integral/boolean
> incompatibilities that the text above suggests should be accepted.
>   E.g.:
> 
>    typedef enum E { e } E;
>    E f (void);
> 
>    typedef int F (void);
> 
>    F *pf = (F *)f;   // -Wcast-function-type
> 
> Is the warning here intended?  (My reading of the documentation
> suggests it's not.)
> 

Aehm no, that is unintentional, thanks for testing...

It looks like the warning does not trigger with
typedef unsigned int F (void);

But this enum should promote to int, likewise for _Bool,
So I think this should be fixable.


> In testing the warning in C++, I noticed it's not issued for
> casts between incompatible pointers to member functions, or for
> casts between member functions to ordinary functions (those are
> diagnosed with -Wpedantic
> 
>    struct S { void foo (int*); };
> 
>    typedef void (S::*MF)(int);
>    typedef void F (int*);
> 
>    MF pmf = (MF)::foo;   // no warning
>    F *pf = (F*)::foo;    // -Wpedantic only
> 
> These both look like they would be worth diagnosing under the new
> option (the second one looks like an opportunity to provide
> a dedicated option to control the existing pedantic warning).
> 

Yes I agree.

I think all pointer-to member function casts where the types
are different should warn, although I don't have seen any of that
crap so far.


>> I cannot convince myself to handle uintptr_t and pointers as
>> equivalent.  It is possible that targets like m68k have
>> an ABI where uintptr_t and void* are different as return values
>> but are identical as parameter values.
>>
>> IMHO adding an exception for uintptr_t vs. pointer as parameters
>> could easily prevent detection of real bugs.  Even if it is safe
>> for all targets.
>>
>> However it happens: Examples are the libiberty splay-tree functions,
>> and also one single place in linux, where an argument of type
>> "long int" is used to call a timer function with a pointer
>> argument.  Note, linux does not enable -Wextra.
>>
>>
>> Patch was bootstrapped and reg-tested on x86_64-pc-linux-gnu.
>> Is it OK for trunk?
> 
> A few comments on the documentation:
> 
>    When one of the function types uses variable arguments like this
>    @code{int f(...);}, then only the return value and the parameters
>    before the @code{...} are checked,
> 
> Although G++ accepts 'int f(...)' since GCC does not I would suggest
> to avoid showing the prototype in the descriptive text and instead
> refer to "functions taking variable arguments."   Also, it's the
> types of the arguments that are considered (not the value).  With
> that I would suggest rewording the sentence along these lines:
>  >    In a cast involving a function types with a variable argument
>    list only the types of initial arguments that are provided are
>    considered.
> 
> The sentence
> 
>    Any benign differences in integral types are ignored...
> 
> leaves open the question of what's considered benign.  In my view,
> if pointer types are ignored (which is reasonable as we discussed
> but which can lead to serious 

Re: [PATCH], Add PowerPC ISA 3.0 Atomic Memory Operation functions

2017-10-09 Thread Michael Meissner
On Mon, Oct 09, 2017 at 11:03:10AM -0500, Segher Boessenkool wrote:
> On Fri, Oct 06, 2017 at 02:30:16PM -0400, Michael Meissner wrote:
> > Here is the revised amo.h.  I tested the two test files amo1.c and amo2.c, 
> > and
> > they both compile.  It is interesting, use %P0 results in fewer addi's than 
> > the
> > older one (there were redunant addi's in passing the address).  Can I check 
> > it
> > in?
> > 
> > [gcc]
> > 2017-10-06  Michael Meissner  
> > 
> > * config/rs6000/amo.h: New include file to provide ISA 3.0 atomic
> > memory operation instruction support.
> > * config.gcc (powerpc*-*-*): Include amo.h as an extra header.
> > (rs6000-ibm-aix[789]*): Likewise.
> > * doc/extend.texi (PowerPC Atomic Memory Operation Functions):
> > Document new functions.
> > 
> > [gcc/testsuite]
> > 2017-10-06  Michael Meissner  
> > 
> > * gcc.target/powerpc/amo1.c: New test.
> > * gcc.target/powerpc/amo2.c: Likewise.
> 
> > --- gcc/testsuite/gcc.target/powerpc/amo1.c (revision 0)
> > +++ gcc/testsuite/gcc.target/powerpc/amo1.c (revision 0)
> > @@ -0,0 +1,253 @@
> > +/* { dg-do compile { target { powerpc64*-*-* && lp64 } } } */
> > +/* { dg-require-effective-target powerpc_p9vector_ok } */
> > +/* { dg-options "-mpower9-vector -mpower9-misc -O2" } */
> 
> Should this be powerpc*-*-* instead?

It needs 64-bit because it requries a __int128_t temporary to get two adjacent
GPR registers.  I'll change it to powerpc*-*-* && lp64.

> Okay for trunk with that taken care of.  Thanks!

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



Re: [PATCH] Fix PR80295[aarch64] [7/8 Regression] ICE in __builtin_update_setjmp_buf expander

2017-10-09 Thread Qing Zhao

> On Oct 9, 2017, at 11:27 AM, Qing Zhao  wrote:
> 
>> 
>> On Oct 9, 2017, at 5:33 AM, Richard Earnshaw (lists) 
>>  wrote:
>> 
>> On 06/10/17 20:56, Qing Zhao wrote:
>>> Thanks a lot for Wilco’s help on this bug. 
>>> 
>>> Yes, Aarch64 does NOT do anything wrong.  
>>> 
>>> The implementation of __builtin_update_setjmp_buf is not correct. It takes 
>>> a pointer
>>> as an operand and treats the Mode of the pointer as Pmode, which is not 
>>> correct.
>>> a conversion from ptr_mode to Pmode is needed for this pointer.
>>> 
>>> bootstrapped on aarch64-unknown-linux-gnu.
>>> testing on aarch64-unknown-linux-gnu is running.
>>> 
>> 
>> This is more believable for AArch64, but we need to be careful here.  I
>> think this needs testing on at least one other target that has a
>> ilp32-on-64-bit ABI, eg x86_64's x32 ABI.
> 
> I just built the latest upstream GCC on x86_64 Linux. and use it to compile 
> the testing case in PR80295 with the following options:
> 
> [qinzhao@qzh-ol6-test 80295]$ cat t.c
> void f (void *b) { __builtin_update_setjmp_buf (b); }
> [qinzhao@qzh-ol6-test 80295]$ sh t
> /home/qinzhao/Install/latest/bin/gcc -m32 t.c
> 
> it compiles successfully on x86_64.  no similar issue as aarch64. 
> 
> DId  I use the correct option on X86 (i.e -m32)?

I also tried -mx32,  the compilation had no issue. 

With the latest GCC + my patch, on X86,  the testing case still has No any 
issue with -m32 or -mx32. 

my testing on aarch64-unknown-linux-gnu has finished, no any regression. 

Is my patch Okay?

thanks.

Qing



Go patch committed to GCC 7 branch: Update MIPS architecture names

2017-10-09 Thread Ian Lance Taylor
I've committed a set of patches by James Cowgill to the GCC 7 branch,
backported from trunk.  These patches update the MIPS architecture
names to the names expected by Go programmers.  The backported patches
are:
https://golang.org/cl/46150
https://golang.org/cl/46151
https://golang.org/cl/46152
https://golang.org/cl/46153
https://golang.org/cl/46154
https://gcc.gnu.org/ml/gcc-patches/2017-06/msg01777.html

Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to GCC 7 branch.

Ian

2017-10-09  James Cowgill  

* go.test/go-test.exp (go-set-goarch): Update MIPS architecture names.
Index: gcc/testsuite/go.test/go-test.exp
===
--- gcc/testsuite/go.test/go-test.exp   (revision 253547)
+++ gcc/testsuite/go.test/go-test.exp   (working copy)
@@ -213,29 +213,27 @@
#error FOO
#endif
}] {
-   set goarch "mipso32"
+   set goarch "mips"
} elseif [check_no_compiler_messages mipsn32 assembly {
#if _MIPS_SIM != _ABIN32
#error FOO
#endif
}] {
-   set goarch "mipsn32"
+   set goarch "mips64p32"
} elseif [check_no_compiler_messages mipsn64 assembly {
#if _MIPS_SIM != _ABI64
#error FOO
#endif
}] {
-   set goarch "mipsn64"
-   } elseif [check_no_compiler_messages mipso64 assembly {
-   #if _MIPS_SIM != _ABIO64
-   #error FOO
-   #endif
-   }] {
-   set goarch "mipso64"
+   set goarch "mips64"
} else {
perror "$target_triplet: unrecognized MIPS ABI"
return ""
}
+
+   if [istarget "mips*el-*-*"] {
+   append goarch "le"
+   }
}
"powerpc*-*-*" {
if [check_effective_target_ilp32] {
Index: libgo/configure.ac
===
--- libgo/configure.ac  (revision 253547)
+++ libgo/configure.ac  (working copy)
@@ -197,7 +197,7 @@
 # supported by the gofrontend and all architectures supported by the
 # gc toolchain.
 # N.B. Keep in sync with gcc/testsuite/go.test/go-test.exp (go-set-goarch).
-ALLGOARCH="386 alpha amd64 amd64p32 arm armbe arm64 arm64be ia64 m68k mipso32 
mipsn32 mipso64 mipsn64 mips mipsle mips64 mips64le mips64p32 mips64p32le ppc 
ppc64 ppc64le s390 s390x sparc sparc64"
+ALLGOARCH="386 alpha amd64 amd64p32 arm armbe arm64 arm64be ia64 m68k mips 
mipsle mips64 mips64le mips64p32 mips64p32le ppc ppc64 ppc64le s390 s390x sparc 
sparc64"
 
 # All known GOARCH_FAMILY values.
 ALLGOARCHFAMILY="I386 ALPHA AMD64 ARM ARM64 IA64 M68K MIPS MIPS64 PPC PPC64 
S390 S390X SPARC SPARC64"
@@ -280,18 +280,12 @@
 #error not n64
 #endif],
 [mips_abi="n64"],
-   [AC_COMPILE_IFELSE([
-#if _MIPS_SIM != _ABIO64
-#error not o64
-#endif],
-[mips_abi="o64"],
[AC_MSG_ERROR([unknown MIPS ABI])
-[mips_abi="n32"]])])])])
+[mips_abi="n32"]])])])
 case "$mips_abi" in
-"o32") GOARCH=mipso32 ;;
-"n32") GOARCH=mipsn32 ;;
-"n64") GOARCH=mipsn64 ;;
-"o64") GOARCH=mipso64 ;;
+"o32") GOARCH=mips ;;
+"n32") GOARCH=mips64p32 ;;
+"n64") GOARCH=mips64 ;;
 esac
 case "$mips_abi" in
 "o32" | "n32")
@@ -298,13 +292,14 @@
 GOARCH_FAMILY=MIPS
GOARCH_MINFRAMESIZE=4
 ;;
-"n64" | "o64")
+"n64")
 GOARCH_FAMILY=MIPS64
GOARCH_MINFRAMESIZE=8
 ;;
 esac
 case "${host}" in
-mips*el)
+mips*el-*-*)
+GOARCH="${GOARCH}le"
 ;;
 *)
GOARCH_BIGENDIAN=1
@@ -569,7 +564,7 @@
 
 GCC_CHECK_UNWIND_GETIPINFO
 
-AC_CHECK_HEADERS(port.h sched.h semaphore.h sys/file.h sys/mman.h syscall.h 
sys/epoll.h sys/event.h sys/inotify.h sys/ptrace.h sys/syscall.h sys/user.h 
sys/utsname.h sys/select.h sys/socket.h net/if.h net/if_arp.h net/route.h 
netpacket/packet.h sys/prctl.h sys/mount.h sys/vfs.h sys/statfs.h sys/timex.h 
sys/sysinfo.h utime.h linux/ether.h linux/fs.h linux/reboot.h netinet/icmp6.h 
netinet/in_syst.h netinet/ip.h netinet/ip_mroute.h netinet/if_ether.h)
+AC_CHECK_HEADERS(port.h sched.h semaphore.h sys/file.h sys/mman.h syscall.h 
sys/epoll.h sys/event.h sys/inotify.h sys/ptrace.h sys/syscall.h sys/user.h 
sys/utsname.h sys/select.h sys/socket.h net/if.h net/if_arp.h net/route.h 
netpacket/packet.h sys/prctl.h sys/mount.h sys/vfs.h sys/statfs.h sys/timex.h 
sys/sysinfo.h utime.h linux/ether.h linux/fs.h linux/ptrace.h linux/reboot.h 
netinet/icmp6.h netinet/in_syst.h netinet/ip.h netinet/ip_mroute.h 
netinet/if_ether.h)
 
 AC_CHECK_HEADERS([linux/filter.h linux/if_addr.h linux/if_ether.h 
linux/if_tun.h linux/netlink.h linux/rtnetlink.h], [], [],
 [#ifdef HAVE_SYS_SOCKET_H
Index: libgo/go/cmd/cgo/main.go

Re: [committed] s390 vec_xor fix (PR target/82464)

2017-10-09 Thread Andreas Krebbel
On 10/09/2017 01:42 PM, Jakub Jelinek wrote:
> Hi!
> 
> I've committed following patch which has been preapproved by Andreas in the
> PR.  No testcase right now, it will be covered by testsuite later together
> with all the other intrinsics.
> 
> 2017-10-09  Jakub Jelinek  
> 
>   PR target/82464
>   * config/s390/s390-builtins.def (s390_vec_xor_flt_a,
>   s390_vec_xor_flt_b, s390_vec_xor_flt_c): New.

Thanks!

-Andreas-



Re: [PATCH, rs6000] Add Power 8 support to vec_revb

2017-10-09 Thread Segher Boessenkool
Hi Carl,

On Mon, Oct 09, 2017 at 08:36:57AM -0700, Carl Love wrote:
>   *gcc.target/powerpc/builtins-revb-runnable.c: New
>   runnable test file for the vec_revb builtin.

(Missing space after the asterisk).

> diff --git a/gcc/config/rs6000/vsx.md b/gcc/config/rs6000/vsx.md
> index b47eeac..fccde97 100644
> --- a/gcc/config/rs6000/vsx.md
> +++ b/gcc/config/rs6000/vsx.md
> @@ -4712,6 +4712,94 @@
>"xxbrw %x0,%x1"
>[(set_attr "type" "vecperm")])
>  
> +;; Swap all bytes in each 32-bit element

Elements aren't always 32 bits; commment out of date?

> +(define_expand "revb_"
> +  [(set (match_operand:VSX_L 0 "vsx_register_operand" "=wa")
> +  (bswap:VSX_L (match_operand:VSX_L 1 "vsx_register_operand" "wa")))]

"bswap" should align with the "match_operand", if you can.  Constraints
in expands are not useful, just drop those :-)

> +  "TARGET_P9_VECTOR || TARGET_VSX"

TARGET_VSX is always set if TARGET_P9_VECTOR is, so drop the latter?

> +{
> +  int vals[16];
> +  rtx mask = gen_reg_rtx (V16QImode);
> +  int i;
> +  rtvec v;
> +  rtx rvals[16];
> +
> +  if (TARGET_P9_VECTOR)
> +{
> +   if (mode == V1TImode)
> +  emit_insn (gen_p9_xxbrq_v1ti (operands[0], operands[1]));
> +   else if (mode == V2DImode)
> +  emit_insn (gen_p9_xxbrd_v2di (operands[0], operands[1]));
> +   else if (mode == V2DFmode)
> +  emit_insn (gen_p9_xxbrd_v2df (operands[0], operands[1]));
> +   else if (mode == V4SImode)
> +  emit_insn (gen_p9_xxbrw_v4si (operands[0], operands[1]));
> +   else if (mode == V4SFmode)
> +  emit_insn (gen_p9_xxbrw_v4sf (operands[0], operands[1]));
> +   else if (mode == V8HImode)
> +  emit_insn (gen_p9_xxbrh_v8hi (operands[0], operands[1]));
> +   else if (mode == V16QImode)
> +  emit_insn (gen_p9_xxbrq_v16qi (operands[0], operands[1]));
> +}

  if (TARGET_P9_VECTOR)
emit_insn (gen_p9_xxbr_ (operands[0], operands[1]);

(Mode attributes are great!  And indent by two spaces).

> +  else
> +{
> +  if (mode == V1TImode)
> +{
> +   vals[0] = 15; vals[1] = 14; vals[2] = 13; vals[3] = 12;
> +   vals[4] = 11; vals[5] = 10; vals[6] = 9; vals[7] = 8;
> +   vals[8] = 7; vals[9] = 6; vals[10] = 5; vals[11] = 4;
> +   vals[12] = 3; vals[13] = 2; vals[14] = 1; vals[15] = 0;
> +}
> +  else if ((mode == V2DImode) || (mode == V2DFmode))
> +{
> +   vals[0] = 7; vals[1] = 6; vals[2] = 5; vals[3] = 4;
> +   vals[4] = 3; vals[5] = 2; vals[6] = 1; vals[7] = 0;
> +   vals[8] = 15; vals[9] = 14; vals[10] = 13; vals[11] = 12;
> +   vals[12] = 11; vals[13] = 10; vals[14] = 9; vals[15] = 8;
> +}
> +  else if ((mode == V4SImode) || (mode == V4SFmode))
> +{
> +   vals[0] = 3; vals[1] = 2; vals[2] = 1; vals[3] = 0;
> +   vals[4] = 7; vals[5] = 6; vals[6] = 5; vals[7] = 4;
> +   vals[8] = 11; vals[9] = 10; vals[10] = 9; vals[11] = 8;
> +   vals[12] = 15; vals[13] = 14; vals[14] = 13; vals[15] = 12;
> +}
> +  else if (mode == V8HImode)
> +{
> +   vals[0] = 1; vals[1] = 0; vals[2] = 3; vals[3] = 2;
> +   vals[4] = 5; vals[5] = 4; vals[6] = 7; vals[7] = 6;
> +   vals[8] = 9; vals[9] = 8; vals[10] = 11; vals[11] = 10;
> +   vals[12] = 13; vals[13] = 12; vals[14] = 15; vals[15] = 14;
> +}
> +  else if (mode == V16QImode)
> +{
> +   vals[0] = 15; vals[1] = 14; vals[2] = 13; vals[3] = 12;
> +   vals[4] = 11; vals[5] = 10; vals[6] = 9; vals[7] = 8;
> +   vals[8] = 7; vals[9] = 6; vals[10] = 5; vals[11] = 4;
> +   vals[12] = 3; vals[13] = 2; vals[14] = 1; vals[15] = 0;
> +}
> +  else
> +{
> +   vals[0] = 0; vals[1] = 0; vals[2] = 0; vals[3] = 0;
> +   vals[4] = 0; vals[5] = 0; vals[6] = 0; vals[7] = 0;
> +   vals[8] = 0; vals[9] = 0; vals[10] = 0; vals[11] = 0;
> +   vals[12] = 0; vals[13] = 0; vals[14] = 0; vals[15] = 0;
> +}

What is this last one for?  It seems bogus.

> +  for (i = 0; i < 16; i++)
> + rvals[i] = GEN_INT (vals[i]);
> +
> +  v = gen_rtvec_v (16, rvals);
> +
> +  emit_insn (gen_vec_initv16qiqi (mask, gen_rtx_PARALLEL (V8HImode, v)));
> +  emit_insn (gen_altivec_vperm_ (operands[0], operands[1],
> +operands[1], mask));
> +}

Please use swap_selector_for_mode for this?

> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/powerpc/builtins-revb-runnable.c
> @@ -0,0 +1,354 @@
> +/* { dg-do run { target { powerpc*-*-* } } } */
> +/* { dg-skip-if "do not override -mcpu" { powerpc*-*-* } { "-mcpu=*" } { 
> "-mcpu=power8" } } */
> +/* { dg-require-effective-target vsx_hw } */
> +/* { dg-options "-mcpu=power8  -O3" } */

This should only run on a power8, so p8vector_hw (because of the -mcpu=
there can be p8 insns generated, so we cannot run the testcase 

Re: [PATCH] Fortran -- Handle BOZ in accordance with F2008/2015.

2017-10-09 Thread Dominique d'Humières

> Le 7 oct. 2017 à 17:48, Steve Kargl  a 
> écrit :
> 
> On Sat, Oct 07, 2017 at 12:37:03PM +0200, Dominique d'Humières wrote:
>> (4) Compiling
>> 
>> print *, INT(z'',4)
>> end
>> 
>> gives
>> 
>> print *, INT(z'',4)
>> 1
>> Error: Arithmetic overflow converting INTEGER(-1) to INTEGER(4)
>> at (1). This check can be disabled with the option '-fno-range-check’
>> 
>> Should not it be -1?
> 
> Maybe. :-)
> 
> See my note to Jerry about needing to implement F2015 16.3.3 correctly.
> Upon sleeping on this deficiency, I realized that 16.3.3 without stating
> allows one to set the sign-bit.  We find in 16.3.1 the statement

s/16/13/?

> 
>   The interpretation of a negative integer as a sequence of bits
>   is processor dependent.
> 
> There is the bit model and integer model numbers.  F2015 contrasts the
> models and concludes with 
> 
>   In particular, whereas the models are identical for r = 2 and
>   $w_{z-1}$ = 0, they do not correspond for r = 2 or $w_{z-1} = 1$
>   and the interpretation of bits in such objects is processor dependent.

I am not sure this is relevant. The problem here is not about bit 
interpretation, but how you fill 32 bits with a 32-bit pattern.

IMO 'INT(z'',4)' should return an integer(4) with all its bits set to 
one.

(7) libgomp/testsuite/libgomp.fortran/aligned1.f03 should be changed as 
gcc/testsuite/gfortran.dg/graphite/id-26.f03:

--- ../_clean/libgomp/testsuite/libgomp.fortran/aligned1.f032017-09-28 
11:35:02.0 +0200
+++ libgomp/testsuite/libgomp.fortran/aligned1.f03  2017-10-09 
18:29:25.0 +0200
@@ -52,11 +52,11 @@
   ! Attempt to create 64-byte aligned allocatable
   do i = 1, 64
 allocate (c(1023 + i))
-if (iand (loc (c(1)), 63) == 0) exit
+if (iand (int(loc (c(1)), 8), 63_8) == 0) exit
 deallocate (c)
 allocate (b(i)%a(1023 + i))
 allocate (c(1023 + i))
-if (iand (loc (c(1)), 63) == 0) exit
+if (iand (int(loc (c(1)), 8), 63_8) == 0) exit
 deallocate (c)
   end do
   if (allocated (c)) then

otherwise it fails with -m64.

(8) In gfortran.dg/unf_io_convert_2.f90, why is

integer(1), parameter :: b1 = z'11’, …

valid, but not

integer(1) :: b1
b1 = z’11’

?

Dominique

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



Re: [PATCH] Add a warning for invalid function casts

2017-10-09 Thread Martin Sebor

On 10/07/2017 10:48 AM, Bernd Edlinger wrote:

Hi!

I think I have now something useful, it has a few more heuristics
added, to reduce the number of false-positives so that it
is able to find real bugs, for instance in openssl it triggers
at a function cast which has already a TODO on it.

The heuristics are:
- handle void (*)(void) as a wild-card function type.
- ignore volatile, const qualifiers on parameters/return.
- handle any pointers as equivalent.
- handle integral types, enums, and booleans of same precision
   and signedness as equivalent.
- stop parameter validation at the first "...".


These sound quite reasonable to me.  I have a reservation about
just one of them, and some comments about other aspects of the
warning.  Sorry if this seems like a lot.  I'm hoping you'll
find the feedback constructive.

I don't think using void(*)(void) to suppress the warning is
a robust solution because it's not safe to call a function that
takes arguments through such a pointer (especially not if one
or more of the arguments is a pointer).  Depending on the ABI,
calling a function that expects arguments with none could also
mess up the stack as the callee may pop arguments that were
never passed to it.

Instead, I think the warning should be suppressed for casts to
function types without a prototype.  Calling those is (or should
for the most part be) safe and they are the natural way to express
that we don't care about type safety.

Let me also clarify that I understand bullet 4 correctly.
In my tests the warning triggers on enum/integral/boolean
incompatibilities that the text above suggests should be accepted.
 E.g.:

  typedef enum E { e } E;
  E f (void);

  typedef int F (void);

  F *pf = (F *)f;   // -Wcast-function-type

Is the warning here intended?  (My reading of the documentation
suggests it's not.)

In testing the warning in C++, I noticed it's not issued for
casts between incompatible pointers to member functions, or for
casts between member functions to ordinary functions (those are
diagnosed with -Wpedantic

  struct S { void foo (int*); };

  typedef void (S::*MF)(int);
  typedef void F (int*);

  MF pmf = (MF)::foo;   // no warning
  F *pf = (F*)::foo;// -Wpedantic only

These both look like they would be worth diagnosing under the new
option (the second one looks like an opportunity to provide
a dedicated option to control the existing pedantic warning).


I cannot convince myself to handle uintptr_t and pointers as
equivalent.  It is possible that targets like m68k have
an ABI where uintptr_t and void* are different as return values
but are identical as parameter values.

IMHO adding an exception for uintptr_t vs. pointer as parameters
could easily prevent detection of real bugs.  Even if it is safe
for all targets.

However it happens: Examples are the libiberty splay-tree functions,
and also one single place in linux, where an argument of type
"long int" is used to call a timer function with a pointer
argument.  Note, linux does not enable -Wextra.


Patch was bootstrapped and reg-tested on x86_64-pc-linux-gnu.
Is it OK for trunk?


A few comments on the documentation:

  When one of the function types uses variable arguments like this
  @code{int f(...);}, then only the return value and the parameters
  before the @code{...} are checked,

Although G++ accepts 'int f(...)' since GCC does not I would suggest
to avoid showing the prototype in the descriptive text and instead
refer to "functions taking variable arguments."   Also, it's the
types of the arguments that are considered (not the value).  With
that I would suggest rewording the sentence along these lines:

  In a cast involving a function types with a variable argument
  list only the types of initial arguments that are provided are
  considered.

The sentence

  Any benign differences in integral types are ignored...

leaves open the question of what's considered benign.  In my view,
if pointer types are ignored (which is reasonable as we discussed
but which can lead to serious problems) it seems that that
signed/unsigned differences should also be considered benign.
 The consequences of those differences seem considerably less
dangerous than calling a function that takes an char* with an int*
argument.

Regarding qualifiers, unless some types qualifiers are not ignored
(e.g., _Atomic and restrict) I would suggest to correct the sentence
that mentions const and volatile to simply refer to "type qualifiers"
instead to make it clear that no qualifiers are considered.

Martin


Re: [PATCH] Fix PR80295[aarch64] [7/8 Regression] ICE in __builtin_update_setjmp_buf expander

2017-10-09 Thread Qing Zhao

> On Oct 9, 2017, at 5:33 AM, Richard Earnshaw (lists) 
>  wrote:
> 
> On 06/10/17 20:56, Qing Zhao wrote:
>> Thanks a lot for Wilco’s help on this bug. 
>> 
>> Yes, Aarch64 does NOT do anything wrong.  
>> 
>> The implementation of __builtin_update_setjmp_buf is not correct. It takes a 
>> pointer
>> as an operand and treats the Mode of the pointer as Pmode, which is not 
>> correct.
>> a conversion from ptr_mode to Pmode is needed for this pointer.
>> 
>> bootstrapped on aarch64-unknown-linux-gnu.
>> testing on aarch64-unknown-linux-gnu is running.
>> 
> 
> This is more believable for AArch64, but we need to be careful here.  I
> think this needs testing on at least one other target that has a
> ilp32-on-64-bit ABI, eg x86_64's x32 ABI.

I just built the latest upstream GCC on x86_64 Linux. and use it to compile the 
testing case in PR80295 with the following options:

[qinzhao@qzh-ol6-test 80295]$ cat t.c
void f (void *b) { __builtin_update_setjmp_buf (b); }
[qinzhao@qzh-ol6-test 80295]$ sh t
/home/qinzhao/Install/latest/bin/gcc -m32 t.c

it compiles successfully on x86_64.  no similar issue as aarch64. 

DId  I use the correct option on X86 (i.e -m32)?

Qing

> 
> 
> R.
> 


Re: [PATCH], Add PowerPC ISA 3.0 Atomic Memory Operation functions

2017-10-09 Thread Segher Boessenkool
On Fri, Oct 06, 2017 at 02:30:16PM -0400, Michael Meissner wrote:
> Here is the revised amo.h.  I tested the two test files amo1.c and amo2.c, and
> they both compile.  It is interesting, use %P0 results in fewer addi's than 
> the
> older one (there were redunant addi's in passing the address).  Can I check it
> in?
> 
> [gcc]
> 2017-10-06  Michael Meissner  
> 
>   * config/rs6000/amo.h: New include file to provide ISA 3.0 atomic
>   memory operation instruction support.
>   * config.gcc (powerpc*-*-*): Include amo.h as an extra header.
>   (rs6000-ibm-aix[789]*): Likewise.
>   * doc/extend.texi (PowerPC Atomic Memory Operation Functions):
>   Document new functions.
> 
> [gcc/testsuite]
> 2017-10-06  Michael Meissner  
> 
>   * gcc.target/powerpc/amo1.c: New test.
>   * gcc.target/powerpc/amo2.c: Likewise.

> --- gcc/testsuite/gcc.target/powerpc/amo1.c   (revision 0)
> +++ gcc/testsuite/gcc.target/powerpc/amo1.c   (revision 0)
> @@ -0,0 +1,253 @@
> +/* { dg-do compile { target { powerpc64*-*-* && lp64 } } } */
> +/* { dg-require-effective-target powerpc_p9vector_ok } */
> +/* { dg-options "-mpower9-vector -mpower9-misc -O2" } */

Should this be powerpc*-*-* instead?

Okay for trunk with that taken care of.  Thanks!


Segher


Re: [C++ PATCH] hash-table for extern-c fns.

2017-10-09 Thread Jason Merrill
On Fri, Oct 6, 2017 at 10:18 AM, Nathan Sidwell  wrote:
> This patch converts the extern "C" function map to use a hash table, in the
> same way as I've just changed namespace bindings.
>
> There's a small wart, in that the  c_linkage_bindings user (in c-common)
> expects either a single decl or a TREE_LIST.  I.e. not an OVERLOAD.  But the
> hasher expects either a DECL or an OVERLOAD.  Rather than extend the hasher
> (and marginally pessimize it for this special case), I modify the extern-c
> table handling to insert an initial OVERLOAD node, when there are multiple
> functions.  That can CHAIN directly to a TREE_LIST.  Sure, we have a wasted
> OVERLOAD node in this case, but it's going to be rare -- programs don't
> usually declare extern "C" functions of the same name in different
> namespaces.
>
> Changing the c-common function is harder, as OVERLOAD is a C++ FE local
> node.

Hmm, why do we only check extern "C" conflicts for functions?

Jason


[Ada] Spurious error with expression function returning anonymous access

2017-10-09 Thread Pierre-Marie de Rodat
This patch fixes a spurious error on an expression function that is a
completion, when the expression is a function call that returns an anonymous
access type. The preanalysis of the expression to freeze referenced types
requires the proper computation of the access level of the function call,
at a point where the expression is not yet part of the generated tree for
the body that represents the completion.

The following must compile quietly:

 gcc -c print_interval_quotes.adb

--
with Data_Serializer.Quote_Data;
procedure Print_Interval_Quotes is
begin
   null;
end Print_Interval_Quotes;
---
package Data_Serializer.Futures_Support is

   type Futures_Loader_Kind_Type is (Disabled, Default, Explicit);

   type Futures_Loader_Param_Type
   (Kind : Futures_Loader_Kind_Type := Disabled)
 is record
case Kind is
   when Disabled | Default => null;
   when Explicit =>
  Rollover_Offset : Duration;
  Matching_Offset : Duration;
end case;
 end record;

end Data_Serializer.Futures_Support;
--
package body Data_Serializer.Generic_Per_Day_Data is

   function Default_Element (DS : Data_Source_Type) return Element_Type'Class
   is
   begin
  return Data_Wrapper_Type'((X => Null_D'Access));
   end Default_Element;

   function Next_Pointer (DS : Data_Source_Type)
 return not null access constant Data_Type
   is begin
  return Null_D'Access;
   end Next_Pointer;

   function Next (DS : in out Data_Source_Type) return Element_Type'Class is
  (Data_Wrapper_Type'(X => Next_Pointer (DS)));

   function First (DS : Data_Source_Type) return Cursor_Type
 --  Setting "is (null)" removes the bug
 --  is (null);
 is
   --  begin return
(Next_Pointer (DS));
 --  end;

end Data_Serializer.Generic_Per_Day_Data;
---
generic
   type Data_Type is private;
   Null_Data : Data_Type;
package Data_Serializer.Generic_Per_Day_data is

   Null_D : aliased constant Data_Type := Null_Data;
   type Data_Type_T_Array_Access is access Integer;

   type Data_Wrapper_Type
 (X : not null access constant Data_Type)
 is new Element_Type with null record
 with Implicit_Dereference => X;
   overriding function Timestamp (D : Data_Wrapper_Type) return Time is (0);

   type Data_Source_Type is limited new Source_Type with private;

   type Cursor_Type (<>) is private;

   function First (DS : Data_Source_Type) return Cursor_Type;

private
   type Data_Source_Type_Access is not null access all Data_Source_Type;

   type Writable_Access
 (Self : not null access Data_Source_Type)
 is limited null record;

   type Data_Source_Type
 is limited new Source_Type with null record;

   type Cursor_Type is access constant Data_Type;

end Data_Serializer.Generic_Per_Day_Data;
---
with Data_Serializer.Generic_Per_Day_Data;
with Quotes;

package Data_Serializer.Quote_Data is new Data_Serializer.Generic_Per_Day_Data
  (Data_Type  => Quotes.Quote_Type,
   Null_Data  => Quotes.Null_Quote
   );
package Data_Serializer is
   type Time is new Integer;

   type Element_Type is interface;
   function Timestamp (E : Element_Type) return Time is abstract;

   type Source_Type is abstract tagged limited null record;

end Data_Serializer;
--
package Quotes is
   type Quote_Type is new Integer;
   Null_Quote : constant Quote_Type := 0;
end Quotes;

Tested on x86_64-pc-linux-gnu, committed on trunk

2017-10-09  Ed Schonberg  

* sem_util.adb (Object_Access_Level): If the object is the return
statement of an expression function, return the level of the function.
This is relevant when the object involves an implicit conversion
between access types and the expression function is a completion, which
forces the analysis of the expression before rewriting it as a body, so
that freeze nodes can appear in the proper scope.

Index: sem_util.adb
===
--- sem_util.adb(revision 253548)
+++ sem_util.adb(working copy)
@@ -20383,6 +20383,17 @@
 (Nearest_Dynamic_Scope
(Defining_Entity (Node_Par)));
 
+--  For a return statement within a function, return
+--  the depth of the function itself. This is not just
+--  a small optimization, but matters when analyzing
+--  the expression in an expression function before
+--  the body is created.
+
+when N_Simple_Return_Statement =>
+   if Ekind (Current_Scope) = E_Function then
+  return Scope_Depth (Current_Scope);
+   end if;
+
 when others =>
null;
  end case;


[Ada] Static allocation of secondary dispatch tables

2017-10-09 Thread Pierre-Marie de Rodat
This patch enhances the compiler to statically allocate secondary
dispatch tables.

No test available because it would require the analysis of the
generated assembly code (thus depending on the target architecture).

Tested on x86_64-pc-linux-gnu, committed on trunk

2017-10-09  Javier Miranda  

* exp_ch3.adb (Expand_N_Object_Declaration): Avoid never-ending loop
processing the declaration of the dummy object internally created by
Make_DT to compute the offset to the top of components referencing
secondary dispatch tables.
(Initialize_Tag): Do not initialize the offset-to-top field if it has
been initialized initialized.
* exp_disp.ads (Building_Static_Secondary_DT): New subprogram.
* exp_disp.adb (Building_Static_Secondary_DT): New subprogram.
(Make_DT): Create a dummy constant object if we can statically build
secondary dispatch tables.
(Make_Secondary_DT): For statically allocated secondary dispatch tables
use the dummy object to compute the offset-to-top field value by means
of the attribute 'Position.

Index: exp_ch3.adb
===
--- exp_ch3.adb (revision 253548)
+++ exp_ch3.adb (working copy)
@@ -6138,6 +6138,19 @@
  return;
   end if;
 
+  --  No action needed for the internal imported dummy object added by
+  --  Make_DT to compute the offset of the components that reference
+  --  secondary dispatch tables; required to avoid never-ending loop
+  --  processing this internal object declaration.
+
+  if Tagged_Type_Expansion
+and then Is_Internal (Def_Id)
+and then Is_Imported (Def_Id)
+and then Related_Type (Def_Id) = Implementation_Base_Type (Typ)
+  then
+ return;
+  end if;
+
   --  First we do special processing for objects of a tagged type where
   --  this is the point at which the type is frozen. The creation of the
   --  dispatch table and the initialization procedure have to be deferred
@@ -8384,10 +8397,13 @@
  --  Normal case: No discriminants in the parent type
 
  else
---  Don't need to set any value if this interface shares the
---  primary dispatch table.
+--  Don't need to set any value if the offset-to-top field is
+--  statically set or if this interface shares the primary
+--  dispatch table.
 
-if not Is_Ancestor (Iface, Typ, Use_Full_View => True) then
+if not Building_Static_Secondary_DT (Typ)
+  and then not Is_Ancestor (Iface, Typ, Use_Full_View => True)
+then
Append_To (Stmts_List,
  Build_Set_Static_Offset_To_Top (Loc,
Iface_Tag=> New_Occurrence_Of (Iface_Tag, Loc),
Index: exp_disp.adb
===
--- exp_disp.adb(revision 253546)
+++ exp_disp.adb(working copy)
@@ -29,6 +29,7 @@
 with Einfo;use Einfo;
 with Elists;   use Elists;
 with Errout;   use Errout;
+with Expander; use Expander;
 with Exp_Atag; use Exp_Atag;
 with Exp_Ch6;  use Exp_Ch6;
 with Exp_CG;   use Exp_CG;
@@ -300,6 +301,32 @@
end Building_Static_DT;
 
--
+   -- Building_Static_Secondary_DT --
+   --
+
+   function Building_Static_Secondary_DT (Typ : Entity_Id) return Boolean is
+  Full_Typ : Entity_Id := Typ;
+  Root_Typ : Entity_Id := Root_Type (Typ);
+
+   begin
+  --  Handle private types
+
+  if Present (Full_View (Typ)) then
+ Full_Typ := Full_View (Typ);
+  end if;
+
+  if Present (Full_View (Root_Typ)) then
+ Root_Typ := Full_View (Root_Typ);
+  end if;
+
+  return Building_Static_DT (Full_Typ)
+and then not Is_Interface (Full_Typ)
+and then Has_Interfaces (Full_Typ)
+and then (Full_Typ = Root_Typ
+or else not Is_Variable_Size_Record (Etype (Full_Typ)));
+   end Building_Static_Secondary_DT;
+
+   --
-- Build_Static_Dispatch_Tables --
--
 
@@ -1693,11 +1720,10 @@
 
if From_Limited_With (Actual_Typ) then
 
-  --  If the type of the actual parameter comes from a
-  --  limited with-clause and the non-limited view is already
-  --  available, we replace the anonymous access type by
-  --  a duplicate declaration whose designated type is the
-  --  non-limited view.
+  --  If the type of the actual parameter comes from a limited
+  --  with_clause and the nonlimited view is already available,
+  --  we replace the anonymous access type by a duplicate
+  --  declaration whose designated type is the 

[Ada] Improve nnd debugging hooks

2017-10-09 Thread Pierre-Marie de Rodat
This patch improves and simplifies the debugging hooks.  Now you just have to
break on nnd to find all "interesting" creations/modifications of node ids.  No
change in functionality; no test available.

Tested on x86_64-pc-linux-gnu, committed on trunk

2017-10-09  Bob Duff  

* atree.adb: Make nnd apply to everything "interesting", including
Rewrite.  Remove rrd.

Index: atree.adb
===
--- atree.adb   (revision 253546)
+++ atree.adb   (working copy)
@@ -73,12 +73,13 @@
-- ww := 12345
--  and set a breakpoint on New_Node_Breakpoint (nickname "nn"). Continue.
 
-   --  Either way, gnat1 will stop when node 12345 is created
+   --  Either way, gnat1 will stop when node 12345 is created, or certain other
+   --  interesting operations are performed, such as Rewrite. To see exactly
+   --  which operations, search for "pragma Debug" below.
 
-   --  The second method is much faster
+   --  The second method is much faster if the amount of Ada code being
+   --  compiled is large.
 
-   --  Similarly, rr and rrd allow breaking on rewriting of a given node
-
ww : Node_Id'Base := Node_Id'First - 1;
pragma Export (Ada, ww); --  trick the optimizer
Watch_Node : Node_Id'Base renames ww;
@@ -103,24 +104,8 @@
--  If Node = Watch_Node, this prints out the new node and calls
--  New_Node_Breakpoint. Otherwise, does nothing.
 
-   procedure rr;
-   pragma Export (Ada, rr);
-   procedure Rewrite_Breakpoint renames rr;
-   --  This doesn't do anything interesting; it's just for setting breakpoint
-   --  on as explained above.
-
-   procedure rrd (Old_Node, New_Node : Node_Id);
-   pragma Export (Ada, rrd);
-   procedure Rewrite_Debugging_Output
- (Old_Node, New_Node : Node_Id) renames rrd;
-   --  For debugging. If debugging is turned on, Rewrite calls this. If debug
-   --  flag N is turned on, this prints out the new node.
-   --
-   --  If Old_Node = Watch_Node, this prints out the old and new nodes and
-   --  calls Rewrite_Breakpoint. Otherwise, does nothing.
-
procedure Node_Debug_Output (Op : String; N : Node_Id);
-   --  Common code for nnd and rrd, writes Op followed by information about N
+   --  Called by nnd; writes Op followed by information about N
 
procedure Print_Statistics;
pragma Export (Ada, Print_Statistics);
@@ -751,6 +736,8 @@
   Save_Link: constant Union_Id := Nodes.Table (Destination).Link;
 
begin
+  pragma Debug (New_Node_Debugging_Output (Source));
+  pragma Debug (New_Node_Debugging_Output (Destination));
   Nodes.Table (Destination) := Nodes.Table (Source);
   Nodes.Table (Destination).In_List := Save_In_List;
   Nodes.Table (Destination).Link:= Save_Link;
@@ -1348,6 +1335,8 @@
   Temp_Flg : Flags_Byte;
 
begin
+  pragma Debug (New_Node_Debugging_Output (E1));
+  pragma Debug (New_Node_Debugging_Output (E2));
   pragma Assert (True
 and then Has_Extension (E1)
 and then Has_Extension (E2)
@@ -1746,7 +1735,6 @@
begin
   Write_Str ("Watched node ");
   Write_Int (Int (Watch_Node));
-  Write_Str (" created");
   Write_Eol;
end nn;
 
@@ -1759,7 +1747,7 @@
 
begin
   if Debug_Flag_N or else Node_Is_Watched then
- Node_Debug_Output ("Allocate", N);
+ Node_Debug_Output ("Node", N);
 
  if Node_Is_Watched then
 New_Node_Breakpoint;
@@ -2163,6 +2151,8 @@
 (not Has_Extension (Old_Node)
   and not Has_Extension (New_Node)
   and not Nodes.Table (New_Node).In_List);
+  pragma Debug (New_Node_Debugging_Output (Old_Node));
+  pragma Debug (New_Node_Debugging_Output (New_Node));
 
   --  Do copy, preserving link and in list status and required flags
 
@@ -2214,7 +2204,8 @@
 (not Has_Extension (Old_Node)
   and not Has_Extension (New_Node)
   and not Nodes.Table (New_Node).In_List);
-  pragma Debug (Rewrite_Debugging_Output (Old_Node, New_Node));
+  pragma Debug (New_Node_Debugging_Output (Old_Node));
+  pragma Debug (New_Node_Debugging_Output (New_Node));
 
   if Nkind (Old_Node) in N_Subexpr then
  Old_Paren_Count := Paren_Count (Old_Node);
@@ -2264,36 +2255,6 @@
   end if;
end Rewrite;
 
-   -
-   -- Rewrite_Breakpoint --
-   -
-
-   procedure rr is
-   begin
-  Write_Str ("Watched node ");
-  Write_Int (Int (Watch_Node));
-  Write_Str (" rewritten");
-  Write_Eol;
-   end rr;
-
-   --
-   -- Rewrite_Debugging_Output --
-   --
-
-   procedure rrd (Old_Node, New_Node : Node_Id) is
-  Node_Is_Watched : constant Boolean := Old_Node = Watch_Node;
-
-   begin
-  if Debug_Flag_N or else Node_Is_Watched then
- Node_Debug_Output ("Rewrite", Old_Node);
- Node_Debug_Output ("into",

[Add] Spurious ambiguity in prefixed call to classwide operation

2017-10-09 Thread Pierre-Marie de Rodat
This patch suppresses a spurious ambiguity error on a prefixed call to an
inherited class-wide operation, when the operation also has other visible
homonyms in the context.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

2017-10-09  Ed Schonberg  

* sem_ch4.adb (Try_Class_Wide_Operation, Traverse_Homonyms):
Suppress spurious ambiguity error when two traversals of the homonym
chain (first directly, and then through an examination of relevant
interfaces) retrieve the same operation, when other irrelevant homonyms
of the operatioh are also present.

gcc/testsuite/

2017-10-09  Ed Schonberg  

* gnat.dg/class_wide3.adb, gnat.dg/class_wide3_pkg.ads: New testcase.
Index: sem_ch4.adb
===
--- sem_ch4.adb (revision 253546)
+++ sem_ch4.adb (working copy)
@@ -8860,7 +8860,7 @@
 while Present (Hom) loop
if Ekind_In (Hom, E_Procedure, E_Function)
  and then (not Is_Hidden (Hom) or else In_Instance)
- and then Scope (Hom) = Scope (Anc_Type)
+ and then Scope (Hom) = Scope (Base_Type (Anc_Type))
  and then Present (First_Formal (Hom))
  and then
(Base_Type (Etype (First_Formal (Hom))) = Cls_Type
@@ -8921,8 +8921,13 @@
 Success=> Success,
 Skip_First => True);
 
+ --  The same operation may be encountered on two homonym
+ --  traversals, before and after looking at interfaces.
+ --  Check for this case before reporting a real ambiguity.
+
  if Present (Valid_Candidate (Success, Call_Node, Hom))
and then Nkind (Call_Node) /= N_Function_Call
+   and then Hom /= Matching_Op
  then
 Error_Msg_NE ("ambiguous call to&", N, Hom);
 Report_Ambiguity (Matching_Op);
Index: ../testsuite/gnat.dg/class_wide3.adb
===
--- ../testsuite/gnat.dg/class_wide3.adb(revision 0)
+++ ../testsuite/gnat.dg/class_wide3.adb(revision 0)
@@ -0,0 +1,8 @@
+with Ada.Text_IO; use Ada.Text_IO;
+with Class_Wide3_Pkg; use Class_Wide3_Pkg;
+
+procedure Class_Wide3 is
+   DC : Disc_Child := (N => 1, I => 3, J => 5);
+begin
+   DC.Put_Line;
+end Class_Wide3;
Index: ../testsuite/gnat.dg/class_wide3_pkg.ads
===
--- ../testsuite/gnat.dg/class_wide3_pkg.ads(revision 0)
+++ ../testsuite/gnat.dg/class_wide3_pkg.ads(revision 0)
@@ -0,0 +1,16 @@
+package Class_Wide3_Pkg is
+
+   type Iface is interface;
+   type Iface_Ptr is access all Iface'Class;
+
+   procedure Put_Line (I : Iface'Class);
+
+   type Root is tagged record
+  I : Integer;
+   end record;
+
+   type Disc_Child (N : Integer) is new Root and Iface with record
+  J : Integer;
+   end record;
+
+end Class_Wide3_Pkg;


[PATCH, rs6000] Add Power 8 support to vec_revb

2017-10-09 Thread Carl Love
GCC maintainers:

The following patch add Power8 vec_revb() builtin support to the
existing Power 9 support.  The Power ISA specification says the
vec_revb() builtin is to be supported on both Power 8 and Power 9.
There are new instructions in Power 9 that support the vec_revb()
functionality.  So the support generates different code for Power 8
versus Power 9.  

The patch has been tested on 

powerpc64le-unknown-linux-gnu (Power 8 LE)
powerpc64-unknown-linux-gnu (Power 8 BE)
powerpc64le-unknown-linux-gnu (Power 9 LE)

without regressions.  

Please let me know if the following patch is acceptable.  Thanks.

   Carl Love

---
>From 5813b99e68f1a5e82bcc1cb1ee0636f6386ba841 Mon Sep 17 00:00:00 2001
From: Carl Love 
Date: Mon, 2 Oct 2017 11:04:01 -0500
Subject: [PATCH] Add Power 8 support to vec_revb

gcc/ChangeLog:

2017-10-05  Carl Love  

* config/rs6000/rs6000-c.c (P8V_BUILTIN_VEC_REVB):
Add power 8 definitions for the builtin instances.
(P9V_BUILTIN_VEC_REVB): Remove the power 9 instance
definitions.
* config/rs6000/altivec.h (vec_revb): Change the
#define from power 9 to power 8.
* config/rs6000/rs6000-builtin.def (BU_P8V_VSX_1,
BU_P8V_OVERLOAD_1): Add power 8 macro expansions.
(BU_P9V_OVERLOAD_1): Remove power 9 overload expansion.
* config/rs6000/vsx.md (revb_): Add define_expand
to generate power 8 instructions for the vec_revb builtin.

gcc/testsuite/ChangeLog:

2017-10-05  Carl Love  

*gcc.target/powerpc/builtins-revb-runnable.c: New
runnable test file for the vec_revb builtin.
---
 gcc/config/rs6000/altivec.h|   3 +-
 gcc/config/rs6000/rs6000-builtin.def   |  10 +-
 gcc/config/rs6000/rs6000-c.c   |  44 +--
 gcc/config/rs6000/vsx.md   |  88 +
 .../gcc.target/powerpc/builtins-revb-runnable.c| 354 +
 5 files changed, 474 insertions(+), 25 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/powerpc/builtins-revb-runnable.c

diff --git a/gcc/config/rs6000/altivec.h b/gcc/config/rs6000/altivec.h
index c8e508c..a05e23a 100644
--- a/gcc/config/rs6000/altivec.h
+++ b/gcc/config/rs6000/altivec.h
@@ -415,6 +415,7 @@
 #define vec_vsubuqm __builtin_vec_vsubuqm
 #define vec_vupkhsw __builtin_vec_vupkhsw
 #define vec_vupklsw __builtin_vec_vupklsw
+#define vec_revb __builtin_vec_revb
 #endif
 
 #ifdef __POWER9_VECTOR__
@@ -476,8 +477,6 @@
 
 #define vec_xlx __builtin_vec_vextulx
 #define vec_xrx __builtin_vec_vexturx
-
-#define vec_revb __builtin_vec_revb
 #endif
 
 /* Predicates.
diff --git a/gcc/config/rs6000/rs6000-builtin.def 
b/gcc/config/rs6000/rs6000-builtin.def
index 850164a..7ca2974 100644
--- a/gcc/config/rs6000/rs6000-builtin.def
+++ b/gcc/config/rs6000/rs6000-builtin.def
@@ -1853,6 +1853,13 @@ BU_P6_64BIT_2 (CMPB, "cmpb", CONST,  cmpbdi3)
 /* 1 argument VSX instructions added in ISA 2.07.  */
 BU_P8V_VSX_1 (XSCVSPDPN,  "xscvspdpn", CONST,  vsx_xscvspdpn)
 BU_P8V_VSX_1 (XSCVDPSPN,  "xscvdpspn", CONST,  vsx_xscvdpspn)
+BU_P8V_VSX_1 (REVB_V1TI,  "revb_v1ti", CONST,   revb_v1ti)
+BU_P8V_VSX_1 (REVB_V2DI,  "revb_v2di", CONST,   revb_v2di)
+BU_P8V_VSX_1 (REVB_V4SI,  "revb_v4si", CONST,   revb_v4si)
+BU_P8V_VSX_1 (REVB_V8HI,  "revb_v8hi", CONST,   revb_v8hi)
+BU_P8V_VSX_1 (REVB_V16QI, "revb_v16qi",CONST,   revb_v16qi)
+BU_P8V_VSX_1 (REVB_V2DF,  "revb_v2df", CONST,   revb_v2df)
+BU_P8V_VSX_1 (REVB_V4SF,  "revb_v4sf", CONST,   revb_v4sf)
 
 /* 1 argument altivec instructions added in ISA 2.07.  */
 BU_P8V_AV_1 (ABS_V2DI,   "abs_v2di",   CONST,  absv2di2)
@@ -1962,6 +1969,7 @@ BU_P8V_OVERLOAD_1 (VPOPCNTUH, "vpopcntuh")
 BU_P8V_OVERLOAD_1 (VPOPCNTUW,  "vpopcntuw")
 BU_P8V_OVERLOAD_1 (VPOPCNTUD,  "vpopcntud")
 BU_P8V_OVERLOAD_1 (VGBBD,  "vgbbd")
+BU_P8V_OVERLOAD_1 (REVB,   "revb")
 
 /* ISA 2.07 vector overloaded 2 argument functions.  */
 BU_P8V_OVERLOAD_2 (EQV,"eqv")
@@ -2073,8 +2081,6 @@ BU_P9V_OVERLOAD_1 (VSTDCNQP,  "scalar_test_neg_qp")
 BU_P9V_OVERLOAD_1 (VSTDCNDP,   "scalar_test_neg_dp")
 BU_P9V_OVERLOAD_1 (VSTDCNSP,   "scalar_test_neg_sp")
 
-BU_P9V_OVERLOAD_1 (REVB,   "revb")
-
 BU_P9V_OVERLOAD_1 (VEXTRACT_FP_FROM_SHORTH, "vextract_fp_from_shorth")
 BU_P9V_OVERLOAD_1 (VEXTRACT_FP_FROM_SHORTL, "vextract_fp_from_shortl")
 
diff --git a/gcc/config/rs6000/rs6000-c.c b/gcc/config/rs6000/rs6000-c.c
index 897306c..0706319 100644
--- a/gcc/config/rs6000/rs6000-c.c
+++ b/gcc/config/rs6000/rs6000-c.c
@@ -5532,36 +5532,38 @@ const struct altivec_builtin_types 
altivec_overloaded_builtins[] = {
 RS6000_BTI_unsigned_V16QI, RS6000_BTI_unsigned_V16QI,
 RS6000_BTI_unsigned_V16QI, 0 },
 
-  { P9V_BUILTIN_VEC_REVB, 

Re: [RFA] Implement __VA_OPT__

2017-10-09 Thread Tom Tromey
> "Tom" == Tom Tromey  writes:

[ __VA_OPT__ ]
Tom> Here's v3.

Ping.

Tom


[Ada] Detect protected types as program units

2017-10-09 Thread Pierre-Marie de Rodat
Routine Unit_Declaration_Node now recognizes protected types as program
units and returns their declaration nodes; previously it returned
declaration nodes of the enclosing program units. This was an oversight.


-- Source --


--  illegal.ads

package Illegal
  with SPARK_Mode
is
   protected type PT
 with SPARK_Mode => Off
   is
   end PT;

end Illegal;

--  illegal.adb

package body Illegal
  with SPARK_Mode
is
   protected body PT
 with SPARK_Mode--  Error
   is
   end PT;

end Illegal;


-- Compilation and output --


$ gcc -c illegal.adb 
illegal.adb:5:11: incorrect use of SPARK_Mode
illegal.adb:5:11: value Off was set for SPARK_Mode on "PT" at illegal.ads:5

Tested on x86_64-pc-linux-gnu, committed on trunk

2017-10-09  Piotr Trojanek  

* sem_aux.adb (Unit_Declaration_Node): Detect protected declarations,
just like other program units listed in Ada RM 10.1(1).

Index: sem_aux.adb
===
--- sem_aux.adb (revision 253546)
+++ sem_aux.adb (working copy)
@@ -1693,6 +1693,7 @@
 and then Nkind (N) /= N_Package_Renaming_Declaration
 and then Nkind (N) /= N_Procedure_Instantiation
 and then Nkind (N) /= N_Protected_Body
+and then Nkind (N) /= N_Protected_Type_Declaration
 and then Nkind (N) /= N_Subprogram_Declaration
 and then Nkind (N) /= N_Subprogram_Body
 and then Nkind (N) /= N_Subprogram_Body_Stub


[Ada] Warnings for ineffective use clauses unclear

2017-10-09 Thread Pierre-Marie de Rodat
This patch modifies the warnings denoting ineffective use-clauses to be more
explicit and user-friendly.


-- Source --


--  unused_a.adb

with Ada.Text_IO;
with Interfaces;

procedure Unused_A is
   use type Interfaces.Unsigned_8;
begin
   Ada.Text_IO.Put_Line ("Hello, World!");
end;

--  unused_b.adb

with Ada.Text_IO;
with Interfaces;

procedure Unused_B is
   use type Interfaces.Unsigned_32;
   Val : Interfaces.Unsigned_32 := 5;
begin
   Ada.Text_IO.Put_Line ("Hello, World!" & Interfaces.Unsigned_32'Image (Val));
end;

--  unused_c.adb

with Ada.Text_IO;
with Interfaces;

procedure Unused_C is
   Val : Interfaces.Unsigned_32 := 5;
begin
   Ada.Text_IO.Put_Line ("Hello, World!" & Interfaces.Unsigned_32'Image (Val));

   declare
  use Interfaces; -- no warning that this is useless here
   begin
  Ada.Text_IO.Put_Line ("Goodbye!");
   end;

end;


-- Compilation and output --


& gnatmake -gnatwu -q unused_a.adb
& gnatmake -gnatwu -q unused_b.adb
& gnatmake -gnatwu -q unused_c.adb

unused_a.adb:5:04: warning: use clause for type "Interfaces.Unsigned_8"
 has no effect
unused_b.adb:5:04: warning: use clause for type "Interfaces.Unsigned_32"
 has no effect
unused_c.adb:10:07: warning: use clause for package "Interfaces" has no effect

Tested on x86_64-pc-linux-gnu, committed on trunk

2017-10-09  Justin Squirek  

* sem_ch8.adb (Update_Chain_In_Scope): Modify warning messages.

Index: sem_ch8.adb
===
--- sem_ch8.adb (revision 253546)
+++ sem_ch8.adb (working copy)
@@ -9069,7 +9069,7 @@
  (Current_Use_Clause (Associated_Node (N
   then
  Error_Msg_Node_1 := Entity (N);
- Error_Msg_NE ("ineffective use clause for package &?",
+ Error_Msg_NE ("use clause for package &? has no effect",
Curr, Entity (N));
   end if;
 
@@ -9077,7 +9077,7 @@
 
else
   Error_Msg_Node_1 := Etype (N);
-  Error_Msg_NE ("ineffective use clause for }?",
+  Error_Msg_NE ("use clause for }? has no effect",
  Curr, Etype (N));
end if;
 end if;


[Ada] Crash on validity check on actual with type conversion

2017-10-09 Thread Pierre-Marie de Rodat
This patch fixes a compiler crash on a function call when validity checks
on actuals are enabled (-gnatVi) and the target type is a scalar type.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

2017-10-09  Ed Schonberg  

* exp_attr.adb (Expand_Attribute_Reference, case 'Valid): The prefix of
the attribute is an object, but it may appear within a conversion. The
object itself must be retrieved when generating the range test that
implements the validity check on a scalar type.

gcc/testsuite/

2017-10-09  Ed Schonberg  

* gnat.dg/validity_check2.adb, gnat.dg/validity_check2_pkg.ads:
New testcase.
Index: exp_attr.adb
===
--- exp_attr.adb(revision 253546)
+++ exp_attr.adb(working copy)
@@ -6512,7 +6512,9 @@
  begin
 --  The prefix of attribute 'Valid should always denote an object
 --  reference. The reference is either coming directly from source
---  or is produced by validity check expansion.
+--  or is produced by validity check expansion. The object may be
+--  wrapped in a conversion in which case the call to Unqual_Conv
+--  will yield it.
 
 --  If the prefix denotes a variable which captures the value of
 --  an object for validation purposes, use the variable in the
@@ -6523,7 +6525,7 @@
 --if not Temp in ... then
 
 if Is_Validation_Variable_Reference (Pref) then
-   Temp := New_Occurrence_Of (Entity (Pref), Loc);
+   Temp := New_Occurrence_Of (Entity (Unqual_Conv (Pref)), Loc);
 
 --  Otherwise the prefix is either a source object or a constant
 --  produced by validity check expansion. Generate:
Index: ../testsuite/gnat.dg/validity_check2.adb
===
--- ../testsuite/gnat.dg/validity_check2.adb(revision 0)
+++ ../testsuite/gnat.dg/validity_check2.adb(revision 0)
@@ -0,0 +1,11 @@
+--  { dg-do compile }
+--  { dg-options "-gnatVi -gnatws" }
+
+with Validity_Check2_Pkg; use Validity_Check2_Pkg;
+
+procedure Validity_Check2 (R : access Rec) is
+begin
+  if Op_Code_To_Msg (R.Code) in Valid_Msg then
+raise Program_Error;
+  end if;
+end;
Index: ../testsuite/gnat.dg/validity_check2_pkg.ads
===
--- ../testsuite/gnat.dg/validity_check2_pkg.ads(revision 0)
+++ ../testsuite/gnat.dg/validity_check2_pkg.ads(revision 0)
@@ -0,0 +1,16 @@
+with Ada.unchecked_conversion;
+
+package Validity_Check2_Pkg is
+
+  type Op_Code is (One, Two, Three, Four);
+
+  subtype Valid_Msg is Integer range 0 .. 15;
+
+  function Op_Code_To_Msg is
+new Ada.Unchecked_Conversion (Source => Op_code, Target => Valid_Msg);
+
+  type Rec is record
+Code : Op_Code;
+  end record;
+
+end Validity_Check2_Pkg;


[Ada] Crash on actual that is an instance of a generic child unit

2017-10-09 Thread Pierre-Marie de Rodat
This patch fixes a compiler abort on an instantiation where the actual for
a formal package is an instantiation of a generic child unit. An instantiation
freezes its actuals, and in the case of formal packages whose instance
includes a body the back-end needs an explicit freeze node for the actual.
If the generic for that actual appears within an enclosing instantiation
that instantiation must be frozen as well. Additionally, if the actual is
an instantiation of a child unit it depends on an instance of its parent
unit, and that instantiation must be frozen as well. Previously only the
first kind of dependence on a previous instantiation was handled properly.

The following must compile quietly:

   gcc -c p.ads

---
with Q;
with Q.Sub1;
with Q.Sub2;
package P is

   type Rec is record
  null;
   end record;

   package My_Q is new Q (Rec);

   package My_Sub1 is new My_Q.Sub1;

   package My_Sub2 is new My_Q.Sub2 (My_Sub1);

end P;
---
generic
   type T is private;
package Q is

   pragma Elaborate_Body;

   package Inner is

  generic
  package G is
  end G;

   end Inner;

end Q;
---
generic
package Q.Sub1 is

  pragma Elaborate_Body;

end Q.Sub1;
---
package body Q.Sub1 is

  package My_G is new Q.Inner.G;

end Q.Sub1;
---
with Q.Sub1;

generic

   with package F is new Q.Sub1 (<>);

package Q.Sub2 is
end Q.Sub2;
---
with R;
package body Q is

   package My_R is new R (T);

   package body Inner is

  package body G is

 package My_H is new My_R.H;

  end G;

   end Inner;

end Q;
---
generic
   type Message is private;
package R is

   pragma Elaborate_Body;

   generic
   package H is
   end H;

end R;
---
package body R is

   type Message_P is access Message;

   package body H is
  Obj : constant Message_P := null;
   end H;

end R;
---

Tested on x86_64-pc-linux-gnu, committed on trunk

2017-10-09  Ed Schonberg  

* sem_ch12.adb (Analyze_Associations, Check_Generic_Parent): If an
actual for a formal package is an instantiation of a child unit, create
a freeze node for the instance of the parent if it appears in the same
scope and is not frozen yet.

Index: sem_ch12.adb
===
--- sem_ch12.adb(revision 253546)
+++ sem_ch12.adb(working copy)
@@ -1903,7 +1903,8 @@
  --  body.
 
  Explicit_Freeze_Check : declare
-Actual : constant Entity_Id := Entity (Match);
+Actual  : constant Entity_Id := Entity (Match);
+Gen_Par : Entity_Id;
 
 Needs_Freezing : Boolean;
 S  : Entity_Id;
@@ -1912,7 +1913,11 @@
 --  The actual may be an instantiation of a unit
 --  declared in a previous instantiation. If that
 --  one is also in the current compilation, it must
---  itself be frozen before the actual.
+--  itself be frozen before the actual. The actual
+--  may be an instantiation of a generic child unit,
+--  in which case the same applies to the instance
+--  of the parent which must be frozen before the
+--  actual.
 --  Should this itself be recursive ???
 
 --
@@ -1920,30 +1925,71 @@
 --
 
 procedure Check_Generic_Parent is
-   Par : Entity_Id;
+   Inst : constant Node_Id :=
+  Next (Unit_Declaration_Node (Actual));
+   Par  : Entity_Id;
 
 begin
-   if Nkind (Parent (Actual)) =
-N_Package_Specification
+   Par := Empty;
+
+   if Nkind (Parent (Actual)) = N_Package_Specification
then
   Par := Scope (Generic_Parent (Parent (Actual)));
+  if Is_Generic_Instance (Par) then
+ null;
 
-  if Is_Generic_Instance (Par)
-and then Scope (Par) = Current_Scope
-and then
-  (No (Freeze_Node (Par))
-or else
-  not Is_List_Member (Freeze_Node (Par)))
+  --  If the actual is a child generic unit, check
+  --  whether the instantiation of the parent is
+  --  also local and must also be frozen now.
+   

Re: [patch] configure option to override TARGET_LIBC_PROVIDES_SSP

2017-10-09 Thread Joseph Myers
The install.texi documentation for --disable-libssp only says "Specify 
that the run-time libraries for stack smashing protection should not be 
built.".  I think it needs updating to mention these additional effects as 
well.

-- 
Joseph S. Myers
jos...@codesourcery.com


Re: [PATCH][mingw] Enable colorized diagnostics

2017-10-09 Thread Liu Hao

On 2017/10/9 22:16, David Malcolm wrote:

I have some concerns about adding non-trivial host-specific code to the
diagnostics subsystem.

I occasionally make changes to the files you're touching, but I don't
have access to the host in question, so I can't test that I don't break
things on MinGW.

Is it OK if this is the MinGW team's problem, and not mine?  (i.e. can
you please clean up after me if I break something on MinGW?).

I am tracing the branch for the latest stable major release 
(`gcc-7-branch` at the moment) closely. If anything is broken I will let 
you know.



Also, you might want to add some selftests to the code e.g. for
find_esc_head and find_esc_terminator.  
Those functions are static - they will not be visible elsewhere. They 
are formulated for clarification purposes and nothing else.



I looked at the docs for the
Windows console API and unfortunately there doesn't seem to be a way to
set up a dummy console for unit-testing the parts of the code that call
the console API directly.  But find_esc_head and find_esc_terminator
don't directly call the API, and hence you can write some selftest
functions for them.  (there's probably a much more involved way to test
this using mocks/stubs for the console API, but that's probably
overkill).

Dave





--
Best regards,
LH_Mouse



Re: [PATCH][mingw] Enable colorized diagnostics

2017-10-09 Thread David Malcolm
On Mon, 2017-10-09 at 11:01 +, JonY wrote:
> On 10/08/2017 11:39 AM, Liu Hao wrote:
> > On 2017/9/28 4:09, Joseph Myers wrote:
> > > On Thu, 28 Sep 2017, Liu Hao wrote:
> > > 
> > > > Colorized diagnostics used to be disabled for MinGW targets (on
> > > > which
> > > > the macro `_WIN32` is defined), and this patch enables it.
> > > 
> > > I'd hope this is all to do with MinGW host, and nothing to do
> > > with the
> > > target.
> > > 
> > 
> > Ping? Are there any more opinions about this?
> > 
> 
> I'm not sure if it should be enabled by default due to the
> interleaving
> problem, but seeing as the user has to go out to set GCC_COLORS to
> use
> this feature, I suppose it is OK.
> 
> I will commit soon if there are no more comments.

I have some concerns about adding non-trivial host-specific code to the
diagnostics subsystem.

I occasionally make changes to the files you're touching, but I don't
have access to the host in question, so I can't test that I don't break
things on MinGW.

Is it OK if this is the MinGW team's problem, and not mine?  (i.e. can
you please clean up after me if I break something on MinGW?).

Also, you might want to add some selftests to the code e.g. for
find_esc_head and find_esc_terminator.  I looked at the docs for the
Windows console API and unfortunately there doesn't seem to be a way to
set up a dummy console for unit-testing the parts of the code that call
the console API directly.  But find_esc_head and find_esc_terminator
don't directly call the API, and hence you can write some selftest
functions for them.  (there's probably a much more involved way to test
this using mocks/stubs for the console API, but that's probably
overkill).

Dave


Re: [PATCH] Fix PR82397

2017-10-09 Thread Richard Biener
On Mon, 9 Oct 2017, Richard Biener wrote:

> On Sat, 7 Oct 2017, Richard Sandiford wrote:
> 
> > Richard Biener  writes:
> > > I am testing the following patch to fix the qsort intransitiveness
> > > of dr_group_sort_cmp.  The patch removes the overly powerful
> > > operand_equal_p checks (handling commutativity )
> > > because those do not mix well with the sorting constraints.
> > >
> > > I am also testing a followup to address the missed equalities by
> > > canonicalization -- the interesting trees happen to be all built
> > > by split_constant_offset where we can do some elaborate canonicalization
> > > in linear complexity (as opposed to operand_equal_p's exponential
> > > handling or trying to handle it in data_ref_compare_tree where it would
> > > be done at least multiple times during qsort invocation).
> > >
> > > Bootstrapped on x86_64-unknown-linux-gnu, testing still in progress
> > > (so is a quick SPEC 2k6 build where the issue showed up in multiple
> > > places).
> > >
> > > Richard.
> > >
> > > 2017-10-06  Richard Biener  
> > >
> > >   PR tree-optimization/82397
> > >   * tree-vect-data-refs.c (dr_group_sort_cmp): Do not use
> > >   operand_equal_p but rely on data_ref_compare_tree for detecting
> > >   equalities.
> > >   (vect_analyze_data_ref_accesses): Use data_ref_compare_tree
> > >   to match up with dr_group_sort_cmp.
> > >
> > >   * gfortran.dg/pr82397.f: New testcase.
> > >
> > > Index: gcc/tree-vect-data-refs.c
> > > ===
> > > --- gcc/tree-vect-data-refs.c (revision 253475)
> > > +++ gcc/tree-vect-data-refs.c (working copy)
> > > @@ -2727,43 +2727,30 @@ dr_group_sort_cmp (const void *dra_, con
> > >  return loopa->num < loopb->num ? -1 : 1;
> > >  
> > >/* Ordering of DRs according to base.  */
> > > -  if (!operand_equal_p (DR_BASE_ADDRESS (dra), DR_BASE_ADDRESS (drb), 0))
> > > -{
> > > -  cmp = data_ref_compare_tree (DR_BASE_ADDRESS (dra),
> > > -DR_BASE_ADDRESS (drb));
> > > -  if (cmp != 0)
> > > -return cmp;
> > > -}
> > > +  cmp = data_ref_compare_tree (DR_BASE_ADDRESS (dra),
> > > +DR_BASE_ADDRESS (drb));
> > > +  if (cmp != 0)
> > > +return cmp;
> > >  
> > >/* And according to DR_OFFSET.  */
> > > -  if (!dr_equal_offsets_p (dra, drb))
> > > -{
> > > -  cmp = data_ref_compare_tree (DR_OFFSET (dra), DR_OFFSET (drb));
> > > -  if (cmp != 0)
> > > -return cmp;
> > > -}
> > > +  cmp = data_ref_compare_tree (DR_OFFSET (dra), DR_OFFSET (drb));
> > > +  if (cmp != 0)
> > > +return cmp;
> > >  
> > >/* Put reads before writes.  */
> > >if (DR_IS_READ (dra) != DR_IS_READ (drb))
> > >  return DR_IS_READ (dra) ? -1 : 1;
> > >  
> > >/* Then sort after access size.  */
> > > -  if (!operand_equal_p (TYPE_SIZE_UNIT (TREE_TYPE (DR_REF (dra))),
> > > - TYPE_SIZE_UNIT (TREE_TYPE (DR_REF (drb))), 0))
> > > -{
> > > -  cmp = data_ref_compare_tree (TYPE_SIZE_UNIT (TREE_TYPE (DR_REF 
> > > (dra))),
> > > -TYPE_SIZE_UNIT (TREE_TYPE (DR_REF (drb;
> > > -  if (cmp != 0)
> > > -return cmp;
> > > -}
> > > +  cmp = data_ref_compare_tree (TYPE_SIZE_UNIT (TREE_TYPE (DR_REF (dra))),
> > > +TYPE_SIZE_UNIT (TREE_TYPE (DR_REF (drb;
> > > +  if (cmp != 0)
> > > +return cmp;
> > >  
> > >/* And after step.  */
> > > -  if (!operand_equal_p (DR_STEP (dra), DR_STEP (drb), 0))
> > > -{
> > > -  cmp = data_ref_compare_tree (DR_STEP (dra), DR_STEP (drb));
> > > -  if (cmp != 0)
> > > -return cmp;
> > > -}
> > > +  cmp = data_ref_compare_tree (DR_STEP (dra), DR_STEP (drb));
> > > +  if (cmp != 0)
> > > +return cmp;
> > >  
> > >/* Then sort after DR_INIT.  In case of identical DRs sort after stmt 
> > > UID.  */
> > >cmp = tree_int_cst_compare (DR_INIT (dra), DR_INIT (drb));
> > > @@ -2835,9 +2822,9 @@ vect_analyze_data_ref_accesses (vec_info
> > >and they are both either store or load (not load and store,
> > >not masked loads or stores).  */
> > > if (DR_IS_READ (dra) != DR_IS_READ (drb)
> > > -   || !operand_equal_p (DR_BASE_ADDRESS (dra),
> > > -DR_BASE_ADDRESS (drb), 0)
> > > -   || !dr_equal_offsets_p (dra, drb)
> > > +   || data_ref_compare_tree (DR_BASE_ADDRESS (dra),
> > > + DR_BASE_ADDRESS (drb)) != 0
> > > +   || data_ref_compare_tree (DR_OFFSET (dra), DR_OFFSET (drb)) != 0
> > > || !gimple_assign_single_p (DR_STMT (dra))
> > > || !gimple_assign_single_p (DR_STMT (drb)))
> > >   break;
> > > @@ -2851,7 +2838,7 @@ vect_analyze_data_ref_accesses (vec_info
> > >   break;
> > >  
> > > /* Check that the data-refs have the same step.  */
> > > -   if (!operand_equal_p (DR_STEP (dra), DR_STEP (drb), 

Re: tree-complex.c: fix some_nonzerop test over reals (and a bug fix)

2017-10-09 Thread Richard Biener
On Mon, Oct 9, 2017 at 3:30 PM, Laurent Thevenoux
 wrote:
>
>
> - Mail original -
>> De: "Richard Biener" 
>> À: "Laurent Thevenoux" 
>> Cc: "GCC Patches" 
>> Envoyé: Lundi 9 Octobre 2017 14:04:49
>> Objet: Re: tree-complex.c: fix some_nonzerop test over reals (and a bug fix)
>>
>> On Fri, Oct 6, 2017 at 8:58 PM, Laurent Thevenoux
>>  wrote:
>> > Hi Richard, thanks for your quick reply.
>> >
>> > - Mail original -
>> >> De: "Richard Biener" 
>> >> À: "Laurent Thevenoux" 
>> >> Cc: "GCC Patches" 
>> >> Envoyé: Vendredi 6 Octobre 2017 13:42:57
>> >> Objet: Re: tree-complex.c: fix some_nonzerop test over reals (and a bug
>> >> fix)
>> >>
>> >> On Thu, Oct 5, 2017 at 4:41 PM, Laurent Thevenoux
>> >>  wrote:
>> >> > Hello,
>> >> >
>> >> > This patch improves the some_nonzerop(tree t) function from
>> >> > tree-complex.c
>> >> > file (the function is only used there).
>> >> >
>> >> > This function returns true if a tree as a parameter is not the constant
>> >> > 0
>> >> > (or +0.0 only for reals when !flag_signed_zeros ). The former result is
>> >> > then used to determine if some simplifications are possible for complex
>> >> > expansions (addition, multiplication, and division).
>> >> >
>> >> > Unfortunately, if the tree is a real constant, the function always
>> >> > return
>> >> > true, even for +0.0 because of the explicit test on flag_signed_zeros
>> >> > (so
>> >> > if your system enables signed zeros you cannot benefit from those
>> >> > simplifications). To avoid this behavior and allow complex expansion
>> >> > simplifications, I propose the following patch, which test for the sign
>> >> > of
>> >> > the real constant 0.0 instead of checking the flag.
>> >>
>> >> But
>> >>
>> >> +  if (TREE_CODE (t) == REAL_CST)
>> >> +{
>> >> +  if (real_identical (_REAL_CST (t), ))
>> >> +   zerop = !real_isneg (_REAL_CST (t));
>> >> +}
>> >>
>> >> shouldn't you do
>> >>
>> >>zerop = !flag_signed_zeros || !real_isneg (_REAL_CST (t));
>> >>
>> >> ?
>> >
>> > I’m not so sure. If I understand your proposition (tables below gives
>> > values of zerop following the values of t and flag_signed_zeros):
>> >
>> >|   zerop
>> >  t | !flag_signed_zeros is false | !flag_signed_zeros is true
>> > -
>> > +n | true*   | true*
>> > -n | false   | true*
>> >  0 | true| true
>> > -0 | false   | unreachable
>> >
>> > But here, results with a * don't return the good value. The existing code
>> > is also wrong, it always returns false if flag_signed_zeros is true, else
>> > the code is correct:
>> >
>> >|   zerop
>> >  t | !flag_signed_zeros is false | !flag_signed_zeros is true
>> > -
>> > +n | false   | false
>> > -n | false   | false
>> >  0 | true| false*
>> > -0 | false   | unreachable
>> >
>> > With the code I propose, we obtain the right results:
>> >
>> >  t | zerop
>> > --
>> > +n | false
>> > -n | false
>> >  0 | true
>> > -0 | false
>> >
>> > Do I really miss something (I'm sorry if I'm wrong)?
>> >
>> >>
>> >> Also doesn't this miscalculate A - B for {ar, 0.} - {br, 0.} given the
>> >> simplification simply
>> >> returns bi?
>> >
>> > Here we are in case PAIR (ONLY_REAL, ONLY_REAL), which gives ri = 0. (ai)
>> > even with signed zeros. So everything is OK.
>> >
>> >>
>> >> So I'm not convinced this handling is correct.
>> >>
>> >> > This first fix reveals a bug (thanks to
>> >> > c-c++-common/torture/complex-sign-add.c ) in the simplification section
>> >> > of
>> >> > expand_complex_addition (also fixed in the patch).
>> >>
>> >> Your patch looks backward and the existing code looks ok.
>> >>
>> >> @@ -937,7 +940,7 @@ expand_complex_addition (gimple_stmt_iterator
>> >> *gsi, tree inner_type,
>> >>
>> >>  case PAIR (VARYING, ONLY_REAL):
>> >>rr = gimplify_build2 (gsi, code, inner_type, ar, br);
>> >> -  ri = ai;
>> >> +  ri = bi;
>> >>break;
>> >
>> > With the existing code we don’t perform the simplification step at all
>> > since it always returns (VARYING, VARYING) when flag_signed_zeros is true.
>> >
>> > For instance, with {ar, -0.} + {br, 0.}, if simplification really occurs,
>> > its in case PAIR (VARIYNG, ONLY_REAL) (because we consider -0. as a
>> > non_zero), and it returns -0. if we return ai (instead of -0. + 0. -> 0.).
>> > But I understand now that returning bi in this case is meaningless since
>> > {br, bi} is a ONLY_REAL complex.
>> >
>> > Nevertheless, for 

Re: [PATCH][GRAPHITE] Fix PR82449

2017-10-09 Thread Richard Biener
On Mon, 9 Oct 2017, Richard Biener wrote:

> On Fri, 6 Oct 2017, Sebastian Pop wrote:
> 
> > On Fri, Oct 6, 2017 at 8:33 AM, Richard Biener  wrote:
> > 
> > > On Fri, 6 Oct 2017, Sebastian Pop wrote:
> > >
> > > > On Fri, Oct 6, 2017 at 6:56 AM, Richard Biener 
> > > wrote:
> > > >
> > > > >
> > > > > The following fences off a few more SCEVs through scev_analyzable_p
> > > given
> > > > > at the end we need those pass chrec_apply when getting a rename 
> > > > > through
> > > > > SCEV.
> > > > >
> > > > > The SCEV in question is
> > > > >
> > > > >   {(integer(kind=4)) {0, +, {1, +, 1}_1}_1, + 1}_2
> > > > >
> > > > > which fails to chrec_apply in the CHREC_LEFT part because that part
> > > > > is not affine (and we're usually not replacing a IV with a constant
> > > > > where chrec_apply might handle one or the other case).
> > > > >
> > > > > Bootstrapped and tested on x86_64-unknown-linux-gnu.
> > > > >
> > > > > This fixes three out of the remaining 8 codegen errors in SPEC CPU
> > > 2006.
> > > > >
> > > > > Ok?
> > > > >
> > > > > Thanks,
> > > > > Richard.
> > > > >
> > > > > 2017-10-06  Richard Biener  
> > > > >
> > > > > PR tree-optimization/82449
> > > > > * sese.c (can_chrec_apply): New function.
> > > > > (scev_analyzable_p): Check we can call chrec_apply on the 
> > > > > SCEV.
> > > > >
> > > > > * gfortran.dg/graphite/pr82449.f: New testcase.
> > >
> > > >
> > > > > Index: gcc/sese.c
> > > > > ===
> > > > > --- gcc/sese.c  (revision 253477)
> > > > > +++ gcc/sese.c  (working copy)
> > > > > @@ -421,6 +421,27 @@ invariant_in_sese_p_rec (tree t, const s
> > > > >return true;
> > > > >  }
> > > > >
> > > > > +/* Check whether we can call chrec_apply on CHREC with arbitrary X 
> > > > > and
> > > > > VAR.  */
> > >
> > > > +
> > > > > +static bool
> > > > > +can_chrec_apply (tree chrec)
> > >
> > 
> > Could we use scev_is_linear_expression ?
> > It seems like can_chrec_apply has the same semantics.
> 
> Looks like that works.
> 
> > 
> > > > > +{
> > > > > +  if (automatically_generated_chrec_p (chrec))
> > > > > +return false;
> > > > > +  switch (TREE_CODE (chrec))
> > > > > +{
> > > > > +case POLYNOMIAL_CHREC:
> > > > > +  if (evolution_function_is_affine_p (chrec))
> > > > > +   return (can_chrec_apply (CHREC_LEFT (chrec))
> > > > > +   && can_chrec_apply (CHREC_RIGHT (chrec)));
> > > > > +  return false;
> > > > > +CASE_CONVERT:
> > > > > +  return can_chrec_apply (TREE_OPERAND (chrec, 0));
> > > > > +default:;
> > > > > +  return tree_does_not_contain_chrecs (chrec);
> > > > > +}
> > > > > +}
> > > > > +
> > > > >  /* Return true when DEF can be analyzed in REGION by the scalar
> > > > > evolution analyzer.  */
> > > > >
> > > > > @@ -449,6 +470,7 @@ scev_analyzable_p (tree def, sese_l 
> > > > > || !defined_in_sese_p (scev, region))
> > > > >  && (tree_does_not_contain_chrecs (scev)
> > > > > || evolution_function_is_affine_p (scev))
> > > > >
> > > >
> > > > Why isn't evolution_function_is_affine_p returning false on {0, +, {1, 
> > > > +,
> > > > 1}_1}_1?
> > > > This is quadratic.
> > >
> > > It returns false on that but the CHREC we ask it on is
> > >
> > > {(integer(kind=4)) {0, +, {1, +, 1}_1}_1, + 1}_2
> > >
> > > only the initial value is "quadratic".
> > >
> > 
> > Right.
> > If I understand correctly, the scop is the body of loop_1,
> > and we do not need to represent the quadratic evolution
> > of the initial value.
> 
> Giving the following full testing now.

And the following is what I have applied after bootstrap / testing
on x86_64-unknown-linux-gnu.

As you can see I needed some adjustments to not reject otherwise
valid SCEVs with address constants.

Richard.

2017-10-09  Richard Biener  

PR tree-optimization/82449
* sese.c (scev_analyzable_p): Check whether the SCEV is linear.
* tree-chrec.h (evolution_function_is_constant_p): Adjust to
allow constant addresses.
* tree-chrec.c (scev_is_linear_expression): Constant evolutions
are linear.

* gfortran.dg/graphite/pr82449.f: New testcase.

Index: gcc/sese.c
===
--- gcc/sese.c  (revision 253486)
+++ gcc/sese.c  (working copy)
@@ -444,14 +444,13 @@ scev_analyzable_p (tree def, sese_l 
   loop = loop_containing_stmt (SSA_NAME_DEF_STMT (def));
   scev = scalar_evolution_in_region (region, loop, def);
 
-  return !chrec_contains_undetermined (scev)
-&& (TREE_CODE (scev) != SSA_NAME
-   || !defined_in_sese_p (scev, region))
-&& (tree_does_not_contain_chrecs (scev)
-   || evolution_function_is_affine_p (scev))
-&& (! loop
-   || ! loop_in_sese_p (loop, region)
-   || ! chrec_contains_symbols_defined_in_loop (scev, loop->num));
+  

Re: [PATCH GCC][5/7]Extend loop distribution for two-level innermost loop nest

2017-10-09 Thread Richard Biener
On Thu, Oct 5, 2017 at 3:17 PM, Bin Cheng  wrote:
> Hi,
> For now distribution pass only handles the innermost loop.  This patch 
> extends the pass
> to cover two-level innermost loop nest.  It also refactors code in 
> pass_loop_distribution::execute
> for better reading.  Note I restrict it to 2-level loop nest on purpose 
> because of high
> cost in data dependence computation.  Some compilation time optimizations 
> like reusing
> the data reference finding, data dependence computing, would require a 
> rewrite of this
> pass like the proposed loop interchange implementation.  But that's another 
> task.
>
> This patch introduces a temporary TODO for loop nest builtin partition which 
> is covered
> by next two patches.
>
> With this patch, kernel loop in bwaves now can be distributed, thus exposed 
> for further
> interchange.  This patch adds new test for matrix multiplication, as well as 
> adjusts
> test strings of existing tests.
> Bootstrap and test in patch set on x86_64 and AArch64, is it OK?

@ -714,9 +719,11 @@ ssa_name_has_uses_outside_loop_p (tree def, loop_p loop)

   FOR_EACH_IMM_USE_FAST (use_p, imm_iter, def)
 {
-  gimple *use_stmt = USE_STMT (use_p);
-  if (!is_gimple_debug (use_stmt)
- && loop != loop_containing_stmt (use_stmt))
+  if (is_gimple_debug (USE_STMT (use_p)))
+   continue;
+
+  basic_block use_bb = gimple_bb (USE_STMT (use_p));
+  if (use_bb == NULL || !flow_bb_inside_loop_p (loop, use_bb))
return true;

use_bb should never be NULL.

+  /* Don't support loop nest distribution under runtime alias check
+since it's not likely to enable many vectorization opportunities.  */
+  if (loop->inner)
+   {
+ merge_dep_scc_partitions (rdg, , false);
+   }

extra {}

+  /* Support loop nest distribution enclosing current innermost loop.
+For the moment, we only support the innermost two-level loop nest.  */
+  if (flag_tree_loop_distribution
+ && outer->num > 0 && outer->inner == loop && loop->next == NULL

The canonical check for is-this-non-root is loop_outer (outer) instead
of outer->num > 0.

+ && single_exit (outer)

not sure how exits are counted but if the inner loop exits also the
outer loop do
we correctly handle/reject this case?

-  if (nb_generated_loops + nb_generated_calls > 0)
-   {
- changed = true;
- dump_printf_loc (MSG_OPTIMIZED_LOCATIONS,
-  loc, "Loop %d distributed: split to %d loops "
-  "and %d library calls.\n",
-  num, nb_generated_loops, nb_generated_calls);
+ if (nb_generated_loops + nb_generated_calls > 0)
+   {
+ changed = true;
+ dump_printf_loc (MSG_OPTIMIZED_LOCATIONS,
+  loc, "Loop%s %d distributed: split to %d loops "
+  "and %d library calls.\n",
+  loop_nest_p ? " nest" : "", loop->num,
+  nb_generated_loops, nb_generated_call
...

can you adjust the printfs to say "loop nest distributed" in case we distributed
a nest?

Can you rewrite the iteration over the nest so it would theoretically support
arbitrary deep perfect nests?  Thus simply initialize loop_nest_p less
cleverly...

Otherwise looks ok to me.

Thanks,
Richard.

> Thanks,
> bin
> 2017-10-04  Bin Cheng  
>
> * tree-loop-distribution.c: Adjust the general comment.
> (NUM_PARTITION_THRESHOLD): New macro.
> (ssa_name_has_uses_outside_loop_p): Support loop nest distribution.
> (classify_partition): Skip builtin pattern of loop nest's inner loop.
> (merge_dep_scc_partitions): New parameter ignore_alias_p and use it
> in call to build_partition_graph.
> (finalize_partitions): New parameter.  Make loop distribution more
> conservative by fusing more partitions.
> (distribute_loop): Don't do runtime alias check in case of loop nest
> distribution.
> (find_seed_stmts_for_distribution): New function.
> (pass_loop_distribution::execute): Refactor code finding seed stmts
> into above function.  Support loop nest distribution for two-level
> innermost loop nest.  Adjust dump information.
>
> gcc/testsuite/ChangeLog
> 2017-10-04  Bin Cheng  
>
> * gcc.dg/tree-ssa/ldist-7.c: Adjust test string.
> * gcc.dg/tree-ssa/ldist-16.c: Ditto.
> * gcc.dg/tree-ssa/ldist-25.c: Ditto.
> * gcc.dg/tree-ssa/ldist-33.c: Ditto.


Re: [C PATCH] Fix -Wtautological-compare (PR c/82437; #2)

2017-10-09 Thread Marek Polacek
On Fri, Oct 06, 2017 at 02:21:41PM +0200, Jakub Jelinek wrote:
> On Thu, Oct 05, 2017 at 11:05:57PM +0200, Marek Polacek wrote:
> > On Thu, Oct 05, 2017 at 10:34:26PM +0200, Jakub Jelinek wrote:
> > > Hi!
> > > 
> > > In warn_tautological_bitwise_comparison, there is even a comment
> > > mentioning the fact that the types of the two constants might not be the
> > > same (it is called with the original arguments before they are promoted
> > > to common type for the comparison).
> > > 
> > > On the following testcase, one of the constants was unsigned (because
> > > it has been converted to that when anded with unsigned variable), while
> > > the other was signed and wi::to_widest (bitopcst) & wi::to_widest (cst)
> > > wasn't sign-extended from 32-bit (because bitopcst was unsigned),
> > > while wi::to_widest (cst) was (because cst was int), so we warned even
> > > when we shouldn't.
> > > 
> > > The following patch instead uses the precision of the larger type and
> > > zero extends from that (because we really don't need to care about bits
> > > beyond that precision).
> > > 
> > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> > 
> > Looks ok, thanks.
> 
> Actually, after committing it I've realized it was wrong.  Sorry for that.
> 
> By forcing UNSIGNED sign in wide_int::from it forces zero extension from the
> precision of the tree to prec, but if there are any bits in between, we
> need extension according to the sign of the constant.  As we create the
> wide_int with prec, comparison of the wide_ints only looks at the low prec
> bits (or, if both wide_ints are guaranteed to be sign-extended from that
> the bits above will match too).
> So, the right thing to do is wide_int::from (cst, prec, TYPE_SIGN (TREE_TYPE 
> (cst)))
> which is wi::to_wide (cst, prec).
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

Ok.

Marek


Re: [PATCH GCC][4/7]Choose exit edge/path when removing inner loop's exit statement

2017-10-09 Thread Richard Biener
On Thu, Oct 5, 2017 at 3:16 PM, Bin Cheng  wrote:
> Hi,
> Function generate_loops_for_partition chooses arbitrary path when removing 
> exit
> condition not in partition.  This is fine for now because it's impossible to 
> have
> loop exit condition in case of innermost distribution.  After extending to 
> loop
> nest distribution, we must choose exit edge/path for inner loop's exit 
> condition,
> otherwise an infinite empty loop will be generated.  Test case added.
>
> Bootstrap and test in patch set on x86_64 and AArch64, is it OK?

Ok.

Richard.

> Thanks,
> bin
> 2017-10-04  Bin Cheng  
>
> * tree-loop-distribution.c (generate_loops_for_partition): Remove
> inner loop's exit stmt by making it always exit the loop, otherwise
> we would generate an infinite empty loop.
>
> gcc/testsuite/ChangeLog
> 2017-10-04  Bin Cheng  
>
> * gcc.dg/tree-ssa/ldist-27.c: New test.


Re: [PATCH GCC][3/7]Don't skip renaming PHIs in loop nest with only one inner loop

2017-10-09 Thread Richard Biener
On Thu, Oct 5, 2017 at 3:16 PM, Bin Cheng  wrote:
> Hi,
> Function rename_variables_in_bb skips renaming PHI nodes in loop nest if the
> outer loop has only one inner loop.  This breaks loop nest distribution when
> inner loop has PHI node initialized from outer loop's variable.  
> Unfortunately,
> I lost the original C code illustrating the issue.  Now it is only triggered
> in building spec2006/416.gamess with loop nest distribution, but I failed to
> reduce a test from it.

Bah, can you re-try isolating a testcase?

> Bootstrap and test in patch set on x86_64 and AArch64, is it OK?

Ok.  Note that the renaming is a very fragile bit of code - you may run into
issues when applying it on loop nests ;)

Richard.

> Thanks,
> bin
> 2017-10-04  Bin Cheng  
>
> * tree-vect-loop-manip.c (rename_variables_in_bb): Rename PHI nodes
> when copying loop nest with only one inner loop.


Re: tree-complex.c: fix some_nonzerop test over reals (and a bug fix)

2017-10-09 Thread Laurent Thevenoux


- Mail original -
> De: "Richard Biener" 
> À: "Laurent Thevenoux" 
> Cc: "GCC Patches" 
> Envoyé: Lundi 9 Octobre 2017 14:04:49
> Objet: Re: tree-complex.c: fix some_nonzerop test over reals (and a bug fix)
> 
> On Fri, Oct 6, 2017 at 8:58 PM, Laurent Thevenoux
>  wrote:
> > Hi Richard, thanks for your quick reply.
> >
> > - Mail original -
> >> De: "Richard Biener" 
> >> À: "Laurent Thevenoux" 
> >> Cc: "GCC Patches" 
> >> Envoyé: Vendredi 6 Octobre 2017 13:42:57
> >> Objet: Re: tree-complex.c: fix some_nonzerop test over reals (and a bug
> >> fix)
> >>
> >> On Thu, Oct 5, 2017 at 4:41 PM, Laurent Thevenoux
> >>  wrote:
> >> > Hello,
> >> >
> >> > This patch improves the some_nonzerop(tree t) function from
> >> > tree-complex.c
> >> > file (the function is only used there).
> >> >
> >> > This function returns true if a tree as a parameter is not the constant
> >> > 0
> >> > (or +0.0 only for reals when !flag_signed_zeros ). The former result is
> >> > then used to determine if some simplifications are possible for complex
> >> > expansions (addition, multiplication, and division).
> >> >
> >> > Unfortunately, if the tree is a real constant, the function always
> >> > return
> >> > true, even for +0.0 because of the explicit test on flag_signed_zeros
> >> > (so
> >> > if your system enables signed zeros you cannot benefit from those
> >> > simplifications). To avoid this behavior and allow complex expansion
> >> > simplifications, I propose the following patch, which test for the sign
> >> > of
> >> > the real constant 0.0 instead of checking the flag.
> >>
> >> But
> >>
> >> +  if (TREE_CODE (t) == REAL_CST)
> >> +{
> >> +  if (real_identical (_REAL_CST (t), ))
> >> +   zerop = !real_isneg (_REAL_CST (t));
> >> +}
> >>
> >> shouldn't you do
> >>
> >>zerop = !flag_signed_zeros || !real_isneg (_REAL_CST (t));
> >>
> >> ?
> >
> > I’m not so sure. If I understand your proposition (tables below gives
> > values of zerop following the values of t and flag_signed_zeros):
> >
> >|   zerop
> >  t | !flag_signed_zeros is false | !flag_signed_zeros is true
> > -
> > +n | true*   | true*
> > -n | false   | true*
> >  0 | true| true
> > -0 | false   | unreachable
> >
> > But here, results with a * don't return the good value. The existing code
> > is also wrong, it always returns false if flag_signed_zeros is true, else
> > the code is correct:
> >
> >|   zerop
> >  t | !flag_signed_zeros is false | !flag_signed_zeros is true
> > -
> > +n | false   | false
> > -n | false   | false
> >  0 | true| false*
> > -0 | false   | unreachable
> >
> > With the code I propose, we obtain the right results:
> >
> >  t | zerop
> > --
> > +n | false
> > -n | false
> >  0 | true
> > -0 | false
> >
> > Do I really miss something (I'm sorry if I'm wrong)?
> >
> >>
> >> Also doesn't this miscalculate A - B for {ar, 0.} - {br, 0.} given the
> >> simplification simply
> >> returns bi?
> >
> > Here we are in case PAIR (ONLY_REAL, ONLY_REAL), which gives ri = 0. (ai)
> > even with signed zeros. So everything is OK.
> >
> >>
> >> So I'm not convinced this handling is correct.
> >>
> >> > This first fix reveals a bug (thanks to
> >> > c-c++-common/torture/complex-sign-add.c ) in the simplification section
> >> > of
> >> > expand_complex_addition (also fixed in the patch).
> >>
> >> Your patch looks backward and the existing code looks ok.
> >>
> >> @@ -937,7 +940,7 @@ expand_complex_addition (gimple_stmt_iterator
> >> *gsi, tree inner_type,
> >>
> >>  case PAIR (VARYING, ONLY_REAL):
> >>rr = gimplify_build2 (gsi, code, inner_type, ar, br);
> >> -  ri = ai;
> >> +  ri = bi;
> >>break;
> >
> > With the existing code we don’t perform the simplification step at all
> > since it always returns (VARYING, VARYING) when flag_signed_zeros is true.
> >
> > For instance, with {ar, -0.} + {br, 0.}, if simplification really occurs,
> > its in case PAIR (VARIYNG, ONLY_REAL) (because we consider -0. as a
> > non_zero), and it returns -0. if we return ai (instead of -0. + 0. -> 0.).
> > But I understand now that returning bi in this case is meaningless since
> > {br, bi} is a ONLY_REAL complex.
> >
> > Nevertheless, for instance, {ar, -0.} + {br, 0.} -> {ar + br, -0.} is still
> > buggy.
> >
> > A solution could be:
> >
> > case PAIR (VARYING, ONLY_REAL):
> >   rr = gimplify_build2 (gsi, code, inner_type, ar, br);
> > + if 

Re: [PATCH GCC][2/7]Don't rename variables for deleted new preheader

2017-10-09 Thread Richard Biener
On Thu, Oct 5, 2017 at 3:15 PM, Bin Cheng  wrote:
> Hi,
> I noticed that new_preheader basic block could be deleted if the copied
> loop is added at entry in function slpeel_tree_duplicate_loop_to_edge_cfg.
> This simple patch skips new_preheader during variable renaming if it is
> deleted.
> Bootstrap and test in patch set on x86_64 and AArch64, is it OK?

Ok.

Richard.

> Thanks,
> bin
> 2017-10-04  Bin Cheng  
>
> * tree-vect-loop-manip.c (slpeel_tree_duplicate_loop_to_edge_cfg): 
> Skip
> renaming variables in new preheader if it's deleted.


Re: [PATCH GCC][1/7]Delete unused field of struct partition in loop distribution

2017-10-09 Thread Richard Biener
On Thu, Oct 5, 2017 at 3:15 PM, Bin Cheng  wrote:
> Hi,
> This patch set implements distribution and builtin pattern distribution for
> loop nest.  It consists of below patches:
>   Patches [1~4]: Cleanup and (latent) bug fixes.
>   Patch [5]: Loop nest distribution of two-level innermost loop nest.
>   Patches [6,7]: Loop nest builtin pattern distribution.
>
> This is the first simple patch deleting unused field of struct partition in 
> loop
> distribution.  It's an obvious change.
> Bootstrap and test in patch set on x86_64 and AArch64.

Ok.

Richard.

> Thanks,
> bin
> 2017-10-04  Bin Cheng  
>
> * tree-loop-distribution.c (struct partition): Remove unused field
> loops of the structure.
> (partition_alloc, partition_free): Ditto.
> (build_rdg_partition_for_vertex): Ditto.


Re: Require wi::to_wide for trees

2017-10-09 Thread Richard Biener
On Tue, Oct 3, 2017 at 9:14 PM, Richard Sandiford
 wrote:
> One of the original requirements for getting wide-int.h accepted
> was that it should work efficiently on trees.  Through a process
> that I no longer recall exactly, this ended up meaning that we can
> use things like:
>
>wi::add (t, 1)
>
> to add 1 to an INTEGER_CST T in its native precision.  However, we also have:
>
>wi::to_offset (t)  // Treat T as an offset_int
>wi::to_widest (t)  // Treat T as a widest_int
>
> Recently we also gained:
>
>wi::to_wide (t, prec)  // Treat T as a wide_int in preccision PREC
>
> I'd like to revisit the decision to treat "wide_int trees" differently.
> Requiring:
>
>wi::to_wide (t)
>
> would be just as efficient, and would make it clearer that a deliberate
> choice is being made to treat the tree as a wide_int in its native
> precision.  This also removes the inconsistency that
>
> a) wide_int trees can be used without an accessor but must use wi::
>functions instead of C++ operators
>
> b) the other forms need an explicit accessor but the result can be used
>with C++ operators.
>
> It also helps with SVE, where there's the additional possibility
> that the tree could be a runtime value.
>
> Tested on aarch64-linux-gnu, x86_64-linux-gnu and powerpc64le-linux-gnu.
> Also tested by comparing the testsuite assembly output on at least one
> target per CPU directory.  OK to install?

So I thought on this on and off.  I like the consistency, not sure if it
adds much clarity to the casual observer though.  I don't like the
verbosity too much but lookign at the patch it isn't too bad.

Thus ...

ok.

Thanks,
Richard.

> If so, it might make sense to use wi::to_wide (rtx, mode) for rtxes too.
>
> Richard
>
>
> 2017-10-03  Richard Sandiford  
>
> gcc/
> * wide-int.h (wide_int_ref_storage): Make host_dependent_precision
> a template parameter.
> (WIDE_INT_REF_FOR): Update accordingly.
> * tree.h (wi::int_traits ): Delete.
> (wi::tree_to_widest_ref, wi::tree_to_offset_ref): New typedefs.
> (wi::to_widest, wi::to_offset): Use them.  Expand commentary.
> (wi::tree_to_wide_ref): New typedef.
> (wi::to_wide): New function.
> * calls.c (get_size_range): Use wi::to_wide when operating on
> trees as wide_ints.
> * cgraph.c (cgraph_node::create_thunk): Likewise.
> * config/i386/i386.c (ix86_data_alignment): Likewise.
> (ix86_local_alignment): Likewise.
> * dbxout.c (stabstr_O): Likewise.
> * dwarf2out.c (add_scalar_info, gen_enumeration_type_die): Likewise.
> * expr.c (const_vector_from_tree): Likewise.
> * fold-const-call.c (host_size_t_cst_p, fold_const_call_1): Likewise.
> * fold-const.c (may_negate_without_overflow_p, negate_expr_p)
> (fold_negate_expr_1, int_const_binop_1, const_binop)
> (fold_convert_const_int_from_real, optimize_bit_field_compare)
> (all_ones_mask_p, sign_bit_p, build_range_check, unextend)
> (extract_muldiv_1, fold_div_compare, fold_single_bit_test)
> (fold_plusminus_mult_expr, pointer_may_wrap_p, expr_not_equal_to)
> (fold_binary_loc, fold_ternary_loc, multiple_of_p, fold_negate_const)
> (fold_abs_const, fold_not_const, round_up_loc): Likewise.
> * gimple-fold.c (gimple_fold_indirect_ref): Likewise.
> * gimple-ssa-warn-alloca.c (alloca_call_type_by_arg): Likewise.
> (alloca_call_type): Likewise.
> * gimple.c (preprocess_case_label_vec_for_gimple): Likewise.
> * godump.c (go_output_typedef): Likewise.
> * graphite-sese-to-poly.c (tree_int_to_gmp): Likewise.
> * internal-fn.c (get_min_precision): Likewise.
> * ipa-cp.c (ipcp_store_vr_results): Likewise.
> * ipa-polymorphic-call.c
> (ipa_polymorphic_call_context::ipa_polymorphic_call_context): 
> Likewise.
> * ipa-prop.c (ipa_print_node_jump_functions_for_edge): Likewise.
> (ipa_modify_call_arguments): Likewise.
> * match.pd: Likewise.
> * omp-low.c (scan_omp_1_op, lower_omp_ordered_clauses): Likewise.
> * print-tree.c (print_node_brief, print_node): Likewise.
> * stmt.c (expand_case): Likewise.
> * stor-layout.c (layout_type): Likewise.
> * tree-affine.c (tree_to_aff_combination): Likewise.
> * tree-cfg.c (group_case_labels_stmt): Likewise.
> * tree-data-ref.c (dr_analyze_indices): Likewise.
> (prune_runtime_alias_test_list): Likewise.
> * tree-dump.c (dequeue_and_dump): Likewise.
> * tree-inline.c (remap_gimple_op_r, copy_tree_body_r): Likewise.
> * tree-predcom.c (is_inv_store_elimination_chain): Likewise.
> * tree-pretty-print.c (dump_generic_node): Likewise.
> * tree-scalar-evolution.c (iv_can_overflow_p): Likewise.
> (simple_iv_with_niters): Likewise.

Re: [PATCH][PING][PR 81376] Remove unnecessary float casts in comparisons

2017-10-09 Thread Richard Biener
On Mon, Oct 9, 2017 at 11:12 AM, Yuri Gribov  wrote:
> Hi all,
>
> This patch gets rid of float casts in comparisons when all values of
> casted integral type are exactly representable by the float type
> (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81376).
>
> Bootstrapped and regtested on x64_64. Ok to commit?

+bool format_helper::can_represent_integral_type_p (tree type) const
+{
+  gcc_assert (! decimal_p () && INTEGRAL_TYPE_P (type) && "NYI");

"NYI"?

+/* Determine the largest type.  */
+

excess vertical space

+signop sign1 = TYPE_SIGN (type1),
+  sign2 = TYPE_SIGN (type2);
+int prec1 = TYPE_PRECISION (type1),
+  prec2 = TYPE_PRECISION (type2);
+
+bool type1_largest_p = (sign1 == sign2 && prec2 <= prec1)
+  || (sign1 == SIGNED && sign2 == UNSIGNED && prec2 < prec1);
+bool type2_largest_p = (sign1 == sign2 && prec1 <= prec2)
+  || (sign1 == UNSIGNED && sign2 == SIGNED && prec1 < prec2);
+   }
+   (switch

I dislike too many temporaries, isn't

  (if (TYPE_PRECISION (type1) > TYPE_PRECISION (type2))
(cmp @1 (convert @2)
(if (TYPE_PRECISION (type2) > TYPE_PRECISION (type1))
 (cmp (convert @1) @2)
 (if (TYPE_SIGN (type1) == TYPE_SIGN (type2))
  (cmp @1 @2)

easier to follow?  Note the if-else cascade, note the (convert ..)s do not
need an explicit type.

I wonder if we anywhere "canonicalize" non-simple comparison operators
(unle, ltgt, etc.) for comparisons involving integer-to-float
converted operands.

Thanks,
Richard.

> -Y


Re: [PATCH 1/9] [SFN] adjust RTL insn-walking API

2017-10-09 Thread Richard Biener
On Sat, Sep 30, 2017 at 11:08 AM, Alexandre Oliva  wrote:
> This patch removes unused RTL functions, introduces alternate ones for
> use in a later SFN patch, and regroups other related functions so that
> they appear in a more consistent order.

Ok.

Thanks,
Richard.

> for  gcc/ChangeLog
>
> * emit-rtl.c (next_nondebug_insn, prev_nondebug_insn): Reorder.
> (next_nonnote_nondebug_insn, prev_nonnote_nondebug_insn): Reorder.
> (next_nonnote_nondebug_insn_bb): New.
> (prev_nonnote_nondebug_insn_bb): New.
> (prev_nonnote_insn_bb, next_nonnote_insn_bb): Remove.
> * rtl.h (prev_nonnote_insn_bb, next_nonnote_insn_bb): Remove decls.
> (prev_nonnote_nondebug_insn_bb): Declare.
> (next_nonnote_nondebug_insn_bb): Declare.
> * cfgbuild.c (find_bb_boundaries): Adjust to skip debug insns.
> * cfgrtl.c (get_last_bb_insn): Likewise.
> * lra.c (push_insns): Likewise.
> ---
>  gcc/cfgbuild.c |  2 +-
>  gcc/cfgrtl.c   |  4 ++--
>  gcc/emit-rtl.c | 69 
> --
>  gcc/lra.c  |  2 +-
>  gcc/rtl.h  |  4 ++--
>  5 files changed, 44 insertions(+), 37 deletions(-)
>
> diff --git a/gcc/cfgbuild.c b/gcc/cfgbuild.c
> index 62956b2..76c21d7 100644
> --- a/gcc/cfgbuild.c
> +++ b/gcc/cfgbuild.c
> @@ -512,7 +512,7 @@ find_bb_boundaries (basic_block bb)
>  the middle of a BB.  We need to split it in the same manner as
>  if the barrier were preceded by a control_flow_insn_p insn.  */
>   if (!flow_transfer_insn)
> -   flow_transfer_insn = prev_nonnote_insn_bb (insn);
> +   flow_transfer_insn = prev_nonnote_nondebug_insn_bb (insn);
> }
>
>if (control_flow_insn_p (insn))
> diff --git a/gcc/cfgrtl.c b/gcc/cfgrtl.c
> index 6ef47b7..bce56b4 100644
> --- a/gcc/cfgrtl.c
> +++ b/gcc/cfgrtl.c
> @@ -2274,11 +2274,11 @@ get_last_bb_insn (basic_block bb)
>  end = table;
>
>/* Include any barriers that may follow the basic block.  */
> -  tmp = next_nonnote_insn_bb (end);
> +  tmp = next_nonnote_nondebug_insn_bb (end);
>while (tmp && BARRIER_P (tmp))
>  {
>end = tmp;
> -  tmp = next_nonnote_insn_bb (end);
> +  tmp = next_nonnote_nondebug_insn_bb (end);
>  }
>
>return end;
> diff --git a/gcc/emit-rtl.c b/gcc/emit-rtl.c
> index e790cbc..68c1f11 100644
> --- a/gcc/emit-rtl.c
> +++ b/gcc/emit-rtl.c
> @@ -3355,20 +3355,17 @@ next_nonnote_insn (rtx_insn *insn)
>return insn;
>  }
>
> -/* Return the next insn after INSN that is not a NOTE, but stop the
> -   search before we enter another basic block.  This routine does not
> -   look inside SEQUENCEs.  */
> +/* Return the next insn after INSN that is not a DEBUG_INSN.  This
> +   routine does not look inside SEQUENCEs.  */
>
>  rtx_insn *
> -next_nonnote_insn_bb (rtx_insn *insn)
> +next_nondebug_insn (rtx_insn *insn)
>  {
>while (insn)
>  {
>insn = NEXT_INSN (insn);
> -  if (insn == 0 || !NOTE_P (insn))
> +  if (insn == 0 || !DEBUG_INSN_P (insn))
> break;
> -  if (NOTE_INSN_BASIC_BLOCK_P (insn))
> -   return NULL;
>  }
>
>return insn;
> @@ -3390,67 +3387,70 @@ prev_nonnote_insn (rtx_insn *insn)
>return insn;
>  }
>
> -/* Return the previous insn before INSN that is not a NOTE, but stop
> -   the search before we enter another basic block.  This routine does
> -   not look inside SEQUENCEs.  */
> +/* Return the previous insn before INSN that is not a DEBUG_INSN.
> +   This routine does not look inside SEQUENCEs.  */
>
>  rtx_insn *
> -prev_nonnote_insn_bb (rtx_insn *insn)
> +prev_nondebug_insn (rtx_insn *insn)
>  {
> -
>while (insn)
>  {
>insn = PREV_INSN (insn);
> -  if (insn == 0 || !NOTE_P (insn))
> +  if (insn == 0 || !DEBUG_INSN_P (insn))
> break;
> -  if (NOTE_INSN_BASIC_BLOCK_P (insn))
> -   return NULL;
>  }
>
>return insn;
>  }
>
> -/* Return the next insn after INSN that is not a DEBUG_INSN.  This
> -   routine does not look inside SEQUENCEs.  */
> +/* Return the next insn after INSN that is not a NOTE nor DEBUG_INSN.
> +   This routine does not look inside SEQUENCEs.  */
>
>  rtx_insn *
> -next_nondebug_insn (rtx_insn *insn)
> +next_nonnote_nondebug_insn (rtx_insn *insn)
>  {
>while (insn)
>  {
>insn = NEXT_INSN (insn);
> -  if (insn == 0 || !DEBUG_INSN_P (insn))
> +  if (insn == 0 || (!NOTE_P (insn) && !DEBUG_INSN_P (insn)))
> break;
>  }
>
>return insn;
>  }
>
> -/* Return the previous insn before INSN that is not a DEBUG_INSN.
> -   This routine does not look inside SEQUENCEs.  */
> +/* Return the next insn after INSN that is not a NOTE nor DEBUG_INSN,
> +   but stop the search before we enter another basic block.  This
> +   routine does not look inside SEQUENCEs.  */
>
>  rtx_insn *
> -prev_nondebug_insn (rtx_insn *insn)
> +next_nonnote_nondebug_insn_bb (rtx_insn *insn)
>  {
>

Re: [PATCH 5/9] [SFN] Introduce -gstatement-frontiers option, enable debug markers

2017-10-09 Thread Richard Biener
On Sat, Sep 30, 2017 at 11:08 AM, Alexandre Oliva  wrote:
> Introduce a command line option to enable statement frontiers, enabled
> by default in optimized builds with DWARF2+ debug information.
>
> This patch depends on an earlier patch that completed the
> infrastructure for debug markers, and on another patch that turns -g
> into a negatable option prefix.

Ok.

Richard.

> gcc/ChangeLog
>
> * common.opt (gstatement-frontiers): New, setting
> debug_nonbind_markers_p.
> * rtl.h (MAY_HAVE_DEBUG_MARKER_INSNS): Activate.
> * toplev.c (process_options): Autodetect value for debug statement
> frontiers option.
> * tree.h (MAY_HAVE_DEBUG_MARKER_STMTS): Activate.
> * doc/invoke.texi (gstatement-frontiers, gno-statement-frontiers): 
> New.
> ---
>  gcc/common.opt  |  4 
>  gcc/doc/invoke.texi | 12 
>  gcc/rtl.h   |  2 +-
>  gcc/toplev.c|  4 
>  gcc/tree.h  |  2 +-
>  5 files changed, 22 insertions(+), 2 deletions(-)
>
> diff --git a/gcc/common.opt b/gcc/common.opt
> index dfde6ad..a12c11c 100644
> --- a/gcc/common.opt
> +++ b/gcc/common.opt
> @@ -2889,6 +2889,10 @@ gstabs+
>  Common Driver JoinedOrMissing Negative(gvms)
>  Generate debug information in extended STABS format.
>
> +gstatement-frontiers
> +Common Driver Var(debug_nonbind_markers_p) Init(2)
> +Emit progressive recommended breakpoint locations.
> +
>  gstrict-dwarf
>  Common Driver Report Var(dwarf_strict) Init(0)
>  Don't emit DWARF additions beyond selected version.
> diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
> index 108d730..85e41e4 100644
> --- a/gcc/doc/invoke.texi
> +++ b/gcc/doc/invoke.texi
> @@ -346,6 +346,7 @@ Objective-C and Objective-C++ Dialects}.
>  -ggdb  -grecord-gcc-switches  -gno-record-gcc-switches @gol
>  -gstabs  -gstabs+  -gstrict-dwarf  -gno-strict-dwarf @gol
>  -gcolumn-info  -gno-column-info @gol
> +-gstatement-frontiers  -gno-statement-frontiers @gol
>  -gvms  -gxcoff  -gxcoff+  -gz@r{[}=@var{type}@r{]} @gol
>  -fdebug-prefix-map=@var{old}=@var{new}  -fdebug-types-section @gol
>  -fno-eliminate-unused-debug-types @gol
> @@ -7040,6 +7041,17 @@ Emit location column information into DWARF debugging 
> information, rather
>  than just file and line.
>  This option is disabled by default.
>
> +@item -gstatement-frontiers
> +@item -gno-statement-frontiers
> +@opindex gstatement-frontiers
> +@opindex gno-statement-frontiers
> +This option causes GCC to create markers in the internal representation
> +at the beginning of statements, and to keep them roughly in place
> +throughout compilation, using them to guide the output of @code{is_stmt}
> +markers in the line number table.  This is enabled by default when
> +compiling with optimization (@option{-Os}, @option{-O}, @option{-O2},
> +@dots{}), and outputting DWARF 2 debug information at the normal level.
> +
>  @item -gz@r{[}=@var{type}@r{]}
>  @opindex gz
>  Produce compressed debug sections in DWARF format, if that is supported.
> diff --git a/gcc/rtl.h b/gcc/rtl.h
> index c79a277..a0c27fc 100644
> --- a/gcc/rtl.h
> +++ b/gcc/rtl.h
> @@ -816,7 +816,7 @@ struct GTY(()) rtvec_def {
>  #define NONDEBUG_INSN_P(X) (INSN_P (X) && !DEBUG_INSN_P (X))
>
>  /* Nonzero if DEBUG_MARKER_INSN_P may possibly hold.  */
> -#define MAY_HAVE_DEBUG_MARKER_INSNS 0 /* debug_nonbind_markers_p */
> +#define MAY_HAVE_DEBUG_MARKER_INSNS debug_nonbind_markers_p
>  /* Nonzero if DEBUG_BIND_INSN_P may possibly hold.  */
>  #define MAY_HAVE_DEBUG_BIND_INSNS flag_var_tracking_assignments
>  /* Nonzero if DEBUG_INSN_P may possibly hold.  */
> diff --git a/gcc/toplev.c b/gcc/toplev.c
> index bee79d3..0ef46da 100644
> --- a/gcc/toplev.c
> +++ b/gcc/toplev.c
> @@ -1514,6 +1514,10 @@ process_options (void)
>  warning_at (UNKNOWN_LOCATION, 0,
> "var-tracking-assignments changes selective scheduling");
>
> +  if (debug_nonbind_markers_p == AUTODETECT_VALUE)
> +debug_nonbind_markers_p = optimize && debug_info_level >= 
> DINFO_LEVEL_NORMAL
> +  && (write_symbols == DWARF2_DEBUG || write_symbols == 
> VMS_AND_DWARF2_DEBUG);
> +
>if (flag_tree_cselim == AUTODETECT_VALUE)
>  {
>if (HAVE_conditional_move)
> diff --git a/gcc/tree.h b/gcc/tree.h
> index 62a85ea..8c3bda1 100644
> --- a/gcc/tree.h
> +++ b/gcc/tree.h
> @@ -1127,7 +1127,7 @@ extern void omp_clause_range_check_failed (const_tree, 
> const char *, int,
>((int)TREE_INT_CST_LOW (VL_EXP_CHECK (NODE)->exp.operands[0]))
>
>  /* Nonzero if gimple_debug_nonbind_marker_p() may possibly hold.  */
> -#define MAY_HAVE_DEBUG_MARKER_STMTS 0 /* debug_nonbind_markers_p */
> +#define MAY_HAVE_DEBUG_MARKER_STMTS debug_nonbind_markers_p
>  /* Nonzero if gimple_debug_bind_p() (and thus
> gimple_debug_source_bind_p()) may possibly hold.  */
>  #define MAY_HAVE_DEBUG_BIND_STMTS flag_var_tracking_assignments
> --
> 2.9.5
>


Re: [PATCH 4/9] [SFN] introduce statement frontier notes, still disabled

2017-10-09 Thread Richard Biener
On Sat, Sep 30, 2017 at 11:08 AM, Alexandre Oliva  wrote:
> This patch completes the infrastructure for the introduction of
> statement frontiers in C-family languages.
>
> It brings in all the code remaining code needed to introduce and
> transform begin stmt trees, gimple stmts, insns and notes, and
> ultimately use them to generate the is_stmt column in DWARF2+ line
> number tables/programs, however none of it is activated: the option
> that would do so will be introduced in a subsequent patch.
>
> This patch depends on an earlier patch with not-quite-boilerplate
> changes towards SFN.

The middle-end changes are ok.   The C FE change looks reasonable,
I'd appreciate a 2nd look at the C++ FE changes by a maintainer.

Thanks,
Richard.

> for  gcc/c-family/ChangeLog
>
> * c-semantics.c (pop_stmt_list): Move begin stmt marker into
> subsequent statement list.
>
> for  gcc/c/ChangeLog
>
> * c-objc-common.h (LANG_HOOKS_EMITS_BEGIN_STMT): Redefine as true.
> * c-parser.c (add_debug_begin_stmt): New.
> (c_parser_declaration_or_fndef): Call it.
> (c_parser_compound_statement_nostart): Likewise.
> (c_parser_statement_after_labels): Likewise.
> * c-typeck (c_finish_stmt_expr): Skip begin stmts markers.
>
> for  gcc/cp/ChangeLog
>
> * constexpr.c (build_data_member_initialization): Skip begin stmt
> markers.
> (check_constexpr_ctor_body_1): Likewise.
> (build_constexpr_constructor_member_initializers): Likewise.
> (constexpr_fn_retval): Likewise.
> (cxx_eval_statement_list): Likewise.
> (potential_constant_expression_1): Likewise.
> * cp-array-notation.c (stmt_location): New.
> (cp_expand_cond_array_notations): Use it.
> * cp-objcp-common.h (LANG_HOOKS_EMITS_BEGIN_STMT): Redefine as true.
> * parser.c (add_debug_begin_stmt): New.
> (cp_parser_statement): Call it.
> * pt.c (tsubst_copy): Handle begin stmt markers.
>
> for  gcc/ChangeLog
>
> * cfgexpand.c (expand_gimple_basic_block): Handle begin stmt
> markers.  Integrate source bind into debug stmt expand loop.
> (pass_expand::execute): Check debug marker limit.  Avoid deep
> TER and expand debug locations for debug bind insns only.
> * cse.c (insn_live_p): Keep nonbind markers and debug bindings
> followed by them.
> * df-scan.c (df_insn_delete): Accept out-of-block debug insn.
> * final.c (reemit_insn_block_notes): Take current block from
> nonbind markers.  Declare note where it's first set.
> (final_scan_insn): Handle begin stmt notes.  Emit is_stmt according to
> begin stmt markers if enabled.
> (notice_source_line): Handle nonbind markers.  Fail if their
> location is unknown or that of builtins.
> (rest_of_handle_final): Convert begin stmt markers to notes if
> var-tracking didn't run.
> (rest_of_clean_state): Skip begin stmt markers.
> * gimple-pretty-print.c (dump_gimple_debug): Handle begin stmt
> markers.
> * function.c (allocate_struct_function): Set begin_stmt_markers.
> * function.h (struct function): Add debug_marker_count counter
> and debug_nonbind_markers flag.
> * gimple-iterator.c (gsi_remove): Adjust debug_marker_count.
> * gimple-low.c (lower_function_body): Adjust
> debug_nonbind_markers.
> (lower_stmt): Drop or skip gimple debug stmts.
> (lower_try_catch): Skip debug stmts.
> * gimple.c (gimple_build_debug_begin_stmt): New.
> (gimple_copy): Increment debug_marker_count if copying one.
> * gimple.h (gimple_build_debug_begin_stmt): Declare.
> * gimplify.c (rexpr_location): New.
> (rexpr_has_location): New.
> (warn_switch_unreachable_r): Handle gimple debug stmts.
> (shortcut_cond_r): Call expr_location.
> (find_goto): New.
> (find_goto_label): New.
> (shortcut_cond_expr): Call expr_has_location, expr_location, and
> find_goto_label.
> (gimplify_cond_expr): Call find_goto_label, expr_has_location, and
> expr_location.
> (gimplify_expr): Handle begin stmt markers.  Reject debug expr decls.
> * langhooks-def.h (LANG_HOOKS_EMITS_BEGIN_STMT): New.  Add to...
> (LANG_HOOKS_INITIALIZER): ... this.
> * langhooks.h (struct lang_hooks): Add emits_begin_stmt.
> * lra-contraints.c (inherit_reload_reg): Tolerate between-blocks
> debug insns.
> (update_ebb_live_info): Skip debug insn markers.
> * lra.c (debug_insn_static_data): Rename to...
> (debug_bind_static_data): ... this.
> (debug_marker_static_data): New.
> (lra_set_insn_recog_data): Select one of the above depending
> on debug insn kind.
> (lra_update_isn_regno_info): Don't assume debug insns have
>

Re: [PATCH][mingw] Enable colorized diagnostics

2017-10-09 Thread Liu Hao

On 2017/10/9 19:01, JonY wrote:

On 10/08/2017 11:39 AM, Liu Hao wrote:

I'm not sure if it should be enabled by default due to the interleaving
problem, but seeing as the user has to go out to set GCC_COLORS to use
this feature, I suppose it is OK.

I will commit soon if there are no more comments.




Thank you. By the way I noticed a mistake in the comments above 
`find_esc_terminator()`. This function returns zero on failure like its 
`find_esc_head()` counterpart, while the comments mistakenly referred 
-1. Please correct it before committing.



--
Best regards,
LH_Mouse



Re: [PATCH 3/9] [SFN] not-quite-boilerplate changes in preparation to introduce nonbind markers

2017-10-09 Thread Richard Biener
On Sat, Sep 30, 2017 at 11:08 AM, Alexandre Oliva  wrote:
> This patch adjusts numerous parts of the compiler that would
> malfunction should they find debug markers at points where they may be
> introduced.  The changes purport to allow the compiler to pass
> bootstrap-debug-lean (-fcompare-debug in stage3) at various
> optimization levels, as well as bootstrap-debug-lib (-fcompare-debug
> for target libraries), even after the compiler is changed so that
> debug markers are introduced in code streams at spots where earlier
> debug stmts, insns and notes wouldn't normally appear.
>
> This patch depends on an earlier SFN boilerplate patch, and on another
> SFN patch that introduces new RTL insn-walking functions.

Ok.

Thanks,
Richard.

> for  gcc/ChangeLog
>
> * cfgcleanup.c (delete_unreachable_blocks): Use alternate
> block removal order if MAY_HAVE_DEBUG_BIND_INSNS.
> * cfgexpand.c (label_rtx_for_bb): Skip debug insns.
> * cfgrtl.c (try_redirect_by_replacing_jump): Skip debug insns.
> (rtl_tidy_fallthru_edge): Likewise.
> (rtl_verify_fallthru): Likewise.
> (rtl_verify_bb_layout): Likewise.
> (skip_insns_after_block): Likewise.
> (duplicate_insn_chain): Use DEBUG_BIND_INSN_P.
> * dwarf2out.c: Include print-rtl.h.
> (dwarf2out_next_real_insn): New.
> (dwarf2out_var_location): Call it.  Disregard begin stmt markers.
> Dump debug binds in asm comments.
> * gimple-iterator.c (gimple_find_edge_insert_loc): Skip debug stmts.
> * gimple-iterator.h (gsi_start_bb_nondebug): Remove; adjust
> callers to use gsi_start_nondebug_bb instead.
> (gsi_after_labels): Skip gimple debug stmts.
> (gsi_start_nondebug): New.
> * gimple-low.c (gimple_seq_may_fallthru): Take last nondebug stmt.
> * gimple.h (gimple_seq_last_nondebug_stmt): New.
> * gimplify.c (last_stmt_in_scope): Skip debug stmts.
> (collect_fallthrough_labels): Likewise.
> (should_warn_for_implicit_fallthrough): Likewise.
> (warn_implicit_fallthrough_r): Likewise.
> (expand_FALLTHROUGH_r): Likewise.
> * graphite-isl-ast-to-gimple.c (gsi_insert_earliest): Adjust.
> (rename_uses): Skip nonbind markers.
> * graphite-scop-detection.c (trivially_empty_bb_p): Call
> is_gimple_debug in test.
> * haifa-sched.c (sched_extend_bb): Skip debug insns.
> * ipa-icf-gimple.c (func_checker::compare_bb): Adjust.
> * jump.c (clean_barriers): Skip debug insns.
> * omp-expand.c (expand_parallel_call): Skip debug insns.
> (expand_cilk_for_call): Likewise.
> (expand_task_call): Likewise.
> (remove_exit_barrier): Likewise.
> (expand_omp_taskreg): Likewise.
> (expand_omp_for_init_counts): Likewise.
> (expand_omp_for_generic): Likewise.
> (expand_omp_for_static_nochunk): Likewise.
> (expand_omp_for_static_chunk): Likewise.
> (expand_cilk_for): Likewise.
> (expand_omp_simd): Likewise.
> (expand_omp_taskloop_for_outer): Likewise.
> (expand_omp_taskloop_for_inner): Likewise.
> (expand_oacc_for): Likewise.
> (expand_omp_sections): Likewise.
> (expand_omp_single): Likewise.
> (expand_omp_synch): Likewise.
> (expand_omp_atomic_load): Likewise.
> (expand_omp_atomic_store): Likewise.
> (expand_omp_atomic_fetch_op): Likewise.
> (expand_omp_atomic_pipeline): Likewise.
> (expand_omp_atomic_mutex): Likewise.
> (expand_omp_target): Likewise.
> (grid_expand_omp_for_loop): Likewise.
> (grid_expand_target_grid_body): Likewise.
> (build_omp_regions_1): Likewise.
> * omp-low.c (check_combined_parallel): Skip debug stmts.
> * postreload.c (fixup_debug_insns): Skip nonbind debug insns.
> * regcprop.c (find_oldest_value_reg): Ensure REGNO is not a pseudo.
> * tree-cfg.c (make_blobs_1): Skip debug stmts.
> (make_edges): Likewise.
> (cleanup_dead_labels): Likewise.
> (gimple_can_merge_blocks_p): Likewise.
> (stmt_starts_bb_p): Likewise.
> (gimple_block_label): Likewise.
> (gimple_redirect_edge_and_branch): Likewise.
> * tree-cfgcleanup.c (remove_forwarder_block): Rearrange skipping
> of debug stmts.
> (execute_cleanup_cfg_post_optimizing): Dump enumerated decls with
> TDF_SLIM.
> * tree-pretty-print (print_declaration): Omit initializer in slim
> dumps.
> * tree-ssa-dce.c (mark_stmt_if_obviously_necessary): Mark begin stmt
> markers.
> (eliminate_unnecessary_stmts): Stabilize block removal order.
> * tree-ssa-tail-merge.c (find_duplicate): Skip debug stmts.
> * var-tracking.c (get_first_insn): New.
> (vt_emit_notes): Call it.
> (vt_initialize): Walk any 

Re: [PATCH][GCC] Simplification of 1U << (31 - x)

2017-10-09 Thread Wilco Dijkstra
Richard Biener wrote:

> I think the patch is ok with these changes but obviously we should try
> to address
> the code-generation issue on x86 at RTL expansion time.  They are sort-of
> existing missing optimizations.

Note the only x64 specific issue is the backend expansion of 64-bit immediates
which could be improved like I suggested. However what we're really missing
is a generic optimization pass that tries to simplify immediates using accurate
target costs. In eg. x >= C or x > C we can use either C or C-1 - on many 
targets
one option may be a single instruction, while the other might take 2 or even 3.

Wilco

Re: [PATCH, ARM] correctly encode the CC reg data flow

2017-10-09 Thread Richard Earnshaw (lists)
On 06/09/17 14:17, Bernd Edlinger wrote:
> On 09/06/17 14:51, Richard Earnshaw (lists) wrote:
>> On 06/09/17 13:44, Bernd Edlinger wrote:
>>> On 09/04/17 21:54, Bernd Edlinger wrote:
 Hi Kyrill,

 Thanks for your review!


 On 09/04/17 15:55, Kyrill Tkachov wrote:
> Hi Bernd,
>
> On 18/01/17 15:36, Bernd Edlinger wrote:
>> On 01/13/17 19:28, Bernd Edlinger wrote:
>>> On 01/13/17 17:10, Bernd Edlinger wrote:
 On 01/13/17 14:50, Richard Earnshaw (lists) wrote:
> On 18/12/16 12:58, Bernd Edlinger wrote:
>> Hi,
>>
>> this is related to PR77308, the follow-up patch will depend on this
>> one.
>>
>> When trying the split the *arm_cmpdi_insn and *arm_cmpdi_unsigned
>> before reload, a mis-compilation in libgcc function
>> __gnu_satfractdasq
>> was discovered, see [1] for more details.
>>
>> The reason seems to be that when the *arm_cmpdi_insn is directly
>> followed by a *arm_cmpdi_unsigned instruction, both are split
>> up into this:
>>
>>  [(set (reg:CC CC_REGNUM)
>>(compare:CC (match_dup 0) (match_dup 1)))
>>   (parallel [(set (reg:CC CC_REGNUM)
>>   (compare:CC (match_dup 3) (match_dup 4)))
>>  (set (match_dup 2)
>>   (minus:SI (match_dup 5)
>>(ltu:SI (reg:CC_C CC_REGNUM)
>> (const_int
>> 0])]
>>
>>  [(set (reg:CC CC_REGNUM)
>>(compare:CC (match_dup 2) (match_dup 3)))
>>   (cond_exec (eq:SI (reg:CC CC_REGNUM) (const_int 0))
>>  (set (reg:CC CC_REGNUM)
>>   (compare:CC (match_dup 0) (match_dup 1]
>>
>> The problem is that the reg:CC from the *subsi3_carryin_compare
>> is not mentioning that the reg:CC is also dependent on the reg:CC
>> from before.  Therefore the *arm_cmpsi_insn appears to be
>> redundant and thus got removed, because the data values are
>> identical.
>>
>> I think that applies to a number of similar pattern where data
>> flow is happening through the CC reg.
>>
>> So this is a kind of correctness issue, and should be fixed
>> independently from the optimization issue PR77308.
>>
>> Therefore I think the patterns need to specify the true
>> value that will be in the CC reg, in order for cse to
>> know what the instructions are really doing.
>>
>>
>> Bootstrapped and reg-tested on arm-linux-gnueabihf.
>> Is it OK for trunk?
>>
> I agree you've found a valid problem here, but I have some issues
> with
> the patch itself.
>
>
> (define_insn_and_split "subdi3_compare1"
> [(set (reg:CC_NCV CC_REGNUM)
>   (compare:CC_NCV
> (match_operand:DI 1 "register_operand" "r")
> (match_operand:DI 2 "register_operand" "r")))
>  (set (match_operand:DI 0 "register_operand" "=")
>   (minus:DI (match_dup 1) (match_dup 2)))]
> "TARGET_32BIT"
> "#"
> "&& reload_completed"
> [(parallel [(set (reg:CC CC_REGNUM)
>  (compare:CC (match_dup 1) (match_dup 2)))
> (set (match_dup 0) (minus:SI (match_dup 1) (match_dup
> 2)))])
>  (parallel [(set (reg:CC_C CC_REGNUM)
>  (compare:CC_C
>(zero_extend:DI (match_dup 4))
>(plus:DI (zero_extend:DI (match_dup 5))
> (ltu:DI (reg:CC_C CC_REGNUM) (const_int 0)
> (set (match_dup 3)
>  (minus:SI (minus:SI (match_dup 4) (match_dup 5))
>(ltu:SI (reg:CC_C CC_REGNUM) (const_int 0])]
>
>
> This pattern is now no-longer self consistent in that before the
> split
> the overall result for the condition register is in mode CC_NCV, but
> afterwards it is just CC_C.
>
> I think CC_NCV is correct mode (the N, C and V bits all correctly
> reflect the result of the 64-bit comparison), but that then
> implies that
> the cc mode of subsi3_carryin_compare is incorrect as well and
> should in
> fact also be CC_NCV.  Thinking about this pattern, I'm inclined to
> agree
> that CC_NCV is the correct mode for this operation
>
> I'm not sure if there are other consequences that will fall out from
> fixing this (it's possible that we might need a change to
> select_cc_mode
> as well).
>
 Yes, this is still a bit 

Re: [PATCH 2/9] [SFN] boilerplate changes in preparation to introduce nonbind markers

2017-10-09 Thread Richard Biener
On Sat, Sep 30, 2017 at 11:08 AM, Alexandre Oliva  wrote:
> This patch introduces a number of new macros and functions that will
> be used to distinguish between different kinds of debug stmts, insns
> and notes, namely, preexisting debug bind ones and to-be-introduced
> nonbind markers.
>
> In a seemingly mechanical way, it adjusts several uses of the macros
> and functions, so that they refer to narrower categories when
> appropriate.
>
> These changes, by themselves, should not have any visible effect in
> the compiler behavior, since the upcoming debug markers are never
> created with this patch alone.

Ok.

Thanks,
Richard.

> for  gcc/ChangeLog
>
> * gimple.h (enum gimple_debug_subcode): Add
> GIMPLE_DEBUG_BEGIN_STMT.
> (gimple_debug_begin_stmt_p): New.
> (gimple_debug_nonbind_marker_p): New.
> * tree.h (MAY_HAVE_DEBUG_MARKER_STMTS): New.
> (MAY_HAVE_DEBUG_BIND_STMTS): Renamed from
> (MAY_HAVE_DEBUG_STMTS): ... this.  Check both.
> * insn-notes.def (BEGIN_STMT): New.
> * rtl.h (MAY_HAVE_DEBUG_MARKER_INSNS): New.
> (MAY_HAVE_DEBUG_BIND_INSNS): Renamed from
> (MAY_HAVE_DEBUG_INSNS): ... this.  Check both.
> (NOTE_MARKER_LOCATION, NOTE_MARKER_P): New.
> (DEBUG_BIND_INSN_P, DEBUG_MARKER_INSN_P): New.
> (INSN_DEBUG_MARKER_KIND): New.
> (INSN_VAR_LOCATION): Check for VAR_LOCATION.
> (INSN_VAR_LOCATION_PTR): New.
> * cfgexpand.c (expand_debug_locations): Handle debug bind insns
> only.
> (expand_gimple_basic_block): Likewise.  Emit debug temps for TER
> deps only if debug bind insns are enabled.
> (pass_expand::execute): Avoid deep TER and expand
> debug locations for debug bind insns only.
> * cgraph.c (cgraph_edge::redirect_call_stmt_to_callee): Narrow
> debug stmts special handling down to debug bind stmts.
> * combine.c (try_combine): Narrow debug insns special handling
> down to debug bind insns.
> * cse.c (delete_trivially_dead_insns): Handle debug bindings.
> Narrow debug insns preexisting special handling down to debug
> bind insns.
> * dce.c (rest_of_handle_ud_dce): Narrow debug insns special
> handling down to debug bind insns.
> * function.c (instantiate_virtual_regs): Skip debug markers,
> adjust handling of debug binds.
> * gimple-ssa-backprop.c (backprop::prepare_change): Try debug
> temp insertion iff MAY_HAVE_DEBUG_BIND_STMTS.
> * haifa-sched.c (schedule_insn): Narrow special handling of debug
> insns to debug bind insns.
> * ipa-prop.c (ipa_modify_call_arguments): Narrow special
> handling of debug insns to debug bind insns.
> * ipa-split.c (split_function): Likewise.
> * ira.c (combine_and_move_insns): Adjust debug bind insns only.
> * loop-unroll.c (apply_opt_in_copies): Adjust tests on bind
> debug insns.
> * reg-stack.c (convert_regs_1): Use DEBUG_BIND_INSN_P.
> * regrename.c (build_def_use): Likewise.
> * regcprop.c (copyprop_hardreg_forward_1): Likewise.
> (pass_cprop_hardreg): Narrow special casing of debug insns to
> debug bind insns.
> * regstat.c (regstat_init_n_sets_and_refs): Likewise.
> * reload1.c (reload): Likewise.
> * sese.c (sese_build_liveouts): Narrow special casing of debug
> stmts to debug bind stmts.
> * shrink-wrap.c (move_insn_for_shrink_wrap): Likewise.
> * ssa-iterators.h (num_imm_uses): Likewise.
> * tree-cfg.c (gimple_merge_blocks): Narrow special casing of
> debug stmts to debug bind stmts.
> * tree-inline.c (tree_function_versioning): Narrow special casing
> of debug stmts to debug bind stmts.
> * tree-loop-distribution.c (generate_loops_for_partition):
> Narrow special casing of debug stmts to debug bind stmts.
> * tree-sra.c (analyze_access_subtree): Narrow special casing
> of debug stmts to debug bind stmts.
> * tree-ssa-dce.c (remove_dead_stmt): Narrow special casing of debug
> stmts to debug bind stmts.
> * tree-ssa-loop-ivopt.c (remove_unused_ivs): Narrow special
> casing of debug stmts to debug bind stmts.
> * tree-ssa-reassoc.c (reassoc_remove_stmt): Likewise.
> * tree-ssa-tail-merge.c (tail_merge_optimize): Narrow special
> casing of debug stmts to debug bind stmts.
> * tree-ssa-threadedge.c (propagate_threaded_block_debug_info):
> Likewise.
> * tree-ssa.c (flush_pending_stmts): Narrow special casing of
> debug stmts to debug bind stmts.
> (gimple_replace_ssa_lhs): Likewise.
> (insert_debug_temp_for_var_def): Likewise.
> (insert_debug_temps_for_defs): Likewise.
> (reset_debug_uses): Likewise.
> * tree-ssanames.c 

Re: X+Y < X iff Y<0 moved to match.pd

2017-10-09 Thread Richard Biener
On Sun, Oct 8, 2017 at 1:22 PM, Marc Glisse  wrote:
> Hello,
>
> this moves (and extends a bit) one more transformation from fold-const.c to
> match.pd. The single_use restriction is necessary for consistency with the
> existing X+CST1 CMP CST2 transformation (if we do only one of the 2
> transformations, gcc.dg/tree-ssa/vrp54.c regresses because DOM fails to
> simplify 2 conditions based on different variables). The relaxation of the
> condition to simplify (T) X == (T) Y is an easier way to avoid regressing
> gcc.dg/tree-ssa/foldaddr-1.c than adding plenty of convert? in the patterns,
> although that may still prove necessary at some point. I left a few odd
> float cases in fold-const.c for later.

+/* X + Y < Y is the same as X < 0 when there is no overflow.  */
+(for op  (lt le ge gt)
+ rop (gt ge le lt)
+ (simplify
+  (op (plus:c@2 @0 @1) @1)
+  (if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0))
+   && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0))
+   && (CONSTANT_CLASS_P (@0) || single_use (@2)))
+   (op @0 { build_zero_cst (TREE_TYPE (@0)); })))
+ (simplify
+  (op @1 (plus:c@2 @0 @1))
+  (if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0))
+   && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0))
+   && (CONSTANT_CLASS_P (@0) || single_use (@2)))
+   (rop @0 { build_zero_cst (TREE_TYPE (@0)); }

any reason (op:c (plus... on the first of the two patterns wouldn't have catched
the second?  :c on comparison swaps the comparison code.

+/* For equality, this is also true with wrapping overflow.  */
+(for op (eq ne)
+ (simplify
+  (op:c (plus:c@2 @0 @1) @1)
+  (if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0))
+   && (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0))
+  || TYPE_OVERFLOW_WRAPS (TREE_TYPE (@0)))
+   && (CONSTANT_CLASS_P (@0) || single_use (@2)))
+   (op @0 { build_zero_cst (TREE_TYPE (@0)); })))
+ (simplify
+  (op:c (convert?@3 (pointer_plus@2 @0 @1)) (convert? @0))
+  (if (CONSTANT_CLASS_P (@1) || (single_use (@2) && single_use (@3)))
+   (op @1 { build_zero_cst (TREE_TYPE (@1)); }

for consistency can you add the convert?s to the integer variant as well?
I'm not sure you'll see the convers like you write them (with matching @0).
Eventually on GENERIC when we still have pointer conversions around?
You are allowing arbitrary conversions here - is that desired?  Isn't
a tree_nop_conversion_p missing?

> We could add a strict overflow warning to the transformations, there are
> already examples in match.pd, but experience shows that it mostly confuses
> users (if we do add it, we should at least restrict it to GENERIC or remove
> it from -Wall). My plan, unless reviewers complain, is to list the 2 xfailed
> testcases in PR80511.

Works for me.

> It is inconvenient that :s is ignored when the output is a single
> instruction, there are now quite a few transformations that call single_use
> manually but would be ok with a :S that is only ignored if the output is a
> constant (or SSA_NAME?). On the other hand, not having a shotcut makes it
> more likely we'll tailor the heuristic to each transformation.

I know -- the situation isn't very satisfying but unless the places we call
into match-and-simplify apply some sort of a cost-model it's going to be
like it is.  Note that each single_use () check possibly pessimizes
value-numbering which uses this for expression simplification.

Richard.

> Bootstrap+testsuite on powerpc64le-unknown-linux-gnu.
>
> 2017-10-09  Marc Glisse  
>
> gcc/
> * fold-const.c (fold_binary_loc) [X +- Y CMP X]: Move ...
> * match.pd: ... here.
> ((T) X == (T) Y): Relax condition.
>
> gcc/testsuite/
> * gcc.dg/Wstrict-overflow-7.c: Xfail.
> * gcc.dg/pragma-diag-3.c: Likewise.
>
> --
> Marc Glisse


Re: tree-complex.c: fix some_nonzerop test over reals (and a bug fix)

2017-10-09 Thread Richard Biener
On Fri, Oct 6, 2017 at 8:58 PM, Laurent Thevenoux
 wrote:
> Hi Richard, thanks for your quick reply.
>
> - Mail original -
>> De: "Richard Biener" 
>> À: "Laurent Thevenoux" 
>> Cc: "GCC Patches" 
>> Envoyé: Vendredi 6 Octobre 2017 13:42:57
>> Objet: Re: tree-complex.c: fix some_nonzerop test over reals (and a bug fix)
>>
>> On Thu, Oct 5, 2017 at 4:41 PM, Laurent Thevenoux
>>  wrote:
>> > Hello,
>> >
>> > This patch improves the some_nonzerop(tree t) function from tree-complex.c
>> > file (the function is only used there).
>> >
>> > This function returns true if a tree as a parameter is not the constant 0
>> > (or +0.0 only for reals when !flag_signed_zeros ). The former result is
>> > then used to determine if some simplifications are possible for complex
>> > expansions (addition, multiplication, and division).
>> >
>> > Unfortunately, if the tree is a real constant, the function always return
>> > true, even for +0.0 because of the explicit test on flag_signed_zeros (so
>> > if your system enables signed zeros you cannot benefit from those
>> > simplifications). To avoid this behavior and allow complex expansion
>> > simplifications, I propose the following patch, which test for the sign of
>> > the real constant 0.0 instead of checking the flag.
>>
>> But
>>
>> +  if (TREE_CODE (t) == REAL_CST)
>> +{
>> +  if (real_identical (_REAL_CST (t), ))
>> +   zerop = !real_isneg (_REAL_CST (t));
>> +}
>>
>> shouldn't you do
>>
>>zerop = !flag_signed_zeros || !real_isneg (_REAL_CST (t));
>>
>> ?
>
> I’m not so sure. If I understand your proposition (tables below gives values 
> of zerop following the values of t and flag_signed_zeros):
>
>|   zerop
>  t | !flag_signed_zeros is false | !flag_signed_zeros is true
> -
> +n | true*   | true*
> -n | false   | true*
>  0 | true| true
> -0 | false   | unreachable
>
> But here, results with a * don't return the good value. The existing code is 
> also wrong, it always returns false if flag_signed_zeros is true, else the 
> code is correct:
>
>|   zerop
>  t | !flag_signed_zeros is false | !flag_signed_zeros is true
> -
> +n | false   | false
> -n | false   | false
>  0 | true| false*
> -0 | false   | unreachable
>
> With the code I propose, we obtain the right results:
>
>  t | zerop
> --
> +n | false
> -n | false
>  0 | true
> -0 | false
>
> Do I really miss something (I'm sorry if I'm wrong)?
>
>>
>> Also doesn't this miscalculate A - B for {ar, 0.} - {br, 0.} given the
>> simplification simply
>> returns bi?
>
> Here we are in case PAIR (ONLY_REAL, ONLY_REAL), which gives ri = 0. (ai) 
> even with signed zeros. So everything is OK.
>
>>
>> So I'm not convinced this handling is correct.
>>
>> > This first fix reveals a bug (thanks to
>> > c-c++-common/torture/complex-sign-add.c ) in the simplification section of
>> > expand_complex_addition (also fixed in the patch).
>>
>> Your patch looks backward and the existing code looks ok.
>>
>> @@ -937,7 +940,7 @@ expand_complex_addition (gimple_stmt_iterator
>> *gsi, tree inner_type,
>>
>>  case PAIR (VARYING, ONLY_REAL):
>>rr = gimplify_build2 (gsi, code, inner_type, ar, br);
>> -  ri = ai;
>> +  ri = bi;
>>break;
>
> With the existing code we don’t perform the simplification step at all since 
> it always returns (VARYING, VARYING) when flag_signed_zeros is true.
>
> For instance, with {ar, -0.} + {br, 0.}, if simplification really occurs, its 
> in case PAIR (VARIYNG, ONLY_REAL) (because we consider -0. as a non_zero), 
> and it returns -0. if we return ai (instead of -0. + 0. -> 0.). But I 
> understand now that returning bi in this case is meaningless since {br, bi} 
> is a ONLY_REAL complex.
>
> Nevertheless, for instance, {ar, -0.} + {br, 0.} -> {ar + br, -0.} is still 
> buggy.
>
> A solution could be:
>
> case PAIR (VARYING, ONLY_REAL):
>   rr = gimplify_build2 (gsi, code, inner_type, ar, br);
> + if (TREE_CODE (ai) == REAL_CST
> +  && code = PLUS_EXPR
> +  && real_identical (_REAL_CST (ai), )
> +  && real_isneg (_REAL_CST (ai)))
> +   ri = bi;
> + else
> ri = ai;
>   break;

I still don't understand what bug you are fixing.

I think you are fixing fallout of your some_nonzero change in a
strange way which shows your change isn't correct.

All the simplifications in expand_complex_addition (and probably
elsewhere) do _not_ properly handle
signed zeros.  So returning true from some_nonzerp for
flag_signed_zeros is dangerous, even 

Re: [PATCH][GCC] Simplification of 1U << (31 - x)

2017-10-09 Thread Richard Biener
On Tue, Sep 26, 2017 at 2:44 PM, Sudi Das  wrote:
>
> Still waiting on Jakub's comment on whether there are more things needed at 
> the backend. But I have updated the patch according to Richard's comments.

+   (if (TYPE_UNSIGNED(type))

space before '(type)'.

+ (rshift (lshift @0 @2) @3)
+   (with
+{ tree utype = unsigned_type_for (type); }
+(convert (rshift (lshift (convert:utype @0) @2) @3))

I think your testcase needs a

{ dg-require-effective-target int32plus }

as otherwise it'll fail on AVR.

I think the patch is ok with these changes but obviously we should try
to address
the code-generation issue on x86 at RTL expansion time.  They are sort-of
existing missing optimizations.

Richard.

> Thanks
> Sudi
>
>
>
> From: Richard Biener 
> Sent: Friday, August 4, 2017 11:16 AM
> To: Sudi Das
> Cc: Wilco Dijkstra; Jakub Jelinek; GCC Patches; nd; Richard Earnshaw; James 
> Greenhalgh
> Subject: Re: [PATCH][GCC] Simplification of 1U << (31 - x)
>
> On Tue, Aug 1, 2017 at 11:14 AM, Sudi Das  wrote:
>>
>>
>>
>>
>> Sorry about the delayed response but looking at the above discussion, should 
>> I conclude that this is a valid tree simplification?
>
> Yes, I think so.  Jakub requested code to undo this at RTL expansion
> based on target costs, not sure if we really should
> require that from you given the user could have written the target
> sequence himself.
>
> Few comments about the patch:
>
> +/* Fold (1 << (C - x)) where C = precision(type) - 1
> +   into ((1 << C) >> x). */
> +(simplify
> + (lshift integer_onep@0 (minus INTEGER_CST@1 @2))
>
> I think this warrants a single_use check on the minus (note :s isn't enough
> as with the unsigned case we'd happily ignore it by design).
>
> +  (if (INTEGRAL_TYPE_P (type)
> +   && TYPE_PRECISION (type) <= HOST_BITS_PER_WIDE_INT
> +   && tree_to_uhwi (@1) == (unsigned)(TYPE_PRECISION (type) - 1))
>
> You can relax this with using
>
>   && wi::eq_p (@1, TYPE_PRECISION (type) - 1)
>
> +   (if (TYPE_UNSIGNED(type))
> + (rshift (lshift @0 @1) @2)
> +   (with
> +{ tree utype = unsigned_type_for (type); }
> +(convert:type (rshift (lshift (convert:utype @0) @1) @2))
> +
>
> You can write (convert (rshift ...)), without the :type.
>
> I'm leaving it to Jakub whether you need to write that RTL expansion tweak.
>
> Thanks,
> Richard.
>
>> I am pasting the diff of the assembly that AArch64 generates with the test 
>> case that I added. I see fewer instructions generated with the patch.
>>
>> --- pr80131-1.s2017-08-01 10:02:43.243374174 +0100
>> +++ pr80131-1.s-patched2017-08-01 10:00:54.776455630 +0100
>> @@ -24,10 +24,8 @@
>>  strx0, [sp, 8]
>>  ldrx0, [sp, 8]
>>  movw1, w0
>> -movw0, 63
>> -subw0, w0, w1
>> -movx1, 1
>> -lslx0, x1, x0
>> +movx0, -9223372036854775808
>> +lsrx0, x0, x1
>>  addsp, sp, 16
>>  ret
>>  .sizef2, .-f2
>> @@ -39,10 +37,8 @@
>>  strx0, [sp, 8]
>>  ldrx0, [sp, 8]
>>  movw1, w0
>> -movw0, 63
>> -subw0, w0, w1
>> -movx1, 1
>> -lslx0, x1, x0
>> +movx0, -9223372036854775808
>> +lsrx0, x0, x1
>>  addsp, sp, 16
>>  ret
>>  .sizef3, .-f3
>> @@ -52,11 +48,9 @@
>>  f4:
>>  subsp, sp, #16
>>  strw0, [sp, 12]
>> -movw1, 31
>>  ldrw0, [sp, 12]
>> -subw0, w1, w0
>> -movw1, 1
>> -lslw0, w1, w0
>> +movw1, -2147483648
>> +lsrw0, w1, w0
>>  addsp, sp, 16
>>  ret
>>  .sizef4, .-f4
>>
>>
>> Thanks
>>
>> Sudi
>>
>>
>>
>>
>> From: Wilco Dijkstra
>> Sent: Thursday, April 13, 2017 1:01 PM
>> To: Richard Biener; Jakub Jelinek
>> Cc: Sudi Das; GCC Patches; nd; Richard Earnshaw; James Greenhalgh
>> Subject: Re: [PATCH][GCC] Simplification of 1U << (31 - x)
>>
>> Richard Biener wrote:
>>> It is IMHO a valid GIMPLE optimization / canonicalization.
>>>
>>>movabsq $-9223372036854775808, %rax
>>>
>>> so this should then have been generated as 1<<63?
>>>
>>> At some point variable shifts were quite expensive as well..
>>
>> Yes I don't see a major difference between movabsq and
>>
>> movl$1, %eax
>> salq$63, %rax
>>
>> on my Sandy Bridge, but if the above is faster then that is what the x64
>> backend should emit - it's 1 byte smaller as well, so probably better in all
>> cases.
>>
>> Wilco
>


[committed] s390 vec_xor fix (PR target/82464)

2017-10-09 Thread Jakub Jelinek
Hi!

I've committed following patch which has been preapproved by Andreas in the
PR.  No testcase right now, it will be covered by testsuite later together
with all the other intrinsics.

2017-10-09  Jakub Jelinek  

PR target/82464
* config/s390/s390-builtins.def (s390_vec_xor_flt_a,
s390_vec_xor_flt_b, s390_vec_xor_flt_c): New.

--- gcc/config/s390/s390-builtins.def.jj2017-10-06 11:25:44.0 
+0200
+++ gcc/config/s390/s390-builtins.def   2017-10-07 13:47:34.851529686 +0200
@@ -1621,6 +1621,9 @@ OB_DEF_VAR (s390_vec_xor_s64_c,
 OB_DEF_VAR (s390_vec_xor_u64_a, s390_vx,B_DEP, 
 0,  BT_OV_UV2DI_BV2DI_UV2DI)
 OB_DEF_VAR (s390_vec_xor_u64_b, s390_vx,0, 
 0,  BT_OV_UV2DI_UV2DI_UV2DI)
 OB_DEF_VAR (s390_vec_xor_u64_c, s390_vx,B_DEP, 
 0,  BT_OV_UV2DI_UV2DI_BV2DI)
+OB_DEF_VAR (s390_vec_xor_flt_a, s390_vx,B_VXE | B_DEP, 
 0,  BT_OV_V4SF_BV4SI_V4SF)
+OB_DEF_VAR (s390_vec_xor_flt_b, s390_vx,B_VXE, 
 0,  BT_OV_V4SF_V4SF_V4SF)
+OB_DEF_VAR (s390_vec_xor_flt_c, s390_vx,B_VXE | B_DEP, 
 0,  BT_OV_V4SF_V4SF_BV4SI)
 OB_DEF_VAR (s390_vec_xor_dbl_a, s390_vx,B_DEP, 
 0,  BT_OV_V2DF_BV2DI_V2DF)
 OB_DEF_VAR (s390_vec_xor_dbl_b, s390_vx,0, 
 0,  BT_OV_V2DF_V2DF_V2DF)
 OB_DEF_VAR (s390_vec_xor_dbl_c, s390_vx,B_DEP, 
 0,  BT_OV_V2DF_V2DF_BV2DI)

Jakub


Re: Add -Wsuggest-attribute=cold

2017-10-09 Thread Tom de Vries

On 07/24/2017 08:56 PM, Jan Hubicka wrote:

* gcc.dg/cold-1.c: New testcase.



Index: testsuite/gcc.dg/cold-1.c
===
--- testsuite/gcc.dg/cold-1.c   (revision 0)
+++ testsuite/gcc.dg/cold-1.c   (working copy)
@@ -0,0 +1,21 @@
+/* { dg-do compile { target nonpic } } */
+/* { dg-options "-O2 -Wsuggest-attribute=cold" } */
+
+extern void do_something_interesting_and_never_return ();
+
+int
+foo1(int a)
+{ /* { dg-warning "cold" "detect cold candidate" { target *-*-* } "8" } */
+  if (a)
+abort ();
+  else
+abort ();
+}
+
+int
+foo2(int a)
+{
+  if (a)
+do_something_interesting_and_never_return ();
+  abort ();
+}



Hi,

this test-case failed for me due to:
- excess errors due to missing abort declaration
- warning emitted on line 7, but is expected on line 8

This patch that:
- fixes the warning line number
- rewrites the absolute warning line number into a relative one
- adds the abort declaration

Committed as obvious.

Thanks,
- Tom
Fix gcc.dg/cold-1.c

2017-10-09  Tom de Vries  

	* gcc.dg/cold-1.c (foo1): Fix warning line number.  Make warning line
	number relative.
	(abort): Declare.

---
 gcc/testsuite/gcc.dg/cold-1.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/cold-1.c b/gcc/testsuite/gcc.dg/cold-1.c
index 8ea88dd..ba1cd3a 100644
--- a/gcc/testsuite/gcc.dg/cold-1.c
+++ b/gcc/testsuite/gcc.dg/cold-1.c
@@ -1,11 +1,12 @@
 /* { dg-do compile { target nonpic } } */
 /* { dg-options "-O2 -Wsuggest-attribute=cold" } */
 
+extern void abort (void);
 extern void do_something_interesting_and_never_return ();
 
 int
 foo1(int a)  
-{ /* { dg-warning "cold" "detect cold candidate" { target *-*-* } "8" } */ 
+{ /* { dg-warning "cold" "detect cold candidate" { target *-*-* } ".-1" } */
   if (a)
 abort ();
   else


Re: [RFA] [PATCH 4/4] Ignore reads of "dead" memory locations in DSE

2017-10-09 Thread Christophe Lyon
On 5 October 2017 at 21:40, Christophe Lyon  wrote:
> Hi Jeff,
>
>
> On 7 September 2017 at 00:18, Jeff Law  wrote:
>> Another old patch getting resurrected...
>>
>>
>
> This patch (r253305) introduces a new FAIL on arm-none-eabi (as
> opposed arm-linux-gnueabi*):
> FAIL: gcc.dg/tree-ssa/ssa-dse-26.c scan-tree-dump-times dse1
> "Deleted dead store" 2
>
> I'm not familiar with all this, but I quickly looked at the testcase,
> and noticed it
> uses enums.
> One ABI difference between arm-non-eabi and arm-linux-gnueabi is that the
> bare-metal target defaults to short-enums, while the linux one uses
> no-short-enums.
>
> Could that be the problem?
>

It looks like it was, since Wilco committed this:
https://gcc.gnu.org/ml/gcc-patches/2017-10/msg00465.html


> Thanks,
>
> Christophe
>
>> On 01/04/2017 06:50 AM, Richard Biener wrote:
>>> On Thu, Dec 22, 2016 at 7:26 AM, Jeff Law  wrote:
 This is the final patch in the kit to improve our DSE implementation.

 It's based on a observation by Richi.  Namely that a read from bytes of
 memory that are dead can be ignored.  By ignoring such reads we can
 sometimes find additional stores that allow us to either eliminate or trim
 an earlier store more aggressively.

 This only hit (by hit I mean the ability to ignore resulted in finding a
 full or partially dead store that we didn't otherwise find) once during a
 bootstrap, but does hit often in the libstdc++ testsuite.  I've added a 
 test
 derived from the conversation between myself and Richi last year.

 There's nothing in the BZ database on this issue and I can't reasonably 
 call
 it a bugfix.  I wouldn't lose sleep if this deferred to gcc-8.

 Bootstrapped and regression tested on x86-64-linux-gnu.  OK for the trunk 
 or
 defer to gcc-8?



 * tree-ssa-dse.c (live_bytes_read): New function.
 (dse_classify_store): Ignore reads of dead bytes.

 * testsuite/gcc.dg/tree-ssa/ssa-dse-26.c: New test.
 * testsuite/gcc.dg/tree-ssa/ssa-dse-26.c: Likewise.



>> [ snip ]
>>
 diff --git a/gcc/tree-ssa-dse.c b/gcc/tree-ssa-dse.c
 index a807d6d..f5b53fc 100644
 --- a/gcc/tree-ssa-dse.c
 +++ b/gcc/tree-ssa-dse.c
 @@ -475,6 +475,41 @@ maybe_trim_partially_dead_store (ao_ref *ref, sbitmap
 live, gimple *stmt)
  }
  }

 +/* Return TRUE if USE_REF reads bytes from LIVE where live is
 +   derived from REF, a write reference.
 +
 +   While this routine may modify USE_REF, it's passed by value, not
 +   location.  So callers do not see those modifications.  */
 +
 +static bool
 +live_bytes_read (ao_ref use_ref, ao_ref *ref, sbitmap live)
 +{
 +  /* We have already verified that USE_REF and REF hit the same object.
 + Now verify that there's actually an overlap between USE_REF and REF.
 */
 +  if ((use_ref.offset < ref->offset
 +   && use_ref.offset + use_ref.size > ref->offset)
 +  || (use_ref.offset >= ref->offset
 + && use_ref.offset < ref->offset + ref->size))
>>>
>>> can you use ranges_overlap_p? (tree-ssa-alias.h)
>> Yes.  Didn't know about it.  Done.
>>
>>>
 +{
 +  normalize_ref (_ref, ref);
 +
 +  /* If USE_REF covers all of REF, then it will hit one or more
 +live bytes.   This avoids useless iteration over the bitmap
 +below.  */
 +  if (use_ref.offset == ref->offset && use_ref.size == ref->size)
 +   return true;
 +
 +  /* Now iterate over what's left in USE_REF and see if any of
 +those bits are i LIVE.  */
 +  for (int i = (use_ref.offset - ref->offset) / BITS_PER_UNIT;
 +  i < (use_ref.offset + use_ref.size) / BITS_PER_UNIT; i++)
 +   if (bitmap_bit_p (live, i))
>>>
>>> a bitmap_bit_in_range_p () would be nice to have.  And it can be more
>>> efficient than this loop...
>> Yea.  That likely would help here.  I'm testing with a
>> bitmap_bit_in_range_p implementation (only for sbitmaps since that's
>> what we're using here).
>>
>> That implementation does the reasonably efficient things and is modeled
>> after the sbitmap implementation of bitmap_set_range.
>>
>>
 @@ -554,6 +589,41 @@ dse_classify_store (ao_ref *ref, gimple *stmt, gimple
 **use_stmt,
   /* If the statement is a use the store is not dead.  */
   else if (ref_maybe_used_by_stmt_p (use_stmt, ref))
 {
 + /* Handle common cases where we can easily build a ao_ref
 +structure for USE_STMT and in doing so we find that the
 +references hit non-live bytes and thus can be ignored.  */
 + if (live_bytes)
 +   {
 + if (is_gimple_assign (use_stmt))
 +

  1   2   >