[PATCH][i386] Split not+broadcast+pand to broadcast+pandn.

2021-05-24 Thread Hongtao Liu via Gcc-patches
Hi:
  This patch is about to do transformation like below.
  Bootstrapped and regtested on x86_64-linux-gnu{-m32,}.
  Ok for trunk?

from
notl%edi
vpbroadcastd%edi, %xmm0
vpand   %xmm1, %xmm0, %xmm0
to
vpbroadcastd%edi, %xmm0
vpandn   %xmm1, %xmm0, %xmm0

gcc/ChangeLog:

PR target/100711
* config/i386/sse.md (*andnot3): New combine splitter
after it.

gcc/testsuite/ChangeLog:

PR target/100711
* gcc.target/i386/avx2-pr100711.c: New test.
* gcc.target/i386/avx512bw-pr100711.c: New test.


-- 
BR,
Hongtao
From 2a70b50fe3ebe129a66d8e4d5c8c025cb6df6e4c Mon Sep 17 00:00:00 2001
From: liuhongt 
Date: Fri, 21 May 2021 11:12:49 +0800
Subject: [PATCH] [i386] Split not+broadcast+pand to broadcast+pandn.

Split
	notl%edi
  	vpbroadcastd%edi, %xmm0
  	vpand   %xmm1, %xmm0, %xmm0
to
  	vpbroadcastd%edi, %xmm0
  	vpandn   %xmm1, %xmm0, %xmm0

gcc/ChangeLog:

	PR target/100711
	* config/i386/sse.md (*andnot3): New combine splitter
	after it.

gcc/testsuite/ChangeLog:

	PR target/100711
	* gcc.target/i386/avx2-pr100711.c: New test.
	* gcc.target/i386/avx512bw-pr100711.c: New test.
---
 gcc/config/i386/sse.md| 20 +
 gcc/testsuite/gcc.target/i386/avx2-pr100711.c | 73 +++
 .../gcc.target/i386/avx512bw-pr100711.c   | 48 
 3 files changed, 141 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/i386/avx2-pr100711.c
 create mode 100644 gcc/testsuite/gcc.target/i386/avx512bw-pr100711.c

diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
index a4503ddcb73..999c7322aac 100644
--- a/gcc/config/i386/sse.md
+++ b/gcc/config/i386/sse.md
@@ -3990,6 +3990,26 @@ (define_insn "*andnot3"
 	  ]
 	  (const_string "")))])
 
+;; Split
+;;	notl%edi
+;;  vpbroadcastd%edi, %xmm0
+;;  vpand   %xmm1, %xmm0, %xmm0
+;;to
+;;  vpbroadcastd%edi, %xmm0
+;;  vpandn   %xmm1, %xmm0, %xmm0
+
+(define_split
+  [(set (match_operand:VI 0 "register_operand")
+	(and:VI
+	  (vec_duplicate:VI
+	(not:
+	  (match_operand: 1 "register_operand")))
+	  (match_operand:VI 2 "bcst_vector_operand")))]
+  "TARGET_AVX2"
+  [(set (match_dup 3) (vec_duplicate:VI (match_dup 1)))
+   (set (match_dup 0) (and:VI (not:VI (match_dup 3)) (match_dup 2)))]
+  "operands[3] = gen_reg_rtx (mode);")
+
 (define_insn "*andnottf3"
   [(set (match_operand:TF 0 "register_operand" "=x,x,v,v")
 	(and:TF
diff --git a/gcc/testsuite/gcc.target/i386/avx2-pr100711.c b/gcc/testsuite/gcc.target/i386/avx2-pr100711.c
new file mode 100644
index 000..5b144623873
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/avx2-pr100711.c
@@ -0,0 +1,73 @@
+/* { dg-do compile } */
+/* { dg-options "-mavx512bw -O2" } */
+/* { dg-final { scan-assembler-times "pandn" 8 } } */
+/* { dg-final { scan-assembler-not "not\[bwlq\]" } } */
+typedef char v16qi __attribute__((vector_size(16)));
+typedef char v32qi __attribute__((vector_size(32)));
+typedef short v8hi __attribute__((vector_size(16)));
+typedef short v16hi __attribute__((vector_size(32)));
+typedef int v4si __attribute__((vector_size(16)));
+typedef int v8si __attribute__((vector_size(32)));
+typedef long long v2di __attribute__((vector_size(16)));
+typedef long long v4di __attribute__((vector_size(32)));
+
+v16qi
+f1 (char a, v16qi c)
+{
+  char b = ~a;
+  return (__extension__(v16qi) {b, b, b, b, b, b, b, b,
+ b, b, b, b, b, b, b, b}) & c;
+}
+
+v32qi
+f2 (char a, v32qi c)
+{
+  char b = ~a;
+  return (__extension__(v32qi) {b, b, b, b, b, b, b, b,
+ b, b, b, b, b, b, b, b,
+ b, b, b, b, b, b, b, b,
+ b, b, b, b, b, b, b, b}) & c;
+}
+
+v8hi
+f3 (short a, v8hi c)
+{
+  short b = ~a;
+  return (__extension__(v8hi) {b, b, b, b, b, b, b, b}) & c;
+}
+
+v16hi
+f4 (short a, v16hi c)
+{
+  short b = ~a;
+  return (__extension__(v16hi) {b, b, b, b, b, b, b, b,
+ b, b, b, b, b, b, b, b}) & c;
+}
+
+v4si
+f5 (int a, v4si c)
+{
+  int b = ~a;
+  return (__extension__(v4si) {b, b, b, b}) & c;
+}
+
+v8si
+f6 (int a, v8si c)
+{
+  int b = ~a;
+  return (__extension__(v8si) {b, b, b, b, b, b, b, b}) & c;
+}
+
+v2di
+f7 (long long a, v2di c)
+{
+  long long b = ~a;
+  return (__extension__(v2di) {b, b}) & c;
+}
+
+v4di
+f8 (long long a, v4di c)
+{
+  long long b = ~a;
+  return (__extension__(v4di) {b, b, b, b}) & c;
+}
diff --git a/gcc/testsuite/gcc.target/i386/avx512bw-pr100711.c b/gcc/testsuite/gcc.target/i386/avx512bw-pr100711.c
new file mode 100644
index 000..f0a103d0bc2
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/avx512bw-pr100711.c
@@ -0,0 +1,48 @@
+/* { dg-do compile } */
+/* { dg-options "-mavx512bw -O2" } */
+/* { dg-final { scan-assembler-times "pandn" 4 } } */
+/* { dg-final { scan-assembler-not "not\[bwlq\]" } } */
+
+typedef char v64qi __attribute__((vector_size(64)));
+typedef short v32hi __attribute__((vector_size(64)));
+typedef int v16si __attribute__((vector_size(64)));

Re: [r12-989 Regression] FAIL: libgomp.oacc-fortran/privatized-ref-2.f90 -DACC_DEVICE_TYPE_host=1 -DACC_MEM_SHARED=1 -foffload=disable -Os (test for warnings, line 98) on Linux/x86_64

2021-05-24 Thread Sunil Pandey via Gcc-patches
Hi Thomas,

I reproduced this issue manually and it turns out this is a special case.

Script takes input from https://gcc.gnu.org/pipermail/gcc-regression/ and
it matches the exact error message in the triaging process. This failure
reported on gcc regression
https://gcc.gnu.org/pipermail/gcc-regression/2021-May/074806.html

Reason it triaged 325aa13996bafce0c4927876c315d1fa706d9881 and not
11b8286a83289f5b54e813f14ff56d730c3f3185 because,

Commit 325aa13996bafce0c4927876c315d1fa706d9881 is the first commit which
matches the failure message reported on gcc-regression. See the difference
in line number.

Error message produced from commit 325aa13996bafce0c4927876c315d1fa706d9881:
FAIL: libgomp.oacc-fortran/privatized-ref-2.f90 -DACC_DEVICE_TYPE_host=1
-DACC_MEM_SHARED=1 -foffload=disable  -Os   (test for warnings, line 98)
FAIL: libgomp.oacc-fortran/privatized-ref-2.f90 -DACC_DEVICE_TYPE_host=1
-DACC_MEM_SHARED=1 -foffload=disable  -Os   (test for warnings, line 134)

vs.

Error message produced from commit 11b8286a83289f5b54e813f14ff56d730c3f3185:
FAIL: libgomp.oacc-fortran/privatized-ref-2.f90 -DACC_DEVICE_TYPE_host=1
-DACC_MEM_SHARED=1 -foffload=disable  -Os   (test for warnings, line 100)
FAIL: libgomp.oacc-fortran/privatized-ref-2.f90 -DACC_DEVICE_TYPE_host=1
-DACC_MEM_SHARED=1 -foffload=disable  -Os   (test for warnings, line 136)

Thank you so much,
Sunil Pandey


On Sat, May 22, 2021 at 1:41 AM Thomas Schwinge 
wrote:

> Hi!
>
> First: many thanks for running this automated regression testing
> machinery!
>
> On 2021-05-21T18:40:55-0700, "sunil.k.pandey via Gcc-patches" <
> gcc-patches@gcc.gnu.org> wrote:
> > On Linux/x86_64,
> >
> > 325aa13996bafce0c4927876c315d1fa706d9881 is the first bad commit
> > commit 325aa13996bafce0c4927876c315d1fa706d9881
> > Author: Thomas Schwinge 
> > Date:   Fri May 21 08:51:47 2021 +0200
> >
> > [OpenACC privatization] Reject 'static', 'external' in blocks
> [PR90115]
>
> Actually not that one, but instead one commit before is the culprit:
>
> commit 11b8286a83289f5b54e813f14ff56d730c3f3185
> Author: Thomas Schwinge 
> Date:   Thu May 20 16:11:37 2021 +0200
>
> [OpenACC privatization] Largely extend diagnostics and
> corresponding testsuite coverage [PR90115]
>
> (Probably your testing aggregates commits that appear in some period of
> time?  Maybe reflect that in the reporting emails?)
>
> > caused
> >
> > FAIL: libgomp.oacc-fortran/privatized-ref-2.f90 -DACC_DEVICE_TYPE_host=1
> -DACC_MEM_SHARED=1 -foffload=disable  -O0   (test for warnings, line 134)
> > FAIL: libgomp.oacc-fortran/privatized-ref-2.f90 -DACC_DEVICE_TYPE_host=1
> -DACC_MEM_SHARED=1 -foffload=disable  -O0   (test for warnings, line 98)
> > FAIL: libgomp.oacc-fortran/privatized-ref-2.f90 -DACC_DEVICE_TYPE_host=1
> -DACC_MEM_SHARED=1 -foffload=disable  -O1   (test for warnings, line 134)
> > FAIL: libgomp.oacc-fortran/privatized-ref-2.f90 -DACC_DEVICE_TYPE_host=1
> -DACC_MEM_SHARED=1 -foffload=disable  -O1   (test for warnings, line 98)
> > FAIL: libgomp.oacc-fortran/privatized-ref-2.f90 -DACC_DEVICE_TYPE_host=1
> -DACC_MEM_SHARED=1 -foffload=disable  -O2   (test for warnings, line 134)
> > FAIL: libgomp.oacc-fortran/privatized-ref-2.f90 -DACC_DEVICE_TYPE_host=1
> -DACC_MEM_SHARED=1 -foffload=disable  -O2   (test for warnings, line 98)
> > FAIL: libgomp.oacc-fortran/privatized-ref-2.f90 -DACC_DEVICE_TYPE_host=1
> -DACC_MEM_SHARED=1 -foffload=disable  -O3 -fomit-frame-pointer
> -funroll-loops -fpeel-loops -ftracer -finline-functions   (test for
> warnings, line 134)
> > FAIL: libgomp.oacc-fortran/privatized-ref-2.f90 -DACC_DEVICE_TYPE_host=1
> -DACC_MEM_SHARED=1 -foffload=disable  -O3 -fomit-frame-pointer
> -funroll-loops -fpeel-loops -ftracer -finline-functions   (test for
> warnings, line 98)
> > FAIL: libgomp.oacc-fortran/privatized-ref-2.f90 -DACC_DEVICE_TYPE_host=1
> -DACC_MEM_SHARED=1 -foffload=disable  -O3 -g   (test for warnings, line 134)
> > FAIL: libgomp.oacc-fortran/privatized-ref-2.f90 -DACC_DEVICE_TYPE_host=1
> -DACC_MEM_SHARED=1 -foffload=disable  -O3 -g   (test for warnings, line 98)
> > FAIL: libgomp.oacc-fortran/privatized-ref-2.f90 -DACC_DEVICE_TYPE_host=1
> -DACC_MEM_SHARED=1 -foffload=disable  -Os   (test for warnings, line 134)
> > FAIL: libgomp.oacc-fortran/privatized-ref-2.f90 -DACC_DEVICE_TYPE_host=1
> -DACC_MEM_SHARED=1 -foffload=disable  -Os   (test for warnings, line 98)
>
> Sorry, and ACK, and I'm confused why I didn't see that in my own testing.
> I've now pushed "[OpenACC privatization] Prune uninteresting/varying
> diagnostics in 'libgomp.oacc-fortran/privatized-ref-2.f90'" to master
> branch in commit 3050a1a18276d7cdd8946e34cc1344e30efb7030, see attached.
>
>
> Grüße
>  Thomas
>
>
> -
> Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München
> Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank
> Thürauf
>


Re: [PATCH 11/11] use xxx_no_warning APIs in the middle end

2021-05-24 Thread Martin Sebor via Gcc-patches

On 5/24/21 5:08 PM, David Malcolm via Gcc-patches wrote:

On Mon, 2021-05-24 at 16:16 -0600, Martin Sebor via Gcc-patches wrote:

The attached patch replaces TREE_NO_WARNING, gimple_get_no_warning_p
and gimple_set_no_warning with the new APIs, get_no_warning,
set_no_warning, and copy_no_warning.


Might be worth splitting this out into
(a) the middle-end changes versus
(b) the final changes that remove the old mechanisms.


Sure, I can do that.



Is this missing a change to remove "nowarning_flag" from the pertinent
tree struct?


No, the bit is still used and needed when a tree or GIMPLE statement
has no location.

Martin



Dave





Re: [PATCH 0/11] warning control by group and location (PR 74765)

2021-05-24 Thread Martin Sebor via Gcc-patches

On 5/24/21 5:08 PM, David Malcolm wrote:

On Mon, 2021-05-24 at 16:02 -0600, Martin Sebor wrote:

Having just one bit control whether an expression or statement should
be allowed to trigger warnings has been a source of bug reports about
false negatives for years.  PR 74765 has a representative test case
that shows how by setting the bit to avoid -Wparentheses the C++ front
end also ends up preventing valid -Wuninitialized in the middle end,


Thanks for the quick reply!



For reference, PR 74765 has:

int foo(int x, int y)
{
 int i;
 if ((i ==0)) return x;
 return y;
}

int foo2(int x, int y)
{
 int i;
 if (i ==0) return x;
 return y;
}

where both fns have an uninitialized use of "i", but the double-parens
in "foo" have already been warned about, so TREE_NO_WARNING is set,
hence we don't get an uninit warning, right?


Yes, close.  The double parens are used to suppress warning about
assignment in the if condition (-Wparentheses).  The suppression is
applied to the equality expression which then turns into a GIMPLE_COND
statement with the no-warning set. -Wuninitialized then avoids
triggering because it sees the no-warning bit set on the GIMPLE_COND.




but there are other such reports for C (e.g., PR 74762) as well as
the middle end.




This patch series solves the problem by associating an expression
(whether a tree node or a GIMPLE statement) with more than one such
bit through its location.  Each new bit in the mapping corresponds
to a group of warnings (e.g., lexical, access, etc.), and each
location may be associated with a simple bitmap with one bit for
each group.  The initial groups are mostly ad hoc and should be
refined over time.


The overall idea looks promising, thanks.

I didn't see any test cases in the patch kit; do you have some that
demonstrate the fixes for the above PRs?


Yes.  I have a test case for PR 74765 in my tree and but I missed
including it in the patch series.  I have also started going through
Bugzilla looking for other similar reports.  I'll include those I
find in the revised patch.



I'm slightly nervous that, although we're gaining granularity in terms
of the different categories of warning, do we risk losing granularity
due to expressions sharing locations?


If it's possible for two expressions or statements, say A and B, to
have the same location (is it?) then suppressing warning X for A and
a different warning Y for B would also suppress X for B.  (Note that
both A and B would have to have the existing no-warning bit set for
this to happen).  I haven't seen this happen and I can't off hand
think of how to get into a situation like that.




   The rare expressions that have no location
continue to have just one bit[1].


Where does this get stored?  I see the final patch in the kit removes
TREE_NO_WARNING, but I don't quite follow the logic for where the bit
would then be stored for an expr with UNKNOWN_LOCATION.


The patch just removes the TREE_NO_WARNING macro (along with
the gimple_no_warning_p/gimple_set_no_warning) functions but not
the no-warning bit itself.  It removes them to avoid accidentally
modifying the bit alone without going through the new API and
updating the location -> warning group mapping.  The bit is still
needed for expression/statements with no location.





The first patch introduces three new APIs without making use of them
in existing code:

    bool get_no_warning (..., int option);
    void set_no_warning (..., int option, ...);
    void copy_no_warning (...);


Is it possible to use "enum opt_code" (from the generated options.h)
rather than a plain "int" for these?  Or is this not available
everywhere we use these?


I was tempted to do it but I resisted because the existing warning
APIs take an int as an argument.  It doesn't look like there's
a problem with #including "options.h" in the diagnostic subsystem
so I'm down with changing the argument to opt_code.


Subsequent patches then replace invocations of the TREE_NO_WARNING()
macro and the gimple_no_warning_p() and gimple_set_no_warning()
functions throughout GCC with those and remove the legacy APIs to
keep them from being accidentally reintroduced along with the
problem.
These are mostly mechanical changes, except that most of the new
invocations also specify the option whose disposition to query for
the expression or location, or which to enable or disable[2].
The last function, copy_no_warning(), copies the disposition from
one expression or location to another.

A couple of design choices might be helpful to explain:

First, introducing "warning groups" rather than controlling each
individual warning is motivated by a) the fact that the latter
would make avoiding redundant warnings for related problems
cumbersome (e.g., after issuing a -Warray-bounds we want to
suppress -Wstringop-overflow as well -Wstringop-overread for
the same access and vice versa), and b) simplicity and efficiency
of the implementation (mapping each option would require a 

Re: [PATCH 11/11] use xxx_no_warning APIs in the middle end

2021-05-24 Thread David Malcolm via Gcc-patches
On Mon, 2021-05-24 at 16:16 -0600, Martin Sebor via Gcc-patches wrote:
> The attached patch replaces TREE_NO_WARNING, gimple_get_no_warning_p
> and gimple_set_no_warning with the new APIs, get_no_warning,
> set_no_warning, and copy_no_warning.

Might be worth splitting this out into
(a) the middle-end changes versus
(b) the final changes that remove the old mechanisms.

Is this missing a change to remove "nowarning_flag" from the pertinent
tree struct?

Dave



Re: [PATCH 0/11] warning control by group and location (PR 74765)

2021-05-24 Thread David Malcolm via Gcc-patches
On Mon, 2021-05-24 at 16:02 -0600, Martin Sebor wrote:
> Having just one bit control whether an expression or statement should
> be allowed to trigger warnings has been a source of bug reports about
> false negatives for years.  PR 74765 has a representative test case
> that shows how by setting the bit to avoid -Wparentheses the C++ front
> end also ends up preventing valid -Wuninitialized in the middle end,

For reference, PR 74765 has:

int foo(int x, int y)
{
int i;
if ((i ==0)) return x;
return y;
}

int foo2(int x, int y)
{
int i;
if (i ==0) return x;
return y;
}

where both fns have an uninitialized use of "i", but the double-parens
in "foo" have already been warned about, so TREE_NO_WARNING is set,
hence we don't get an uninit warning, right?

> but there are other such reports for C (e.g., PR 74762) as well as
> the middle end.


> This patch series solves the problem by associating an expression
> (whether a tree node or a GIMPLE statement) with more than one such
> bit through its location.  Each new bit in the mapping corresponds
> to a group of warnings (e.g., lexical, access, etc.), and each
> location may be associated with a simple bitmap with one bit for
> each group.  The initial groups are mostly ad hoc and should be
> refined over time.

The overall idea looks promising, thanks.

I didn't see any test cases in the patch kit; do you have some that
demonstrate the fixes for the above PRs?

I'm slightly nervous that, although we're gaining granularity in terms
of the different categories of warning, do we risk losing granularity
due to expressions sharing locations?

>   The rare expressions that have no location
> continue to have just one bit[1].

Where does this get stored?  I see the final patch in the kit removes
TREE_NO_WARNING, but I don't quite follow the logic for where the bit
would then be stored for an expr with UNKNOWN_LOCATION.

> 
> The first patch introduces three new APIs without making use of them
> in existing code:
> 
>    bool get_no_warning (..., int option);
>    void set_no_warning (..., int option, ...);
>    void copy_no_warning (...);

Is it possible to use "enum opt_code" (from the generated options.h)
rather than a plain "int" for these?  Or is this not available
everywhere we use these?

> 
> Subsequent patches then replace invocations of the TREE_NO_WARNING()
> macro and the gimple_no_warning_p() and gimple_set_no_warning()
> functions throughout GCC with those and remove the legacy APIs to
> keep them from being accidentally reintroduced along with the
> problem.
> These are mostly mechanical changes, except that most of the new
> invocations also specify the option whose disposition to query for
> the expression or location, or which to enable or disable[2].
> The last function, copy_no_warning(), copies the disposition from
> one expression or location to another.
> 
> A couple of design choices might be helpful to explain:
> 
> First, introducing "warning groups" rather than controlling each
> individual warning is motivated by a) the fact that the latter
> would make avoiding redundant warnings for related problems
> cumbersome (e.g., after issuing a -Warray-bounds we want to
> suppress -Wstringop-overflow as well -Wstringop-overread for
> the same access and vice versa), and b) simplicity and efficiency
> of the implementation (mapping each option would require a more
> complex data structure like a bitmap).
> 
> Second, using location_t to associate expressions/statements with
> the warning groups also turns out to be more useful in practice
> than a direct association between a tree or gimple*, and also
> simplifies managing the data structure.  Trees and gimple* come
> and go across passes, and maintaining a mapping for them that
> accounts for the possibility of them being garbage-collected
> and the same addresses reused is less than straightforward.

I find some of the terminology rather awkard due to it the negation
we're already using with TREE_NO_WARNING, in that we're turning on a
no_warning flag, and that this is a per-location/expr/stmt thing that's
different from the idea of enabling/disabling a specific warning
altogether (and the pragmas that control that).   Sometimes the patches
refer to enabling/disabling warnings and I think I want "enabling" and
"disabling" to mean the thing the user does with -Wfoo and -Wno-foo.

Would calling it a "warning suppression" or somesuch be more or less
klunky?

> 
> Martin
> 
> [1] My expectation is to work toward providing locations for all
> expressions/statements, even if it's the opening or closing brace
> of the function they're used in.)
> 
> [2] A number of {get,set}_no_warning() calls introduced by the patch
> don't provide an option argument and query or set just the one bit in
> the expression/statement.  Some of these may be correct as they are,
> but others could be refined to also specify an option.  I can do that
> in a follow-up patch if someone helps me find the 

[PATCH 11/11] use xxx_no_warning APIs in the middle end

2021-05-24 Thread Martin Sebor via Gcc-patches

The attached patch replaces TREE_NO_WARNING, gimple_get_no_warning_p
and gimple_set_no_warning with the new APIs, get_no_warning,
set_no_warning, and copy_no_warning.
Add support for per-location warning groups.

gcc/ChangeLog:

	* builtins.c (warn_string_no_nul): Replace uses of TREE_NO_WARNING,
	gimple_no_warning_p and gimple_set_no_warning with get_no_warning,
	and set_no_warning.
	(c_strlen): Same.
	(maybe_warn_for_bound): Same.
	(warn_for_access): Same.
	(check_access): Same.
	(expand_builtin_strncmp): Same.
	(fold_builtin_varargs): Same.
	* calls.c (maybe_warn_nonstring_arg): Same.
	(maybe_warn_rdwr_sizes): Same.
	* cfgexpand.c (expand_call_stmt): Same.
	* cgraphunit.c (check_global_declaration): Same.
	* fold-const.c (fold_undefer_overflow_warnings): Same.
	(fold_truth_not_expr): Same.
	(fold_unary_loc): Same.
	(fold_checksum_tree): Same.
	* gengtype.c (open_base_files): Same.
	* gimple-array-bounds.cc (array_bounds_checker::check_array_ref): Same.
	(array_bounds_checker::check_mem_ref): Same.
	(array_bounds_checker::check_addr_expr): Same.
	(array_bounds_checker::check_array_bounds): Same.
	* gimple-expr.c (copy_var_decl): Same.
	* gimple-fold.c (gimple_fold_builtin_strcpy): Same.
	(gimple_fold_builtin_strncat): Same.
	(gimple_fold_builtin_stxcpy_chk): Same.
	(gimple_fold_builtin_stpcpy): Same.
	(gimple_fold_builtin_sprintf): Same.
	(fold_stmt_1): Same.
	* gimple-ssa-isolate-paths.c (diag_returned_locals): Same.
	* gimple-ssa-nonnull-compare.c (do_warn_nonnull_compare): Same.
	* gimple-ssa-sprintf.c (handle_printf_call): Same.
	* gimple-ssa-store-merging.c (imm_store_chain_info::output_merged_store): Same.
	* gimple-ssa-warn-restrict.c (maybe_diag_overlap): Same.
	(maybe_diag_access_bounds): Same.
	(check_call): Same.
	(check_bounds_or_overlap): Same.
	* gimple.c (gimple_build_call_from_tree): Same.
	* gimplify.c (gimplify_return_expr): Same.
	(gimplify_cond_expr): Same.
	(gimplify_modify_expr_complex_part): Same.
	(gimplify_modify_expr): Same.
	(gimple_push_cleanup): Same.
	(gimplify_expr): Same.
	* omp-expand.c (expand_omp_for_generic): Same.
	(expand_omp_taskloop_for_outer): Same.
	* omp-low.c (lower_rec_input_clauses): Same.
	(lower_lastprivate_clauses): Same.
	(lower_send_clauses): Same.
	(lower_omp_target): Same.
	* tree-cfg.c (pass_warn_function_return::execute): Same.
	* tree-complex.c (create_one_component_var): Same.
	* tree-inline.c (remap_gimple_op_r): Same.
	(copy_tree_body_r): Same.
	(declare_return_variable): Same.
	(expand_call_inline): Same.
	* tree-nested.c (lookup_field_for_decl): Same.
	* tree-sra.c (create_access_replacement): Same.
	(generate_subtree_copies): Same.
	* tree-ssa-ccp.c (pass_post_ipa_warn::execute): Same.
	* tree-ssa-forwprop.c (combine_cond_expr_cond): Same.
	* tree-ssa-loop-ch.c (ch_base::copy_headers): Same.
	* tree-ssa-loop-im.c (execute_sm): Same.
	* tree-ssa-phiopt.c (cond_store_replacement): Same.
	* tree-ssa-strlen.c (maybe_warn_overflow): Same.
	(handle_builtin_strcpy): Same.
	(maybe_diag_stxncpy_trunc): Same.
	(handle_builtin_stxncpy_strncat): Same.
	(handle_builtin_strcat): Same.
	* tree-ssa-uninit.c (get_no_uninit_warning): Same.
	(set_no_uninit_warning): Same.
	(uninit_undefined_value_p): Same.
	(warn_uninit): Same.
	(maybe_warn_operand): Same.
	* tree-vrp.c (compare_values_warnv): Same.
	* vr-values.c (vr_values::extract_range_for_var_from_comparison_expr): Same.
	(test_for_singularity): Same.

	* gimple.h (get_no_warning): New.
	(set_no_warning): Same.
	(copy_no_warning): Same.
	(gimple_set_block): Call gimple_set_location.
	(gimple_set_location): Call copy_warning.
	(gimple_no_warning_p): Remove.
	(gimple_set_no_warning): Same.
	* tree.h (TREE_NO_WARNING): Remove.
	(get_no_warning): New.
	(set_no_warning): Same.
	(copy_no_warning): Same.

diff --git a/gcc/builtins.c b/gcc/builtins.c
index b0c880dc3b5..105deadd42b 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -1094,7 +1094,9 @@ warn_string_no_nul (location_t loc, tree expr, const char *fname,
 		bool exact /* = false */,
 		const wide_int bndrng[2] /* = NULL */)
 {
-  if ((expr && TREE_NO_WARNING (expr)) || TREE_NO_WARNING (arg))
+  const int opt = OPT_Wstringop_overread;
+  if ((expr && get_no_warning (expr, opt))
+  || get_no_warning (arg, opt))
 return;
 
   loc = expansion_point_location_if_in_system_header (loc);
@@ -1122,14 +1124,14 @@ warn_string_no_nul (location_t loc, tree expr, const char *fname,
   if (bndrng)
 	{
 	  if (wi::ltu_p (maxsiz, bndrng[0]))
-	warned = warning_at (loc, OPT_Wstringop_overread,
+	warned = warning_at (loc, opt,
  "%K%qD specified bound %s exceeds "
  "maximum object size %E",
  expr, func, bndstr, maxobjsize);
 	  else
 	{
 	  bool maybe = wi::to_wide (size) == bndrng[0];
-	  warned = warning_at (loc, OPT_Wstringop_overread,
+	  warned = warning_at (loc, opt,
    exact
    ? G_("%K%qD specified bound %s exceeds "
 	"the size %E of unterminated array")
@@ -1144,7 +1146,7 @@ 

[PATCH 10/11] use xxx_no_warning APIs in libcc1

2021-05-24 Thread Martin Sebor via Gcc-patches

The attached patch replaces the uses of TREE_NO_WARNING in libc11.
Add support for per-location warning groups.

libcc1/ChangeLog:

	* libcp1plugin.cc (record_decl_address): Replace a direct use
	of TREE_NO_WARNING with set_no_warning.

diff --git a/libcc1/libcp1plugin.cc b/libcc1/libcp1plugin.cc
index 79694b91964..469a75c7ff7 100644
--- a/libcc1/libcp1plugin.cc
+++ b/libcc1/libcp1plugin.cc
@@ -541,7 +541,7 @@ record_decl_address (plugin_context *ctx, decl_addr_value value)
   **slot = value;
   /* We don't want GCC to warn about e.g. static functions
  without a code definition.  */
-  TREE_NO_WARNING (value.decl) = 1;
+  set_no_warning (value.decl);
   return *slot;
 }
 


[PATCH 9/11] use xxx_no_warning APIs in rl78 back end

2021-05-24 Thread Martin Sebor via Gcc-patches

The attached patch replaces the uses of TREE_NO_WARNING in the rl78
back end.
Add support for per-location warning groups.

gcc/ChangeLog:

	* config/rl78/rl78.c (rl78_handle_naked_attribute): Replace a direct
	use of TREE_NO_WARNING with set_no_warning.

diff --git a/gcc/config/rl78/rl78.c b/gcc/config/rl78/rl78.c
index 4c34949a97f..1055d423c83 100644
--- a/gcc/config/rl78/rl78.c
+++ b/gcc/config/rl78/rl78.c
@@ -847,7 +847,7 @@ rl78_handle_naked_attribute (tree * node,
   /* Disable warnings about this function - eg reaching the end without
  seeing a return statement - because the programmer is doing things
  that gcc does not know about.  */
-  TREE_NO_WARNING (* node) = 1;
+  set_no_warning (* node);
 
   return NULL_TREE;
 }


[PATCH 8/11] use xxx_no_warning APIs in Objective-C

2021-05-24 Thread Martin Sebor via Gcc-patches

The attached patch replaces the uses of TREE_NO_WARNING in
the Objective-C front end.
Add support for per-location warning groups.

gcc/objc/ChangeLog:

	* objc-act.c (objc_maybe_build_modify_expr): Replace direct uses
	of TREE_NO_WARNING with get_no_warning, and set_no_warning.
	(objc_build_incr_expr_for_property_ref): Same.
	(objc_build_struct): Same.
	(synth_module_prologue): Same.
	* objc-gnu-runtime-abi-01.c (gnu_runtime_01_initialize): Same.
	* objc-next-runtime-abi-01.c (next_runtime_01_initialize): Same.
	* objc-next-runtime-abi-02.c (next_runtime_02_initialize): Same.

diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c
index 796256d437e..a4154709b00 100644
--- a/gcc/objc/objc-act.c
+++ b/gcc/objc/objc-act.c
@@ -2007,7 +2007,7 @@ objc_maybe_build_modify_expr (tree lhs, tree rhs)
 	 correct (maybe a more sophisticated implementation could
 	 avoid generating the compound expression if not needed), but
 	 we need to turn it off.  */
-  TREE_NO_WARNING (compound_expr) = 1;
+  set_no_warning (compound_expr, OPT_Wunused);
   return compound_expr;
 }
   else
@@ -2129,7 +2129,7 @@ objc_build_incr_expr_for_property_ref (location_t location,
 
   /* Prevent C++ from warning with -Wall that "right operand of comma
  operator has no effect".  */
-  TREE_NO_WARNING (compound_expr) = 1;
+  set_no_warning (compound_expr, OPT_Wunused);
   return compound_expr;
 }
 
@@ -2262,8 +2262,9 @@ objc_build_struct (tree klass, tree fields, tree super_name)
   DECL_FIELD_IS_BASE (base) = 1;
 
   if (fields)
-	TREE_NO_WARNING (fields) = 1;	/* Suppress C++ ABI warnings -- we   */
-#endif	/* are following the ObjC ABI here.  */
+	/* Suppress C++ ABI warnings: we are following the ObjC ABI here.  */
+	set_no_warning (fields, OPT_Wabi);
+#endif
   DECL_CHAIN (base) = fields;
   fields = base;
 }
@@ -3112,19 +3113,19 @@ synth_module_prologue (void)
 		TYPE_DECL,
 		objc_object_name,
 		objc_object_type));
-  TREE_NO_WARNING (type) = 1;
+  set_no_warning (type);
 
   type = lang_hooks.decls.pushdecl (build_decl (input_location,
 		TYPE_DECL,
 		objc_instancetype_name,
 		objc_instancetype_type));
-  TREE_NO_WARNING (type) = 1;
+  set_no_warning (type);
 
   type = lang_hooks.decls.pushdecl (build_decl (input_location,
 		TYPE_DECL,
 		objc_class_name,
 		objc_class_type));
-  TREE_NO_WARNING (type) = 1;
+  set_no_warning (type);
 
   /* Forward-declare '@interface Protocol'.  */
   type = get_identifier (PROTOCOL_OBJECT_CLASS_NAME);
diff --git a/gcc/objc/objc-gnu-runtime-abi-01.c b/gcc/objc/objc-gnu-runtime-abi-01.c
index 4add71edf41..9a63bbf45fd 100644
--- a/gcc/objc/objc-gnu-runtime-abi-01.c
+++ b/gcc/objc/objc-gnu-runtime-abi-01.c
@@ -213,7 +213,7 @@ static void gnu_runtime_01_initialize (void)
 		TYPE_DECL,
 		objc_selector_name,
 		objc_selector_type));
-  TREE_NO_WARNING (type) = 1;
+  set_no_warning (type);
 
   /* typedef id (*IMP)(id, SEL, ...); */
   ftype = build_varargs_function_type_list (objc_object_type,
diff --git a/gcc/objc/objc-next-runtime-abi-01.c b/gcc/objc/objc-next-runtime-abi-01.c
index 3ec6e1703c1..b58e4829674 100644
--- a/gcc/objc/objc-next-runtime-abi-01.c
+++ b/gcc/objc/objc-next-runtime-abi-01.c
@@ -282,7 +282,7 @@ static void next_runtime_01_initialize (void)
 		TYPE_DECL,
 		objc_selector_name,
 		objc_selector_type));
-  TREE_NO_WARNING (type) = 1;
+  set_no_warning (type);
 
   build_v1_class_template ();
   build_super_template ();
diff --git a/gcc/objc/objc-next-runtime-abi-02.c b/gcc/objc/objc-next-runtime-abi-02.c
index 3cfcd0b1a57..22266c6e612 100644
--- a/gcc/objc/objc-next-runtime-abi-02.c
+++ b/gcc/objc/objc-next-runtime-abi-02.c
@@ -379,7 +379,7 @@ static void next_runtime_02_initialize (void)
 		TYPE_DECL,
 		objc_selector_name,
 		objc_selector_type));
-  TREE_NO_WARNING (type) = 1;
+  set_no_warning (type);
 
   /* IMP : id (*) (id, _message_ref_t*, ...)
  SUPER_IMP : id (*) ( super_t*, _super_message_ref_t*, ...)


[PATCH 7/11] use xxx_no_warning APIs in Fortran

2021-05-24 Thread Martin Sebor via Gcc-patches

The attached patch replaces the uses of TREE_NO_WARNING in the LTO
front end.  The streaming support doesn't extend to multiple bits yet.
I plan to do that in a follow-up change.
Add support for per-location warning groups.

gcc/lto/ChangeLog:

	* gimple-streamer-out.c (output_gimple_stmt): Same.
	* lto-common.c (compare_tree_sccs_1): Expand use of TREE_NO_WARNING.
	* lto-streamer-out.c (hash_tree): Same.
	* tree-streamer-in.c (unpack_ts_base_value_fields): Same.
	* tree-streamer-out.c (pack_ts_base_value_fields): Same.

diff --git a/gcc/gimple-streamer-out.c b/gcc/gimple-streamer-out.c
index fcbf92300d4..ae382665218 100644
--- a/gcc/gimple-streamer-out.c
+++ b/gcc/gimple-streamer-out.c
@@ -73,7 +73,7 @@ output_gimple_stmt (struct output_block *ob, struct function *fn, gimple *stmt)
   /* Emit the tuple header.  */
   bp = bitpack_create (ob->main_stream);
   bp_pack_var_len_unsigned (, gimple_num_ops (stmt));
-  bp_pack_value (, gimple_no_warning_p (stmt), 1);
+  bp_pack_value (, get_no_warning (stmt), 1);
   if (is_gimple_assign (stmt))
 bp_pack_value (,
 		   gimple_assign_nontemporal_move_p (
diff --git a/gcc/lto/lto-common.c b/gcc/lto/lto-common.c
index 02d16f49c11..4f78c90effb 100644
--- a/gcc/lto/lto-common.c
+++ b/gcc/lto/lto-common.c
@@ -1110,8 +1110,8 @@ compare_tree_sccs_1 (tree t1, tree t2, tree **map)
 compare_values (TYPE_UNSIGNED);
   if (TYPE_P (t1))
 compare_values (TYPE_ARTIFICIAL);
-  else
-compare_values (TREE_NO_WARNING);
+  else if (t1->base.nowarning_flag != t2->base.nowarning_flag)
+return false;
   compare_values (TREE_NOTHROW);
   compare_values (TREE_STATIC);
   if (code != TREE_BINFO)
diff --git a/gcc/lto-streamer-out.c b/gcc/lto-streamer-out.c
index a26d4885800..7fecb958efa 100644
--- a/gcc/lto-streamer-out.c
+++ b/gcc/lto-streamer-out.c
@@ -1207,7 +1207,7 @@ hash_tree (struct streamer_tree_cache_d *cache, hash_map *map,
   if (TYPE_P (t))
 hstate.add_flag (TYPE_ARTIFICIAL (t));
   else
-hstate.add_flag (TREE_NO_WARNING (t));
+hstate.add_flag (get_no_warning (t));
   hstate.add_flag (TREE_NOTHROW (t));
   hstate.add_flag (TREE_STATIC (t));
   hstate.add_flag (TREE_PROTECTED (t));
diff --git a/gcc/tree-streamer-in.c b/gcc/tree-streamer-in.c
index 984b1e269cf..fab7c678dae 100644
--- a/gcc/tree-streamer-in.c
+++ b/gcc/tree-streamer-in.c
@@ -131,7 +131,8 @@ unpack_ts_base_value_fields (struct bitpack_d *bp, tree expr)
   if (TYPE_P (expr))
 TYPE_ARTIFICIAL (expr) = (unsigned) bp_unpack_value (bp, 1);
   else
-TREE_NO_WARNING (expr) = (unsigned) bp_unpack_value (bp, 1);
+/* FIXME: set all warning bits. */
+set_no_warning (expr, (unsigned) bp_unpack_value (bp, 1));
   TREE_NOTHROW (expr) = (unsigned) bp_unpack_value (bp, 1);
   TREE_STATIC (expr) = (unsigned) bp_unpack_value (bp, 1);
   if (TREE_CODE (expr) != TREE_BINFO)
diff --git a/gcc/tree-streamer-out.c b/gcc/tree-streamer-out.c
index 1a43534d117..d81ff60bd68 100644
--- a/gcc/tree-streamer-out.c
+++ b/gcc/tree-streamer-out.c
@@ -104,7 +104,8 @@ pack_ts_base_value_fields (struct bitpack_d *bp, tree expr)
   if (TYPE_P (expr))
 bp_pack_value (bp, TYPE_ARTIFICIAL (expr), 1);
   else
-bp_pack_value (bp, TREE_NO_WARNING (expr), 1);
+/* FIXME: pack all warning bits.  */
+bp_pack_value (bp, get_no_warning (expr), 1);
   bp_pack_value (bp, TREE_NOTHROW (expr), 1);
   bp_pack_value (bp, TREE_STATIC (expr), 1);
   if (TREE_CODE (expr) != TREE_BINFO)


[PATCH 6/11] use xxx_no_warning APIs in Fortran

2021-05-24 Thread Martin Sebor via Gcc-patches

The attached patch replaces the uses of TREE_NO_WARNING in the Fortran
front end.

I don't know the Fortran front end and I made no effort to try to find
the right warning options in the calls to set/get_no_warning.
Add support for per-location warning groups.

gcc/fortran/ChangeLog:

	* trans-array.c (trans_array_constructor): Replace direct uses
	of TREE_NO_WARNING with get_no_warning, and set_no_warning.
	* trans-decl.c (gfc_build_qualified_array): Same.
	(gfc_build_dummy_array_decl): Same.
	(generate_local_decl): Same.
	(gfc_generate_function_code): Same.
	* trans-openmp.c (gfc_omp_clause_default_ctor): Same.
	(gfc_omp_clause_copy_ctor): Same.
	* trans-types.c (get_dtype_type_node): Same.
	(gfc_get_desc_dim_type): Same.
	(gfc_get_array_descriptor_base): Same.
	(gfc_get_caf_vector_type): Same.
	(gfc_get_caf_reference_type): Same.
	* trans.c (gfc_create_var_np): Same.

diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index 6d38ea78273..30f9138b5cb 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -2755,7 +2755,7 @@ trans_array_constructor (gfc_ss * ss, locus * where)
   desc = ss_info->data.array.descriptor;
   offset = gfc_index_zero_node;
   offsetvar = gfc_create_var_np (gfc_array_index_type, "offset");
-  TREE_NO_WARNING (offsetvar) = 1;
+  set_no_warning (offsetvar);
   TREE_USED (offsetvar) = 0;
   gfc_trans_array_constructor_value (_loop->pre, type, desc, c,
  , , dynamic);
diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c
index 406b4aeb1d4..81579849fe3 100644
--- a/gcc/fortran/trans-decl.c
+++ b/gcc/fortran/trans-decl.c
@@ -1039,7 +1039,7 @@ gfc_build_qualified_array (tree decl, gfc_symbol * sym)
   if (GFC_TYPE_ARRAY_LBOUND (type, dim) == NULL_TREE)
 	{
 	  GFC_TYPE_ARRAY_LBOUND (type, dim) = create_index_var ("lbound", nest);
-	  TREE_NO_WARNING (GFC_TYPE_ARRAY_LBOUND (type, dim)) = 1;
+	  set_no_warning (GFC_TYPE_ARRAY_LBOUND (type, dim));
 	}
   /* Don't try to use the unknown bound for assumed shape arrays.  */
   if (GFC_TYPE_ARRAY_UBOUND (type, dim) == NULL_TREE
@@ -1047,13 +1047,13 @@ gfc_build_qualified_array (tree decl, gfc_symbol * sym)
 	  || dim < GFC_TYPE_ARRAY_RANK (type) - 1))
 	{
 	  GFC_TYPE_ARRAY_UBOUND (type, dim) = create_index_var ("ubound", nest);
-	  TREE_NO_WARNING (GFC_TYPE_ARRAY_UBOUND (type, dim)) = 1;
+	  set_no_warning (GFC_TYPE_ARRAY_UBOUND (type, dim));
 	}
 
   if (GFC_TYPE_ARRAY_STRIDE (type, dim) == NULL_TREE)
 	{
 	  GFC_TYPE_ARRAY_STRIDE (type, dim) = create_index_var ("stride", nest);
-	  TREE_NO_WARNING (GFC_TYPE_ARRAY_STRIDE (type, dim)) = 1;
+	  set_no_warning (GFC_TYPE_ARRAY_STRIDE (type, dim));
 	}
 }
   for (dim = GFC_TYPE_ARRAY_RANK (type);
@@ -1062,21 +1062,21 @@ gfc_build_qualified_array (tree decl, gfc_symbol * sym)
   if (GFC_TYPE_ARRAY_LBOUND (type, dim) == NULL_TREE)
 	{
 	  GFC_TYPE_ARRAY_LBOUND (type, dim) = create_index_var ("lbound", nest);
-	  TREE_NO_WARNING (GFC_TYPE_ARRAY_LBOUND (type, dim)) = 1;
+	  set_no_warning (GFC_TYPE_ARRAY_LBOUND (type, dim));
 	}
   /* Don't try to use the unknown ubound for the last coarray dimension.  */
   if (GFC_TYPE_ARRAY_UBOUND (type, dim) == NULL_TREE
   && dim < GFC_TYPE_ARRAY_RANK (type) + GFC_TYPE_ARRAY_CORANK (type) - 1)
 	{
 	  GFC_TYPE_ARRAY_UBOUND (type, dim) = create_index_var ("ubound", nest);
-	  TREE_NO_WARNING (GFC_TYPE_ARRAY_UBOUND (type, dim)) = 1;
+	  set_no_warning (GFC_TYPE_ARRAY_UBOUND (type, dim));
 	}
 }
   if (GFC_TYPE_ARRAY_OFFSET (type) == NULL_TREE)
 {
   GFC_TYPE_ARRAY_OFFSET (type) = gfc_create_var_np (gfc_array_index_type,
 			"offset");
-  TREE_NO_WARNING (GFC_TYPE_ARRAY_OFFSET (type)) = 1;
+  set_no_warning (GFC_TYPE_ARRAY_OFFSET (type));
 
   if (nest)
 	gfc_add_decl_to_parent_function (GFC_TYPE_ARRAY_OFFSET (type));
@@ -1088,7 +1088,7 @@ gfc_build_qualified_array (tree decl, gfc_symbol * sym)
   && as->type != AS_ASSUMED_SIZE)
 {
   GFC_TYPE_ARRAY_SIZE (type) = create_index_var ("size", nest);
-  TREE_NO_WARNING (GFC_TYPE_ARRAY_SIZE (type)) = 1;
+  set_no_warning (GFC_TYPE_ARRAY_SIZE (type));
 }
 
   if (POINTER_TYPE_P (type))
@@ -1293,7 +1293,7 @@ gfc_build_dummy_array_decl (gfc_symbol * sym, tree dummy)
 
   /* Avoid uninitialized warnings for optional dummy arguments.  */
   if (sym->attr.optional)
-TREE_NO_WARNING (decl) = 1;
+set_no_warning (decl);
 
   /* We should never get deferred shape arrays here.  We used to because of
  frontend bugs.  */
@@ -5974,7 +5974,7 @@ generate_local_decl (gfc_symbol * sym)
 			 "does not have a default initializer",
 			 sym->name, >declared_at);
 	  if (sym->backend_decl != NULL_TREE)
-		TREE_NO_WARNING(sym->backend_decl) = 1;
+		set_no_warning (sym->backend_decl);
 	}
 	  else if (warn_unused_dummy_argument)
 	{
@@ -5984,7 +5984,7 @@ generate_local_decl (gfc_symbol * sym)
 			 >declared_at);
 
 	  if (sym->backend_decl != NULL_TREE)
-		

[PATCH 5/11] use xxx_no_warning APIs in C++

2021-05-24 Thread Martin Sebor via Gcc-patches

The attached patch replaces the uses of TREE_NO_WARNING in the C++
front end.  For the set/get_no_warning calls I tried to find the most
appropriate option to disable and query.  In some cases there are
helpful comments nearby that made this easy.  In other cases it was
less straightforward, and in some I didn't know.  In some of those,
disabling all warnings may be what we want, but in others we might
want to be more selective to further improve efficacy.
Add support for per-location warning groups.

	* call.c (build_over_call): Replace direct uses of TREE_NO_WARNING
	with get_no_warning, set_no_warning, and copy_no_warning, or nothing
	if not necessary.
	(set_up_extended_ref_temp): Same.
	* class.c (layout_class_type): Same.
	* constraint.cc (constraint_satisfaction_value): Same.
	* coroutines.cc (finish_co_await_expr): Same.
	(finish_co_yield_expr): Same.
	(finish_co_return_stmt): Same.
	(build_actor_fn): Same.
	(coro_rewrite_function_body): Same.
	(morph_fn_to_coro): Same.
	* cp-gimplify.c (genericize_eh_spec_block): Same.
	(gimplify_expr_stmt): Same.
	(cp_genericize_r): Same.
	(cp_fold): Same.
	* cp-ubsan.c (cp_ubsan_instrument_vptr): Same.
	* cvt.c (cp_fold_convert): Same.
	(convert_to_void): Same.
	* decl.c (wrapup_namespace_globals): Same.
	(grokdeclarator): Same.
	(finish_function): Same.
	(require_deduced_type): Same.
	* decl2.c (no_linkage_error): Same.
	(c_parse_final_cleanups): Same.
	* except.c (expand_end_catch_block): Same.
	* init.c (build_new_1): Same.
	(build_new): Same.
	(build_vec_delete_1): Same.
	(build_vec_init): Same.
	(build_delete): Same.
	* method.c (defaultable_fn_check): Same.
	* parser.c (cp_parser_fold_expression): Same.
	(cp_parser_primary_expression): Same.
	* pt.c (push_tinst_level_loc): Same.
	(tsubst_copy): Same.
	(tsubst_omp_udr): Same.
	(tsubst_copy_and_build): Same.
	* rtti.c (build_if_nonnull): Same.
	* semantics.c (maybe_convert_cond): Same.
	(finish_return_stmt): Same.
	(finish_parenthesized_expr): Same.
	(cp_check_omp_declare_reduction): Same.
	* tree.c (build_cplus_array_type): Same.
	* typeck.c (build_ptrmemfunc_access_expr): Same.
	(cp_build_indirect_ref_1): Same.
	(cp_build_function_call_vec): Same.
	(warn_for_null_address): Same.
	(cp_build_binary_op): Same.
	(unary_complex_lvalue): Same.
	(cp_build_modify_expr): Same.
	(build_x_modify_expr): Same.
	(convert_for_assignment): Same.

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 4a59b97c110..2355020066a 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -9437,7 +9437,7 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
 	{
 	  /* Avoid copying empty classes.  */
 	  val = build2 (COMPOUND_EXPR, type, arg, to);
-	  TREE_NO_WARNING (val) = 1;
+	  set_no_warning (val, OPT_Wunused);
 	}
   else if (tree_int_cst_equal (TYPE_SIZE (type), TYPE_SIZE (as_base)))
 	{
@@ -9468,7 +9468,7 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
 		  build2 (MEM_REF, array_type, arg0, alias_set),
 		  build2 (MEM_REF, array_type, arg, alias_set));
 	  val = build2 (COMPOUND_EXPR, TREE_TYPE (to), t, to);
-  TREE_NO_WARNING (val) = 1;
+  set_no_warning (val, OPT_Wunused);
 	}
 
   cp_warn_deprecated_use (fn, complain);
@@ -9542,7 +9542,7 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
 {
   tree c = extract_call_expr (call);
   if (TREE_CODE (c) == CALL_EXPR)
-	TREE_NO_WARNING (c) = 1;
+	set_no_warning (c /* Suppress all warnings.  */);
 }
   if (TREE_CODE (fn) == ADDR_EXPR)
 {
@@ -12491,11 +12491,11 @@ set_up_extended_ref_temp (tree decl, tree expr, vec **cleanups,
 TREE_ADDRESSABLE (var) = 1;
 
   if (TREE_CODE (decl) == FIELD_DECL
-  && extra_warnings && !TREE_NO_WARNING (decl))
+  && extra_warnings && !get_no_warning (decl))
 {
   warning (OPT_Wextra, "a temporary bound to %qD only persists "
 	   "until the constructor exits", decl);
-  TREE_NO_WARNING (decl) = true;
+  set_no_warning (decl);
 }
 
   /* Recursively extend temps in this initializer.  */
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index 354addde773..c3024842f87 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -6689,7 +6689,7 @@ layout_class_type (tree t, tree *virtuals_p)
 	 laying out an Objective-C class.  The ObjC ABI differs
 	 from the C++ ABI, and so we do not want a warning
 	 here.  */
-	  && !TREE_NO_WARNING (field)
+	  && !get_no_warning (field, OPT_Wabi)
 	  && !last_field_was_bitfield
 	  && !integer_zerop (size_binop (TRUNC_MOD_EXPR,
 	 DECL_FIELD_BIT_OFFSET (field),
diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
index 03ce8eb9ff2..c30127662b5 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -3281,14 +3281,14 @@ constraint_satisfaction_value (tree t, tree args, sat_info info)
   else
 r = satisfy_nondeclaration_constraints (t, args, info);
   if (r == error_mark_node && info.quiet ()
-  && !(DECL_P (t) && 

[PATCH 4/11] use xxx_no_warning APIs in C family

2021-05-24 Thread Martin Sebor via Gcc-patches

The attached patch replaces the uses of TREE_NO_WARNING in the C
family common subset of the C and C++ front ends.

Add support for per-location warning groups.

gcc/c-family/ChangeLog:

	* c-common.c (c_wrap_maybe_const): Remove TREE_NO_WARNING.
	(c_common_truthvalue_conversion): Replace direct uses of
	TREE_NO_WARNING with get_no_warning, set_no_warning, and
	copy_no_warning.
	(check_function_arguments_recurse): Same.
	* c-gimplify.c (c_gimplify_expr): Same.
	* c-warn.c (overflow_warning): Same.
	(warn_logical_operator): Same.
	(warn_if_unused_value): Same.
	(do_warn_unused_parameter): Same.

diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index b7daa2e2654..a97376c5fd1 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -3236,7 +3236,6 @@ pointer_int_sum (location_t loc, enum tree_code resultcode,
 tree
 c_wrap_maybe_const (tree expr, bool non_const)
 {
-  bool nowarning = TREE_NO_WARNING (expr);
   location_t loc = EXPR_LOCATION (expr);
 
   /* This should never be called for C++.  */
@@ -3247,8 +3246,6 @@ c_wrap_maybe_const (tree expr, bool non_const)
   STRIP_TYPE_NOPS (expr);
   expr = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (expr), NULL, expr);
   C_MAYBE_CONST_EXPR_NON_CONST (expr) = non_const;
-  if (nowarning)
-TREE_NO_WARNING (expr) = 1;
   protected_set_expr_location (expr, loc);
 
   return expr;
@@ -3494,12 +3491,12 @@ c_common_truthvalue_conversion (location_t location, tree expr)
   break;
 
 case MODIFY_EXPR:
-  if (!TREE_NO_WARNING (expr)
+  if (!get_no_warning (expr, OPT_Wparentheses)
 	  && warn_parentheses
 	  && warning_at (location, OPT_Wparentheses,
 			 "suggest parentheses around assignment used as "
 			 "truth value"))
-	TREE_NO_WARNING (expr) = 1;
+	set_no_warning (expr, OPT_Wparentheses);
   break;
 
 case CONST_DECL:
@@ -5880,7 +5877,7 @@ check_function_arguments_recurse (void (*callback)
   void *ctx, tree param,
   unsigned HOST_WIDE_INT param_num)
 {
-  if (TREE_NO_WARNING (param))
+  if (get_no_warning (param))
 return;
 
   if (CONVERT_EXPR_P (param)
diff --git a/gcc/c-family/c-gimplify.c b/gcc/c-family/c-gimplify.c
index 39c969d8f40..8a6b36fc846 100644
--- a/gcc/c-family/c-gimplify.c
+++ b/gcc/c-family/c-gimplify.c
@@ -713,7 +713,7 @@ c_gimplify_expr (tree *expr_p, gimple_seq *pre_p ATTRIBUTE_UNUSED,
 	  && !TREE_STATIC (DECL_EXPR_DECL (*expr_p))
 	  && (DECL_INITIAL (DECL_EXPR_DECL (*expr_p)) == DECL_EXPR_DECL (*expr_p))
 	  && !warn_init_self)
-	TREE_NO_WARNING (DECL_EXPR_DECL (*expr_p)) = 1;
+	set_no_warning (DECL_EXPR_DECL (*expr_p), OPT_Winit_self);
   break;
 
 case PREINCREMENT_EXPR:
diff --git a/gcc/c-family/c-warn.c b/gcc/c-family/c-warn.c
index c48dc2e6d24..2af2bc0a43f 100644
--- a/gcc/c-family/c-warn.c
+++ b/gcc/c-family/c-warn.c
@@ -155,7 +155,7 @@ overflow_warning (location_t loc, tree value, tree expr)
 			 value);
 
   if (warned)
-TREE_NO_WARNING (value) = 1;
+set_no_warning (value, OPT_Woverflow);
 }
 
 /* Helper function for walk_tree.  Unwrap C_MAYBE_CONST_EXPRs in an expression
@@ -219,7 +219,7 @@ warn_logical_operator (location_t location, enum tree_code code, tree type,
   && INTEGRAL_TYPE_P (TREE_TYPE (op_left))
   && !CONSTANT_CLASS_P (stripped_op_left)
   && TREE_CODE (stripped_op_left) != CONST_DECL
-  && !TREE_NO_WARNING (op_left)
+  && !get_no_warning (op_left, OPT_Wlogical_op)
   && TREE_CODE (op_right) == INTEGER_CST
   && !integer_zerop (op_right)
   && !integer_onep (op_right))
@@ -234,7 +234,7 @@ warn_logical_operator (location_t location, enum tree_code code, tree type,
 	  = warning_at (location, OPT_Wlogical_op,
 			"logical % applied to non-boolean constant");
   if (warned)
-	TREE_NO_WARNING (op_left) = true;
+	set_no_warning (op_left, OPT_Wlogical_op);
   return;
 }
 
@@ -588,7 +588,7 @@ bool
 warn_if_unused_value (const_tree exp, location_t locus, bool quiet)
 {
  restart:
-  if (TREE_USED (exp) || TREE_NO_WARNING (exp))
+  if (TREE_USED (exp) || get_no_warning (exp, OPT_Wunused_value))
 return false;
 
   /* Don't warn about void constructs.  This includes casting to void,
@@ -2422,7 +2422,7 @@ do_warn_unused_parameter (tree fn)
decl; decl = DECL_CHAIN (decl))
 if (!TREE_USED (decl) && TREE_CODE (decl) == PARM_DECL
 	&& DECL_NAME (decl) && !DECL_ARTIFICIAL (decl)
-	&& !TREE_NO_WARNING (decl))
+	&& !get_no_warning (decl, OPT_Wunused_parameter))
   warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wunused_parameter,
 		  "unused parameter %qD", decl);
 }


[PATCH 3/11] use xxx_no_warning APIs in C

2021-05-24 Thread Martin Sebor via Gcc-patches

The attached patch replaces the uses of TREE_NO_WARNING in the C
front end.
Add support for per-location warning groups.

gcc/c/ChangeLog:

	* c-decl.c (pop_scope): Replace direct uses of TREE_NO_WARNING with
	get_no_warning, set_no_warning, and copy_no_warning.
	(diagnose_mismatched_decls): Same.
	(duplicate_decls): Same.
	(grokdeclarator): Same.
	(finish_function): Same.
	(c_write_global_declarations_1): Same.
	* c-fold.c (c_fully_fold_internal): Same.
	* c-parser.c (c_parser_expr_no_commas): Same.
	(c_parser_postfix_expression): Same.
	* c-typeck.c (array_to_pointer_conversion): Same.
	(function_to_pointer_conversion): Same.
	(default_function_array_conversion): Same.
	(convert_lvalue_to_rvalue): Same.
	(default_conversion): Same.
	(build_indirect_ref): Same.
	(build_function_call_vec): Same.
	(build_atomic_assign): Same.
	(build_unary_op): Same.
	(c_finish_return): Same.
	(emit_side_effect_warnings): Same.
	(c_finish_stmt_expr): Same.
	(c_omp_clause_copy_ctor): Same.

diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
index 53b2b5b637d..800f08ed7b9 100644
--- a/gcc/c/c-decl.c
+++ b/gcc/c/c-decl.c
@@ -1295,7 +1295,7 @@ pop_scope (void)
 	case VAR_DECL:
 	  /* Warnings for unused variables.  */
 	  if ((!TREE_USED (p) || !DECL_READ_P (p))
-	  && !TREE_NO_WARNING (p)
+	  && !get_no_warning (p, OPT_Wunused_but_set_variable)
 	  && !DECL_IN_SYSTEM_HEADER (p)
 	  && DECL_NAME (p)
 	  && !DECL_ARTIFICIAL (p)
@@ -2159,8 +2159,8 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl,
 
   if (DECL_IN_SYSTEM_HEADER (newdecl)
 	  || DECL_IN_SYSTEM_HEADER (olddecl)
-	  || TREE_NO_WARNING (newdecl)
-	  || TREE_NO_WARNING (olddecl))
+	  || get_no_warning (newdecl, OPT_Wpedantic)
+	  || get_no_warning (olddecl, OPT_Wpedantic))
 	return true;  /* Allow OLDDECL to continue in use.  */
 
   if (variably_modified_type_p (newtype, NULL))
@@ -2953,7 +2953,7 @@ duplicate_decls (tree newdecl, tree olddecl)
   if (!diagnose_mismatched_decls (newdecl, olddecl, , ))
 {
   /* Avoid `unused variable' and other warnings for OLDDECL.  */
-  TREE_NO_WARNING (olddecl) = 1;
+  set_no_warning (olddecl, OPT_Wunused);
   return false;
 }
 
@@ -7540,10 +7540,7 @@ grokdeclarator (const struct c_declarator *declarator,
 			   FIELD_DECL, declarator->u.id.id, type);
 	DECL_NONADDRESSABLE_P (decl) = bitfield;
 	if (bitfield && !declarator->u.id.id)
-	  {
-	TREE_NO_WARNING (decl) = 1;
-	DECL_PADDING_P (decl) = 1;
-	  }
+	  DECL_PADDING_P (decl) = 1;
 
 	if (size_varies)
 	  C_DECL_VARIABLE_SIZE (decl) = 1;
@@ -10225,7 +10222,7 @@ finish_function (location_t end_loc)
   && targetm.warn_func_return (fndecl)
   && warning (OPT_Wreturn_type,
 		  "no return statement in function returning non-void"))
-TREE_NO_WARNING (fndecl) = 1;
+set_no_warning (fndecl, OPT_Wreturn_type);
 
   /* Complain about parameters that are only set, but never otherwise used.  */
   if (warn_unused_but_set_parameter)
@@ -10240,7 +10237,7 @@ finish_function (location_t end_loc)
 	&& !DECL_READ_P (decl)
 	&& DECL_NAME (decl)
 	&& !DECL_ARTIFICIAL (decl)
-	&& !TREE_NO_WARNING (decl))
+	&& !get_no_warning (decl, OPT_Wunused_but_set_parameter))
 	  warning_at (DECL_SOURCE_LOCATION (decl),
 		  OPT_Wunused_but_set_parameter,
 		  "parameter %qD set but not used", decl);
@@ -12106,19 +12103,20 @@ c_write_global_declarations_1 (tree globals)
 	{
 	  if (C_DECL_USED (decl))
 	{
+	  /* TODO: Add OPT_Wundefined-inline.  */
 	  if (pedwarn (input_location, 0, "%q+F used but never defined",
 			   decl))
-		TREE_NO_WARNING (decl) = 1;
+		set_no_warning (decl /* OPT_Wundefined-inline.  */);
 	}
 	  /* For -Wunused-function warn about unused static prototypes.  */
 	  else if (warn_unused_function
 		   && ! DECL_ARTIFICIAL (decl)
-		   && ! TREE_NO_WARNING (decl))
+		   && ! get_no_warning (decl, OPT_Wunused_function))
 	{
 	  if (warning (OPT_Wunused_function,
 			   "%q+F declared % but never defined",
 			   decl))
-		TREE_NO_WARNING (decl) = 1;
+		set_no_warning (decl, OPT_Wunused_function);
 	}
 	}
 
diff --git a/gcc/c/c-fold.c b/gcc/c/c-fold.c
index 68c74cc1eb2..5bc90ad541b 100644
--- a/gcc/c/c-fold.c
+++ b/gcc/c/c-fold.c
@@ -154,7 +154,7 @@ c_fully_fold_internal (tree expr, bool in_init, bool *maybe_const_operands,
   tree orig_op0, orig_op1, orig_op2;
   bool op0_const = true, op1_const = true, op2_const = true;
   bool op0_const_self = true, op1_const_self = true, op2_const_self = true;
-  bool nowarning = TREE_NO_WARNING (expr);
+  bool nowarning = get_no_warning (expr, OPT_Woverflow);
   bool unused_p;
   bool op0_lval = false;
   source_range old_range;
@@ -670,13 +670,13 @@ c_fully_fold_internal (tree expr, bool in_init, bool *maybe_const_operands,
  out:
   /* Some folding may introduce NON_LVALUE_EXPRs; all lvalue checks
  have been done by this point, so remove them again.  */
-  nowarning |= TREE_NO_WARNING (ret);
+  nowarning |= 

[PATCH 2/11] use xxx_no_warning APIs in Ada

2021-05-24 Thread Martin Sebor via Gcc-patches

[PATCH 2/11] use xxx_no_warning APIs in Ada.
Add support for per-location warning groups.

gcc/ada/ChangeLog:

	* gcc-interface/trans.c (Handled_Sequence_Of_Statements_to_gnu):
	Replace TREE_NO_WARNING with set_no_warning.
	(gnat_gimplify_expr): Same.
	* gcc-interface/utils.c (gnat_pushdecl): Same.

diff --git a/gcc/ada/gcc-interface/trans.c b/gcc/ada/gcc-interface/trans.c
index 9aeaf038118..63d662669ef 100644
--- a/gcc/ada/gcc-interface/trans.c
+++ b/gcc/ada/gcc-interface/trans.c
@@ -5357,7 +5357,7 @@ Handled_Sequence_Of_Statements_to_gnu (Node_Id gnat_node)
 	 because of the unstructured form of EH used by fe_sjlj_eh, there
 	 might be forward edges going to __builtin_setjmp receivers on which
 	 it is uninitialized, although they will never be actually taken.  */
-  TREE_NO_WARNING (gnu_jmpsave_decl) = 1;
+  set_no_warning (gnu_jmpsave_decl, OPT_Wuninitialized);
   gnu_jmpbuf_decl
 	= create_var_decl (get_identifier ("JMP_BUF"), NULL_TREE,
 			   jmpbuf_type,
@@ -8792,7 +8792,7 @@ gnat_gimplify_expr (tree *expr_p, gimple_seq *pre_p,
   else
 	{
 	  *expr_p = create_tmp_var (type, NULL);
-	  TREE_NO_WARNING (*expr_p) = 1;
+	  set_no_warning (*expr_p);
 	}
 
   gimplify_and_add (TREE_OPERAND (expr, 0), pre_p);
diff --git a/gcc/ada/gcc-interface/utils.c b/gcc/ada/gcc-interface/utils.c
index 80a4160adf3..7d08ae9193a 100644
--- a/gcc/ada/gcc-interface/utils.c
+++ b/gcc/ada/gcc-interface/utils.c
@@ -836,7 +836,7 @@ gnat_pushdecl (tree decl, Node_Id gnat_node)
   if (!deferred_decl_context)
 DECL_CONTEXT (decl) = context;
 
-  TREE_NO_WARNING (decl) = (No (gnat_node) || Warnings_Off (gnat_node));
+  set_no_warning (decl, (No (gnat_node) || Warnings_Off (gnat_node)));
 
   /* Set the location of DECL and emit a declaration for it.  */
   if (Present (gnat_node) && !renaming_from_instantiation_p (gnat_node))


[PATCH 1/11] introduce xxx_no_warning APIs

2021-05-24 Thread Martin Sebor via Gcc-patches

The attached patch introduces the get_no_warning(), set_no_warning(),
and copy_no_warning() APIs without making use of them in the rest of
GCC.  They are in three files:

  diagnostic-spec.{h,c}: Location-centric overloads.
  warning-control.cc: Tree- and gimple*-centric overloads.

The location-centric overloads are suitable to use from the diagnostic
subsystem.  The rest can be used from the front ends and the middle end.
Add support for per-location warning groups.

gcc/ChangeLog:

	* Makefile.in (OBJS-libcommon): Add diagnostic-spec.o.
	* gengtype.c (open_base_files): Add diagnostic-spec.h.
	* diagnostic-spec.c: New file.
	* diagnostic-spec.h: New file.
	* warning-control.cc: New file.

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 1164554e6d6..b7bbcb60051 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1696,6 +1696,7 @@ OBJS = \
 	vmsdbgout.o \
 	vr-values.o \
 	vtable-verify.o \
+	warning-control.o \
 	web.o \
 	wide-int.o \
 	wide-int-print.o \
@@ -1707,8 +1708,8 @@ OBJS = \
 
 # Objects in libcommon.a, potentially used by all host binaries and with
 # no target dependencies.
-OBJS-libcommon = diagnostic.o diagnostic-color.o diagnostic-show-locus.o \
-	diagnostic-format-json.o json.o \
+OBJS-libcommon = diagnostic-spec.o diagnostic.o diagnostic-color.o \
+	diagnostic-show-locus.o diagnostic-format-json.o json.o \
 	edit-context.o \
 	pretty-print.o intl.o \
 	sbitmap.o \
@@ -2648,6 +2649,7 @@ GTFILES = $(CPPLIB_H) $(srcdir)/input.h $(srcdir)/coretypes.h \
   $(srcdir)/ipa-modref.h $(srcdir)/ipa-modref.c \
   $(srcdir)/ipa-modref-tree.h \
   $(srcdir)/signop.h \
+  $(srcdir)/diagnostic-spec.h $(srcdir)/diagnostic-spec.c \
   $(srcdir)/dwarf2out.h \
   $(srcdir)/dwarf2asm.c \
   $(srcdir)/dwarf2cfi.c \
diff --git a/gcc/diagnostic-spec.c b/gcc/diagnostic-spec.c
new file mode 100644
index 000..582ae3f3fe2
--- /dev/null
+++ b/gcc/diagnostic-spec.c
@@ -0,0 +1,172 @@
+/* Functions to enable and disable individual warnings on an expression
+   and statement basis.
+   Copyright (C) 2021 Free Software Foundation, Inc.
+   Contributed by Martin Sebor 
+
+   This file is part of GCC.
+
+   GCC is free software; you can redistribute it and/or modify it under
+   the terms of the GNU General Public License as published by the Free
+   Software Foundation; either version 3, or (at your option) any later
+   version.
+
+   GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+   WARRANTY; without even the implied warranty of MERCHANTABILITY or
+   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+   for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GCC; see the file COPYING3.  If not see
+   .  */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "backend.h"
+#include "bitmap.h"
+#include "tree.h"
+#include "cgraph.h"
+#include "hash-map.h"
+#include "diagnostic-spec.h"
+#include "pretty-print.h"
+
+/* Initialize *THIS from warning option OPT.  */
+
+nowarn_spec_t::nowarn_spec_t (int opt)
+{
+  /* Create a very simple mapping based on testing and experience.
+ It should become more refined with time. */
+  switch (opt)
+{
+case 0:
+case -1:
+  bits = opt;
+  break;
+
+  /* Flow-sensitive warnings about pointer problems issued by both
+	 front ends and the middle end.  */
+case OPT_Waddress:
+case OPT_Wnonnull:
+  bits = NW_NONNULL;
+  break;
+
+  /* Flow-sensitive warnings about arithmetic overflow issued by both
+	 front ends and the middle end.  */
+case OPT_Woverflow:
+case OPT_Wshift_count_negative:
+case OPT_Wshift_count_overflow:
+case OPT_Wstrict_overflow:
+  bits = NW_VFLOW;
+  break;
+
+  /* Lexical warnings issued by front ends.  */
+case OPT_Wabi:
+case OPT_Wlogical_op:
+case OPT_Wparentheses:
+case OPT_Wreturn_type:
+case OPT_Wsizeof_array_div:
+case OPT_Wstrict_aliasing:
+case OPT_Wunused:
+case OPT_Wunused_function:
+case OPT_Wunused_but_set_variable:
+case OPT_Wunused_variable:
+case OPT_Wunused_but_set_parameter:
+  bits = NW_LEXICAL;
+  break;
+
+  /* Access warning group.  */
+case OPT_Warray_bounds:
+case OPT_Warray_bounds_:
+case OPT_Wformat_overflow_:
+case OPT_Wformat_truncation_:
+case OPT_Wrestrict:
+case OPT_Wstrict_aliasing_:
+case OPT_Wstringop_overflow_:
+case OPT_Wstringop_overread:
+case OPT_Wstringop_truncation:
+  bits = NW_ACCESS;
+  break;
+
+  /* Initialization warning group.  */
+case OPT_Winit_self:
+case OPT_Wuninitialized:
+case OPT_Wmaybe_uninitialized:
+	bits = NW_UNINIT;
+  break;
+
+default:
+  /* A catchall group for everything else.  */
+  bits = NW_OTHER;
+}
+}
+
+/* Map from location to its no-warning disposition.  */
+
+GTY(()) xint_hash_map_t *nowarn_map;
+
+/* Return the no-warning 

[PATCH 0/11] warning control by group and location (PR 74765)

2021-05-24 Thread Martin Sebor via Gcc-patches

Having just one bit control whether an expression or statement should
be allowed to trigger warnings has been a source of bug reports about
false negatives for years.  PR 74765 has a representative test case
that shows how by setting the bit to avoid -Wparentheses the C++ front
end also ends up preventing valid -Wuninitialized in the middle end,
but there are other such reports for C (e.g., PR 74762) as well as
the middle end.

This patch series solves the problem by associating an expression
(whether a tree node or a GIMPLE statement) with more than one such
bit through its location.  Each new bit in the mapping corresponds
to a group of warnings (e.g., lexical, access, etc.), and each
location may be associated with a simple bitmap with one bit for
each group.  The initial groups are mostly ad hoc and should be
refined over time.  The rare expressions that have no location
continue to have just one bit[1].

The first patch introduces three new APIs without making use of them
in existing code:

  bool get_no_warning (..., int option);
  void set_no_warning (..., int option, ...);
  void copy_no_warning (...);

Subsequent patches then replace invocations of the TREE_NO_WARNING()
macro and the gimple_no_warning_p() and gimple_set_no_warning()
functions throughout GCC with those and remove the legacy APIs to
keep them from being accidentally reintroduced along with the problem.
These are mostly mechanical changes, except that most of the new
invocations also specify the option whose disposition to query for
the expression or location, or which to enable or disable[2].
The last function, copy_no_warning(), copies the disposition from
one expression or location to another.

A couple of design choices might be helpful to explain:

First, introducing "warning groups" rather than controlling each
individual warning is motivated by a) the fact that the latter
would make avoiding redundant warnings for related problems
cumbersome (e.g., after issuing a -Warray-bounds we want to
suppress -Wstringop-overflow as well -Wstringop-overread for
the same access and vice versa), and b) simplicity and efficiency
of the implementation (mapping each option would require a more
complex data structure like a bitmap).

Second, using location_t to associate expressions/statements with
the warning groups also turns out to be more useful in practice
than a direct association between a tree or gimple*, and also
simplifies managing the data structure.  Trees and gimple* come
and go across passes, and maintaining a mapping for them that
accounts for the possibility of them being garbage-collected
and the same addresses reused is less than straightforward.

Martin

[1] My expectation is to work toward providing locations for all
expressions/statements, even if it's the opening or closing brace
of the function they're used in.)

[2] A number of {get,set}_no_warning() calls introduced by the patch
don't provide an option argument and query or set just the one bit in
the expression/statement.  Some of these may be correct as they are,
but others could be refined to also specify an option.  I can do that
in a follow-up patch if someone helps me find the right option.


Re: [PATCH] diagnostics: Support for -finput-charset [PR93067]

2021-05-24 Thread Lewis Hyatt via Gcc-patches
On Tue, May 18, 2021 at 5:31 AM Iain Buclaw  wrote:
>
> Excerpts from Lewis Hyatt via Gcc-patches's message of January 29, 2021 4:46 
> pm:
> > Q1: What is the input charset?
> > A1:
> >
> > libcpp: Whatever was passed to -finput-charset (note, for Fortran,
> > -finput-charset is not supported though.)
> >
> > go: Assume UTF-8.
> >
> > D: UTF-8, UTF-16, or UTF-32 (the latter two in either
> >endianness); determined by inspecting the first bytes of the file.
> >
> > Q2: How should a UTF-8 BOM be handled?
> > A2:
> >
> > libcpp: Treat entirely the same, as if it was not present at all. So
> > a diagnostic referring to the first non-BOM character in the file will
> > point to column 1, not to column 4.
> >
> > go: Treat it like whitespace, ignored for parsing purposes, but still
> > logically part of the file. A diagnostic referring to the first non-BOM
> > character in the file will point to column 4.
> >
> > D: Same as libcpp.
> >
> > So input.c's current behavior (with or without my patch) actually matches
> > the "go" frontend exactly and does the right thing for it. As you
> > thought, though, for D it would be desirable to skip over the UTF-8 BOM
> > too.
> >
> > D adds an additional wrinkle in that, instead of using -finput-charset, it
> > uses its own detection logic -- based on knowledge that the first codepoint
> > in the file must be ASCII, it is able to deduce the encoding from the first
> > few bytes. This means that in D, each source file can have a different
> > encoding, which is not expressible in libcpp frontends currently, and hence
> > the notion of a global input_cpp_context with a constant charset is not
> > sufficient to capture this.
> >
>
> Yes, that is correct for D.
>
> > In this iteration of the patch, I replaced the input_cpp_context with a more
> > general input_context that can handle all of these cases. The context now
> > consists of a callback function and a bool, which the frontend is supposed
> > to configure. The bool determines whether or not to skip the BOM. The
> > callback, when passed a filename, returns the input charset needed to
> > convert that file. For libcpp, the filename is not used as the charset is
> > determined from -finput-charset for all files. For D, the callback function
> > is currently a stub, but it could be expanded to open the file, read the
> > first few bytes, and determine the charset to be used. I have not
> > implemented it for now, because it seems inelegant to duplicate the logic D
> > already has for this detection, but this logic is part of the dmd/ tree
> > which I think is maintained external to GCC, and so it didn't seem right to
> > attempt to refactor it. I figured there may not be much interest in this
> > feature (diagnostics are already unusable for UTF-16 and UTF-32 sources in
> > D), and this patch makes no change to it. This patch does fix the handling
> > of a UTF-8 BOM in D diagnostics, however.
> >
>
> And yes, dmd/ is maintained in a separate upstream repository.
>
> I wouldn't worry about UTF-16 and UTF-32.  I expect all the sources
> written in those charsets are found only in the D testsuite.
>
> > gcc/d/ChangeLog:
> >
> >   PR other/93067
> >   * d-lang.cc (d_input_charset_callback): New function.
> >   (d_init): Call new function input_initialize_context().
> >
>
> > diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc
> > index 0fd207da7f3..9f170c09886 100644
> > --- a/gcc/d/d-lang.cc
> > +++ b/gcc/d/d-lang.cc
> > @@ -50,6 +50,7 @@ along with GCC; see the file COPYING3.  If not see
> >  #include "output.h"
> >  #include "print-tree.h"
> >  #include "debug.h"
> > +#include "input.h"
> >
> >  #include "d-tree.h"
> >  #include "id.h"
> > @@ -362,6 +363,19 @@ d_option_lang_mask (void)
> >return CL_D;
> >  }
> >
> > +/* Implements input charset and BOM skipping configuration for
> > +   diagnostics.  */
> > +static const char *d_input_charset_callback (const char * /*filename*/)
> > +{
> > +  /* TODO: The input charset is automatically determined by code in
> > + dmd/dmodule.c based on the contents of the file.  If this detection
> > + logic were factored out and could be reused here, then we would be 
> > able
> > + to return UTF-16 or UTF-32 as needed here.  For now, we return always
> > + NULL, which means no conversion is necessary, i.e. the input is 
> > assumed
> > + to be UTF-8 when diagnostics read this file.  */
> > +  return NULL;
> > +}
> > +
>
> OK from me.
>
> I can have a look into this, but it will have to wait until after I do
> an impending switch-over of the dmd/ sources from C++ to D.  Then I'd
> have to convince upstream to be open to the change (refactoring has been
> getting a bad rep as of late for sneaking regressions into upstream D).
>
> Iain.

Thank you very much for taking a look at it. I am not sure yet if
David likes the approach of this patch, but in case he does approve
and we go this way or similar, I'll keep 

Re: [PATCH] go/100537 - Bootstrap-O3 and bootstrap-debug fail

2021-05-24 Thread Ian Lance Taylor via Gcc-patches
I've committed a patch to the Go frontend that fixes this problem.
Thanks for the analysis.

Ian

On Thu, May 20, 2021 at 1:59 AM guojiufu  wrote:
>
> On 2021-05-18 14:58, Richard Biener wrote:
> > On Mon, 17 May 2021, Ian Lance Taylor wrote:
> >
> >> On Mon, May 17, 2021 at 1:17 AM Richard Biener via Gcc-patches
> >>  wrote:
> >> >
> >> > On Fri, May 14, 2021 at 11:19 AM guojiufu via Gcc-patches
> >> >  wrote:
> >> > >
> >> > > On 2021-05-14 15:39, guojiufu via Gcc-patches wrote:
> >> > > > On 2021-05-14 15:15, Richard Biener wrote:
> >> > > >> On May 14, 2021 4:52:56 AM GMT+02:00, Jiufu Guo
> >> > > >>  wrote:
> >> > > >>> As discussed in the PR, Richard mentioned the method to
> >> > > >>> figure out which VAR was not set TREE_ADDRESSABLE, and
> >> > > >>> then cause this failure.  It is address_expression which
> >> > > >>> build addr_expr (build_fold_addr_expr_loc), but not set
> >> > > >>> TREE_ADDRESSABLE.
> >> > > >>>
> >> > > >>> I drafted this patch with reference the comments from Richard
> >> > > >>> in this PR, while I'm not quite sure if more thing need to do.
> >> > > >>> So, please have review, thanks!
> >> > > >>>
> >> > > >>> Bootstrap and regtest pass on ppc64le. Is this ok for trunk?
> >> > > >>
> >> > > >> I suggest to use mark_addresssable unless we're sure expr is always 
> >> > > >> an
> >> > > >> entity where TREE_ADDRESSABLE has the desired meaning.
> >> > >
> >> > > Thanks, Richard!
> >> > > You point out the root concern, I'm not sure ;)
> >> > >
> >> > > With looking at code "mark_addresssable" and code around
> >> > > tree-ssa.c:1013,
> >> > > VAR_P, PARM_DECL, and RESULT_DECL are checked before accessing
> >> > > TREE_ADDRESSABLE.
> >> > > So, just wondering if these entities need to be marked as
> >> > > TREE_ADDRESSABLE?
> >> > >
> >> > > diff --git a/gcc/go/go-gcc.cc b/gcc/go/go-gcc.cc
> >> > > index 5d9dbb5d068..85d324a92cc 100644
> >> > > --- a/gcc/go/go-gcc.cc
> >> > > +++ b/gcc/go/go-gcc.cc
> >> > > @@ -1680,6 +1680,11 @@ Gcc_backend::address_expression(Bexpression*
> >> > > bexpr, Location location)
> >> > > if (expr == error_mark_node)
> >> > >   return this->error_expression();
> >> > >
> >> > > +  if ((VAR_P(expr)
> >> > > +   || TREE_CODE(expr) == PARM_DECL
> >> > > +   || TREE_CODE(expr) == RESULT_DECL)
> >> > > +TREE_ADDRESSABLE (expr) = 1;
> >> > > +
> >> >
> >> > The root concern is that mark_addressable does
> >> >
> >> >   while (handled_component_p (x))
> >> > x = TREE_OPERAND (x, 0);
> >> >
> >> > and I do not know the constraints on 'expr' as passed to
> >> > Gcc_backend::address_expression.
> >> >
> >> > I think we need input from Ian here.  Most FEs have their own 
> >> > *_mark_addressable
> >> > function where they also emit diagnostics (guess this is handled in
> >> > the actual Go frontend).
> >> > Since Gcc_backend does lowering to GENERIC using a middle-end is 
> >> > probably OK.
> >>
> >> I doubt I understand all the issues here.
> >>
> >> In general the Go frontend only takes the addresses of VAR_DECLs or
> >> PARM_DECLs.  It doesn't bother to set TREE_ADDRESSABLE for global
> >> variables for which TREE_STATIC or DECL_EXTERNAL is true.  For local
> >> variables it sets TREE_ADDRESSABLE based on the is_address_taken
> >> parameter to Gcc_backend::local_variable, and similarly for PARM_DECLs
> >> and Gcc_backend::parameter_variable.
> >>
> >> The name in the bug report is for a string initializer, which should
> >> be TREE_STATIC == 1 and TREE_PUBLIC == 0.  Perhaps the fix is simply
> >> to set TREE_ADDRESSABLE in Gcc_backend::immutable_struct and
> >> Gcc_backend::implicit_variable.  I can't see how it would hurt to set
> >> TREE_ADDRESSABLE unnecessarily for a TREE_STATIC variable.
> >>
> >> But, again, I doubt I understand all the issues here.
> >
> > GENERIC requires TREE_ADDRESSABLE to be set on all address-taken
> > VAR_DECLs, PARM_DECLs and RESULT_DECLs - the gimplifier is the
> > first to require this for correctness.  Setting TREE_ADDRESSABLE
> > when the address is not taken is harmless and at most results in
> > missed optimizations (on most entities we are able to clear the
> > flag later).
> >
> > We're currently quite forgiving with this though (still the
> > gimplifier can generate wrong-code).  The trigger of the current
> > failure removed one "forgiveness", I do plan to remove a few more.
> >
> > guojiufu's patch works for me but as said I'm not sure if there's
> > a better place to set TREE_ADDRESSABLE for entities that have
> > their address taken - definitely catching the places where
> > you build an ADDR_EXPR are the most obvious ones.
> >
> > Richard.
>
> I tested below patch As Ian said, bootstrap pass.
>
> 
> diff --git a/gcc/go/go-gcc.cc b/gcc/go/go-gcc.cc
> index 5d9dbb5d068..529f657598a 100644
> --- a/gcc/go/go-gcc.cc
> +++ b/gcc/go/go-gcc.cc
> @@ -2943,6 +2943,7 @@ Gcc_backend::implicit_variable(const std::string&
> name,
> TREE_STATIC(decl) = 1;
> 

Re: [PATCH 06/57] rs6000: Add helper functions for parsing

2021-05-24 Thread Segher Boessenkool
On Mon, May 24, 2021 at 12:37:30AM +0200, Bernhard Reutner-Fischer wrote:
> On 21 May 2021 22:56:09 CEST, Bill Schmidt via Gcc-patches 
>  wrote:
> >>> +  char *buf = (char *) malloc (lastpos - pos + 2);
> >>> +  memcpy (buf, [pos], lastpos - pos + 1);
> >>> +  buf[lastpos - pos + 1] = '\0';

> You saw the unchecked usage of the malloc return value, did you?

Yes, and it is Good.  We do not assert on things that will fail on the
next statement anyway, in general.

Also, this is not part of the compiler, this is a tool used to *build*
the compiler, so it is fine to have less user-friendly errors anyway.

> We certainly warn about that, I'd hope.

Maybe I just don't see what you mean?  In general, it is good that we do
*not* do superfluous checks normally.  There is nothing useful we could
say about an out-of-memory situation.

If this was in GCC itself we would get a helpful ICE as-is.  Since this
is in a generator file we can assume whoever debugs this knows how to
fire up GDB for it, so it is fine as well.

There are thousands of ways a developer can crash the generators by
giving bad inputs.  An out-of-memory condition is not likely at all,
compared to that.


Segher


Re: [PATCH] c++: constexpr and copy elision within mem init [PR100368]

2021-05-24 Thread Jason Merrill via Gcc-patches

On 5/24/21 1:48 PM, Patrick Palka wrote:

In the testcase below, the initializer for C::b inside C's default
constructor is encoded as a TARGET_EXPR wrapping the CALL_EXPR f() in
C++17 mode.  During massaging of this constexpr constructor,
build_target_expr_with_type called from bot_manip ends up trying to use
B's implicitly deleted copy constructor rather than preserving the
copy elision.



This patch makes bot_manip use force_target_expr instead of
build_target_expr_with_type so that it copies TARGET_EXPRs in a more
oblivious manner.


Even with that change we should fix build_target_expr_with_type to 
handle CALL_EXPR properly; adding an extra copy is just wrong.



Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK
for trunk?

PR c++/100368

gcc/cp/ChangeLog:

* tree.c (build_target_expr_with_type): Simplify now that
bot_manip is no longer a caller.
(bot_manip): Use force_target_expr instead of
build_target_expr_with_type.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1z/elide6.C: New test.
---
  gcc/cp/tree.c   |  8 +++-
  gcc/testsuite/g++.dg/cpp1z/elide6.C | 16 
  2 files changed, 19 insertions(+), 5 deletions(-)
  create mode 100644 gcc/testsuite/g++.dg/cpp1z/elide6.C

diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 72f498f4b3b..84b84621d35 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -848,12 +848,10 @@ build_target_expr_with_type (tree init, tree type, 
tsubst_flags_t complain)
|| init == error_mark_node)
  return init;
else if (CLASS_TYPE_P (type) && type_has_nontrivial_copy_init (type)
-  && !VOID_TYPE_P (TREE_TYPE (init))
   && TREE_CODE (init) != COND_EXPR
   && TREE_CODE (init) != CONSTRUCTOR
   && TREE_CODE (init) != VA_ARG_EXPR)
-/* We need to build up a copy constructor call.  A void initializer
-   means we're being called from bot_manip.


In general, a void initializer for a TARGET_EXPR means that the 
initialization is more complex than initializing the object from the 
value of the expression.  The caller would need to handle making that 
initialization apply to the new TARGET_EXPR_SLOT (and bot_manip does). 
If we change bot_manip to not call this function, I think this function 
should reject void init.


  COND_EXPR is a special

+/* We need to build up a copy constructor call.  COND_EXPR is a special
 case because we already have copies on the arms and we don't want
 another one here.  A CONSTRUCTOR is aggregate initialization, which
 is handled separately.  A VA_ARG_EXPR is magic creation of an
@@ -3112,8 +3110,8 @@ bot_manip (tree* tp, int* walk_subtrees, void* data_)
AGGR_INIT_ZERO_FIRST (TREE_OPERAND (u, 1)) = true;
}
else
-   u = build_target_expr_with_type (TREE_OPERAND (t, 1), TREE_TYPE (t),
-tf_warning_or_error);
+   u = force_target_expr (TREE_TYPE (t), TREE_OPERAND (t, 1),
+  tf_warning_or_error);
  
TARGET_EXPR_IMPLICIT_P (u) = TARGET_EXPR_IMPLICIT_P (t);

TARGET_EXPR_LIST_INIT_P (u) = TARGET_EXPR_LIST_INIT_P (t);
diff --git a/gcc/testsuite/g++.dg/cpp1z/elide6.C 
b/gcc/testsuite/g++.dg/cpp1z/elide6.C
new file mode 100644
index 000..399e1a9a1ef
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/elide6.C
@@ -0,0 +1,16 @@
+// PR c++/100368
+// { dg-do compile { target c++11 } }
+
+struct A {
+  A() = default;
+  A(const A&) = delete;
+};
+
+struct B { A a; }; // { dg-error "deleted" "" { target c++14_down } }
+
+constexpr B f() { return {}; }
+
+struct C {
+  constexpr C() : b(f()) {} // { dg-error "deleted" "" { target c++14_down } }
+  B b;
+};





https://gcc.gnu.org/onlinedocs/gcc-11.1.0/gfortran/

2021-05-24 Thread Johannes Nendwich via Gcc-patches
Hi folks,

some more suggestions for corrections in the onlinedocs:


https://gcc.gnu.org/onlinedocs/gcc-11.1.0/gfortran/GERROR.html#GERROR

RESULT  "Shall of type CHARACTER and of default"
--> "Shall BE of ... default KIND."


https://gcc.gnu.org/onlinedocs/gcc-11.1.0/gfortran/GETARG.html#GETARG

2 x "VALUE  Shall be of type CHARACTER [...]"


https://gcc.gnu.org/onlinedocs/gcc-11.1.0/gfortran/GETLOG.html#GETLOG

"Stores the current user name in LOGIN."
-->
"Stores the current user name in C."


https://gcc.gnu.org/onlinedocs/gcc-11.1.0/gfortran/NORM2.html#NORM2

"Calculates the Euclidean vector norm (L_2 norm) of of ARRAY along
dimension DIM."

"... of of ..."
-->
"... of ..."


https://gcc.gnu.org/onlinedocs/gcc-11.1.0/gfortran/PARITY.html#PARITY

"LOGICALShall be ..."
-->
"MASK   Shall be ..."


https://gcc.gnu.org/onlinedocs/gcc-11.1.0/gfortran/RANDOM_005fINIT.html#RANDOM_005fINIT

"IMAGE_DISTINCT   ... the seed is set value that does ..."
-->
"IMAGE_DISTINCT   ... the seed is set TO A value that does ..."


https://gcc.gnu.org/onlinedocs/gcc-11.1.0/gfortran/RANDOM_005fNUMBER.html#RANDOM_005fNUMBER

"Syntax: RANDOM_NUMBER(HARVEST)"
-->
"Syntax: CALL RANDOM_NUMBER(HARVEST)"


Greets,
Johannes


Re: [PATCH] add missing GTY support for hash-map (PR 100463)

2021-05-24 Thread Jason Merrill via Gcc-patches

On 5/24/21 12:46 PM, Martin Sebor wrote:

Instantiating a hash_map on a number of integer types including,
for example, int or unsigned int (such as location_t), or
HOST_WIDE_INT, and using it with the garbage collector causes many
cryptic compilation errors due to incomplete support for such types
(the PR shows a few examples).  I ran into these errors as I was
prototyping a new feature and they took me egregiously long to
figure out, even with help from others.

The attached patch adds the missing functions necessary to complete
the support for all integer types to avoid these errors.  This is
prerequisite for a future patch of mine.  The patch uses just one
of these hash_map instances but others shouldn't have to run into
the same errors if they happen to choose one of them.

Tested on x86_64-linux.


OK.

Jason



Re: [PATCH] c++: access for hidden friend of nested class template [PR100502]

2021-05-24 Thread Jason Merrill via Gcc-patches

On 5/21/21 4:35 PM, Patrick Palka wrote:

Here, during ahead of time access checking for the private member
EnumeratorRange::end_reached_ in the hidden friend f, we're triggering
the the assert in enforce_access that verifies we're not trying to add a
dependent access check to TI_DEFERRED_ACCESS_CHECKS.

The special thing about this class member access expression is that it's
considered to be non-type-dependent (so finish_class_member_access_expr
doesn't exit early at template parse time), and then accessible_p
rejects the access (so we don't exit early from enforce access either,
and end up triggering the assert).  I think we're correct to reject it
because a hidden friend is not a member function, so [class.access.nest]
doesn't apply, and also a hidden friend of a nested class is not a
friend of the enclosing class.  (Note that Clang accepts the testcase
and MSVC and ICC reject it.)


Hmm, I think you're right, but that seems inconsistent with the change 
(long ago) to give nested classes access to members of the enclosing class.



This patch relaxes the problematic assert in enforce_access to check
dependent_scope_p instead of uses_template_parms, which is the more
accurate notion of dependence we care about.


Agreed.


This change alone is
sufficient to fix the ICE, but we now end up diagnosing each access
twice, once at substitution time and again from TI_DEFERRED_ACCESS_CHECKS.
So this patch additionally disables ahead of time access checking
during the call to lookup_member from finish_class_member_access_expr;
we're going to check the same access again at substitution time anyway.


That seems undesirable; it's better to diagnose when parsing if we can. 
Why is it going on TI_DEFERRED_ACCESS_CHECKS after we already checked it?



Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
trunk?  For GCC 11, should we just backport the enforce_access hunk?

PR c++/100502

gcc/cp/ChangeLog:

* semantics.c (enforce_access): Relax assert about the type
depedence of the DECL_CONTEXT of the declaration.
* typeck.c (finish_class_member_access_expr): Disable ahead
of time access checking during the member lookup.

gcc/testsuite/ChangeLog:

* g++.dg/template/access37.C: New test.
* g++.dg/template/access37a.C: New test.
---
  gcc/cp/semantics.c|  2 +-
  gcc/cp/typeck.c   |  6 ++
  gcc/testsuite/g++.dg/template/access37.C  | 26 +++
  gcc/testsuite/g++.dg/template/access37a.C |  6 ++
  4 files changed, 39 insertions(+), 1 deletion(-)
  create mode 100644 gcc/testsuite/g++.dg/template/access37.C
  create mode 100644 gcc/testsuite/g++.dg/template/access37a.C

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 0d590c318fb..0de14316bba 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -365,7 +365,7 @@ enforce_access (tree basetype_path, tree decl, tree 
diag_decl,
   check here.  */
gcc_assert (!uses_template_parms (decl));
if (TREE_CODE (decl) == FIELD_DECL)
- gcc_assert (!uses_template_parms (DECL_CONTEXT (decl)));
+ gcc_assert (!dependent_scope_p (DECL_CONTEXT (decl)));
  
  	/* Defer this access check until instantiation time.  */

deferred_access_check access_check;
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 703ddd3cc7a..86cf26b9c84 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -3201,9 +3201,15 @@ finish_class_member_access_expr (cp_expr object, tree 
name, bool template_p,
{
  /* Look up the member.  */
  access_failure_info afi;
+ if (processing_template_decl)
+   /* We're going to redo this member lookup at instantiation
+  time, so don't bother checking access ahead of time here.  */
+   push_deferring_access_checks (dk_no_check);
  member = lookup_member (access_path, name, /*protect=*/1,
  /*want_type=*/false, complain,
  );
+ if (processing_template_decl)
+   pop_deferring_access_checks ();
  afi.maybe_suggest_accessor (TYPE_READONLY (object_type));
  if (member == NULL_TREE)
{
diff --git a/gcc/testsuite/g++.dg/template/access37.C 
b/gcc/testsuite/g++.dg/template/access37.C
new file mode 100644
index 000..92fed3e97cb
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/access37.C
@@ -0,0 +1,26 @@
+// PR c++/100502
+
+template 
+struct EnumeratorRange {
+  struct Iterator {
+EnumeratorRange range_;
+
+friend void f(Iterator i) {
+  i.range_.end_reached_; // { dg-error "private" }
+  i.range_.EnumeratorRange::end_reached_; // { dg-error "private" }
+  _.end_reached_; // { dg-error "private" }
+  _.EnumeratorRange::end_reached_; // { dg-error "private" }
+}
+  };
+
+ private:
+  bool end_reached_;
+#if DECLARE_FRIEND
+  friend void f(Iterator);
+#endif
+};
+
+int main() 

Re: [PATCH] c++: Fix reference NTTP binding to noexcept fn [PR97420]

2021-05-24 Thread Jason Merrill via Gcc-patches

On 5/21/21 4:35 PM, Patrick Palka wrote:

Here, in C++17 mode, convert_nontype_argument_function is rejecting
binding a non-noexcept function reference template parameter to a
noexcept function (encoded as the template argument '*(int (&) (int)) ').

The first roadblock to making this work is that the argument is wrapped
an an implicit INDIRECT_REF, so we need to unwrap it before calling
strip_fnptr_conv.

The second roadblock is that the NOP_EXPR cast converts from a function
pointer type to a reference type while simultaneously removing the
noexcept qualification, and fnptr_conv_p doesn't consider this cast to
be a function pointer conversion.  This patch fixes this by making
fnptr_conv_p treat REFERENCE_TYPEs and POINTER_TYPEs interchangeably.

Finally, in passing, this patch also simplifies noexcept_conv_p by
removing a bunch of redundant checks already performed by its only
caller fnptr_conv_p.

Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
trunk?



gcc/cp/ChangeLog:

PR c++/97420
* cvt.c (noexcept_conv_p): Remove redundant checks and simplify.


This is fine, but please also add a note to its comment that it's just a 
subroutine of fnptr_conv_p.


OK with that change.


(fnptr_conv_p): Don't call non_reference.  Use INDIRECT_TYPE_P
instead of TYPE_PTR_P.
* pt.c (convert_nontype_argument_function): Look through
implicit INDIRECT_REFs before calling strip_fnptr_conv.

gcc/testsuite/ChangeLog:

PR c++/97420
* g++.dg/cpp0x/noexcept68.C: New test.
---
  gcc/cp/cvt.c| 33 +++--
  gcc/cp/pt.c |  5 +++-
  gcc/testsuite/g++.dg/cpp0x/noexcept68.C |  8 ++
  3 files changed, 21 insertions(+), 25 deletions(-)
  create mode 100644 gcc/testsuite/g++.dg/cpp0x/noexcept68.C

diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c
index 7fa6e8df52b..582d03f61f5 100644
--- a/gcc/cp/cvt.c
+++ b/gcc/cp/cvt.c
@@ -2089,30 +2089,15 @@ noexcept_conv_p (tree to, tree from)
if (!flag_noexcept_type)
  return false;
  
-  tree t = non_reference (to);

-  tree f = from;
-  if (TYPE_PTRMEMFUNC_P (t)
-  && TYPE_PTRMEMFUNC_P (f))
-{
-  t = TYPE_PTRMEMFUNC_FN_TYPE (t);
-  f = TYPE_PTRMEMFUNC_FN_TYPE (f);
-}
-  if (TYPE_PTR_P (t)
-  && TYPE_PTR_P (f))
-{
-  t = TREE_TYPE (t);
-  f = TREE_TYPE (f);
-}
-  tree_code code = TREE_CODE (f);
-  if (TREE_CODE (t) != code)
+  if (TREE_CODE (to) != TREE_CODE (from))
  return false;
-  if (code != FUNCTION_TYPE && code != METHOD_TYPE)
+  if (!FUNC_OR_METHOD_TYPE_P (from))
  return false;
-  if (!type_throw_all_p (t)
-  || type_throw_all_p (f))
+  if (!type_throw_all_p (to)
+  || type_throw_all_p (from))
  return false;
-  tree v = build_exception_variant (f, NULL_TREE);
-  return same_type_p (t, v);
+  tree v = build_exception_variant (from, NULL_TREE);
+  return same_type_p (to, v);
  }
  
  /* Return true iff FROM can convert to TO by a function pointer conversion.  */

@@ -2120,7 +2105,7 @@ noexcept_conv_p (tree to, tree from)
  bool
  fnptr_conv_p (tree to, tree from)
  {
-  tree t = non_reference (to);
+  tree t = to;
tree f = from;
if (TYPE_PTRMEMFUNC_P (t)
&& TYPE_PTRMEMFUNC_P (f))
@@ -2128,8 +2113,8 @@ fnptr_conv_p (tree to, tree from)
t = TYPE_PTRMEMFUNC_FN_TYPE (t);
f = TYPE_PTRMEMFUNC_FN_TYPE (f);
  }
-  if (TYPE_PTR_P (t)
-  && TYPE_PTR_P (f))
+  if (INDIRECT_TYPE_P (t)
+  && INDIRECT_TYPE_P (f))
  {
t = TREE_TYPE (t);
f = TREE_TYPE (f);
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 99a9ee5ade2..f3fa9c192ad 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -6622,7 +6622,10 @@ convert_nontype_argument_function (tree type, tree expr,
if (value_dependent_expression_p (fn))
  goto accept;
  
-  fn_no_ptr = strip_fnptr_conv (fn);

+  fn_no_ptr = fn;
+  if (REFERENCE_REF_P (fn_no_ptr))
+fn_no_ptr = TREE_OPERAND (fn_no_ptr, 0);
+  fn_no_ptr = strip_fnptr_conv (fn_no_ptr);
if (TREE_CODE (fn_no_ptr) == ADDR_EXPR)
  fn_no_ptr = TREE_OPERAND (fn_no_ptr, 0);
if (BASELINK_P (fn_no_ptr))
diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept68.C 
b/gcc/testsuite/g++.dg/cpp0x/noexcept68.C
new file mode 100644
index 000..086899a4a19
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/noexcept68.C
@@ -0,0 +1,8 @@
+// PR c++/97420
+// { dg-do compile { target c++11 } }
+
+int f(int) noexcept;
+template void A();
+int main() {
+  A();
+}





Go patch committed: Mark global variables TREE_ADDRESSABLE

2021-05-24 Thread Ian Lance Taylor via Gcc-patches
This patch to the Go frontend marks global variables whose address is
taken.  To implement this, change the backend to use flag bits for
variables.  This fixes GCC PR 100537.  Bootstrapped and ran Go
testsuite on x86_64-pc-linux-gnu.  Committed to mainline.

Ian

PR go/100537
* go-gcc.cc (class Gcc_backend): Update methods that create
variables to take a flags parameter.
18c7d35682baa62e1c3bee22a909d3e95ab08a12
diff --git a/gcc/go/go-gcc.cc b/gcc/go/go-gcc.cc
index 5d9dbb5d068..41f309e7294 100644
--- a/gcc/go/go-gcc.cc
+++ b/gcc/go/go-gcc.cc
@@ -415,47 +415,46 @@ class Gcc_backend : public Backend
   global_variable(const std::string& var_name,
  const std::string& asm_name,
  Btype* btype,
- bool is_external,
- bool is_hidden,
- bool in_unique_section,
+ unsigned int flags,
  Location location);
 
   void
   global_variable_set_init(Bvariable*, Bexpression*);
 
   Bvariable*
-  local_variable(Bfunction*, const std::string&, Btype*, Bvariable*, bool,
-Location);
+  local_variable(Bfunction*, const std::string&, Btype*, Bvariable*,
+unsigned int, Location);
 
   Bvariable*
-  parameter_variable(Bfunction*, const std::string&, Btype*, bool,
+  parameter_variable(Bfunction*, const std::string&, Btype*, unsigned int,
 Location);
 
   Bvariable*
-  static_chain_variable(Bfunction*, const std::string&, Btype*, Location);
+  static_chain_variable(Bfunction*, const std::string&, Btype*, unsigned int,
+   Location);
 
   Bvariable*
-  temporary_variable(Bfunction*, Bblock*, Btype*, Bexpression*, bool,
+  temporary_variable(Bfunction*, Bblock*, Btype*, Bexpression*, unsigned int,
 Location, Bstatement**);
 
   Bvariable*
   implicit_variable(const std::string&, const std::string&, Btype*,
-bool, bool, bool, int64_t);
+unsigned int, int64_t);
 
   void
   implicit_variable_set_init(Bvariable*, const std::string&, Btype*,
-bool, bool, bool, Bexpression*);
+unsigned int, Bexpression*);
 
   Bvariable*
   implicit_variable_reference(const std::string&, const std::string&, Btype*);
 
   Bvariable*
   immutable_struct(const std::string&, const std::string&,
-   bool, bool, Btype*, Location);
+   unsigned int, Btype*, Location);
 
   void
-  immutable_struct_set_init(Bvariable*, const std::string&, bool, bool, Btype*,
-   Location, Bexpression*);
+  immutable_struct_set_init(Bvariable*, const std::string&, unsigned int,
+   Btype*, Location, Bexpression*);
 
   Bvariable*
   immutable_struct_reference(const std::string&, const std::string&,
@@ -2696,9 +2695,7 @@ Bvariable*
 Gcc_backend::global_variable(const std::string& var_name,
 const std::string& asm_name,
 Btype* btype,
-bool is_external,
-bool is_hidden,
-bool in_unique_section,
+unsigned int flags,
 Location location)
 {
   tree type_tree = btype->get_tree();
@@ -2707,30 +2704,49 @@ Gcc_backend::global_variable(const std::string& 
var_name,
 
   // The GNU linker does not like dynamic variables with zero size.
   tree orig_type_tree = type_tree;
+  bool is_external = (flags & variable_is_external) != 0;
+  bool is_hidden = (flags & variable_is_hidden) != 0;
   if ((is_external || !is_hidden) && int_size_in_bytes(type_tree) == 0)
 type_tree = this->non_zero_size_type(type_tree);
 
   tree decl = build_decl(location.gcc_location(), VAR_DECL,
 get_identifier_from_string(var_name),
 type_tree);
-  if (is_external)
-DECL_EXTERNAL(decl) = 1;
-  else
-TREE_STATIC(decl) = 1;
-  if (!is_hidden)
+  if ((flags & variable_is_external) != 0)
 {
-  TREE_PUBLIC(decl) = 1;
-  SET_DECL_ASSEMBLER_NAME(decl, get_identifier_from_string(asm_name));
+  DECL_EXTERNAL(decl) = 1;
+  flags &=~ variable_is_external;
 }
   else
+TREE_STATIC(decl) = 1;
+
+  if ((flags & variable_is_hidden) == 0)
+TREE_PUBLIC(decl) = 1;
+  else
+flags &=~ variable_is_hidden;
+
+  if ((flags & variable_address_is_taken) != 0)
 {
-  SET_DECL_ASSEMBLER_NAME(decl, get_identifier_from_string(asm_name));
+  TREE_ADDRESSABLE(decl) = 1;
+  flags &=~ variable_address_is_taken;
 }
 
+  // We take the address in Bvariable::get_tree if orig_type_tree is
+  // different from type_tree.
+  if (orig_type_tree != type_tree)
+TREE_ADDRESSABLE(decl) = 1;
+
+  SET_DECL_ASSEMBLER_NAME(decl, get_identifier_from_string(asm_name));
+
   TREE_USED(decl) = 1;
 
-  if (in_unique_section)
-resolve_unique_section (decl, 0, 1);
+ 

Re: [PATCH] Pass the number of bytes to push to PUSH_ARGS

2021-05-24 Thread Joseph Myers
On Sat, 22 May 2021, H.J. Lu via Gcc-patches wrote:

> 1. Update PUSH_ARGS to accept an argument.  When the PUSH instruction
> usage is optional, pass the number of bytes to push to PUSH_ARGS so that
> the backend can decide if PUSH instructions should be generated.
> 2. Change x86 PUSH_ARGS to return 0 when number of bytes to push is more
> than a word to avoid generating non-existent PUSH instructions.
> 3. Remove target PUSH_ARGS definitions which return 0 as it is the same
> as the default.

If you're changing all users and definitions of PUSH_ARGS anyway, it 
probably makes sense to change it to a target hook.

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


Re: [PATCH][DOCS] Remove install-old.texi

2021-05-24 Thread Joseph Myers
On Fri, 21 May 2021, Martin Liška wrote:

> CPUs:
> aarch64, alpha, alpha64, amdgcn, arc, arceb, arm, avr, bfin, bpf, cr16, cris,
> csky, epiphany, fido, fr30, frv, ft32, h8300, hppa, hppa2.0, hppa64, i486,
> i686, ia64, iq2000, lm32, m32c, m32r, m32rle, m68k, mcore, microblaze, mips,
> mips64, mips64el, mips64octeon, mips64orion, mips64vr, mipsel, mipsisa32,
> mipsisa32r2, mipsisa64, mipsisa64r2, mipsisa64r2el, mipsisa64sb1,
> mipsisa64sr71k, mipstx39, mmix, mn10300, moxie, msp430, nds32be, nds32le,
> nios2, nvptx, or1k, pdp11, powerpc, powerpc64, powerpcle, pru, riscv32,
> riscv64, rl78, rx, s390, s390x, sh, shle, sparc, sparc64, tic6x, tilegx,
> tilegxbe, tilepro, v850, v850e, v850e1, vax, visium, x86_64, xstormy16, xtensa

I think it makes sense to include some other variants in this list that 
are matched by config.gcc to control something about how the compiler is 
configured.  That includes at least some endian control variants (in 
addition to those you already have): aarch64_be, armeb, microblazeel, 
riscv32be, riscv64be.  powerpc64le is also an important powerpc variant.

> aix7.1, aix7.2, amdhsa, aout, cygwin, darwin, darwin10, darwin7, darwin8,
> darwin9, eabi, eabialtivec, eabisim, eabisimaltivec, elf, elf32, elfbare,
> elfoabi, freebsd4, freebsd6, gnu, hpux, hpux10.1, hpux11.0, hpux11.3,
> hpux11.9, kfreebsd-gnu, kopensolaris-gnu, linux-androideabi, linux-gnu,
> linux-gnu_altivec, linux-musl, linux-uclibc, lynxos, mingw32, mingw32crt,
> mmixware, msdosdjgpp, netbsd, netbsdelf, netbsdelf9, nto-qnx, openbsd, rtems,
> solaris2.11, symbianelf, tpf, uclinux, uclinux_eabi, vms, vxworks, vxworksae,
> vxworksmils

Where an OS version is included here (aix, darwin, freebsd, hpux, 
netbsdelf, solaris), I think it's better to say @var{version}, to indicate 
for which OSes such a version number is meaningful, than to list specific 
version numbers.

linux-gnueabi and linux-gnueabihf (for Arm) are appropriate to list here.

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


Re: [PATCH,rs6000 2/2] Fusion patterns for add-logical/logical-add

2021-05-24 Thread Aaron Sawdey via Gcc-patches
One last addendum to this. I discovered that that needs a "sort" 
in front of "keys %logicals_addsub" because otherwise you may get
the operators in different orders sometimes which leads to fusion.md
having the patterns in different orders which isn't helpful for
sane debugging. Segher and I discussed it offline so I'm posting 
the final patch for posterity.

Also coming will be some updates to the test cases. Things optimize
differently with -m32 apparently so I'll have to add different counts
of the counts of the different fusion patterns for "{ target ilp32 }"
as the current counts in those files only apply to "{ target lp64 }".

  Aaron

gcc/ChangeLog:
* config/rs6000/genfusion.pl (gen_logical_addsubf): Refactor to
add generation of logical-add and add-logical fusion pairs.
* config/rs6000/rs6000-cpus.def: Add new fusion to ISA 3.1 mask
and powerpc mask.
* config/rs6000/rs6000.c (rs6000_option_override_internal): Turn on
logical-add and add-logical fusion by default.
* config/rs6000.opt: Add -mpower10-fusion-logical-add and
-mpower10-fusion-add-logical options.
* config/rs6000/fusion.md: Regenerate file.

gcc/testsuite/ChangeLog:
* gcc.target/powerpc/fusion-p10-logadd.c: New file.
---
 gcc/config/rs6000/fusion.md   | 872 +-
 gcc/config/rs6000/genfusion.pl|  83 +-
 gcc/config/rs6000/rs6000-cpus.def |   4 +
 gcc/config/rs6000/rs6000.c|   8 +
 gcc/config/rs6000/rs6000.opt  |  12 +-
 .../gcc.target/powerpc/fusion-p10-logadd.c|  97 ++
 6 files changed, 797 insertions(+), 279 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/powerpc/fusion-p10-logadd.c

diff --git a/gcc/config/rs6000/fusion.md b/gcc/config/rs6000/fusion.md
index 4d810e6ba13..51912106663 100644
--- a/gcc/config/rs6000/fusion.md
+++ b/gcc/config/rs6000/fusion.md
@@ -355,11 +355,11 @@ (define_insn_and_split "*lbz_cmpldi_cr0_QI_GPR_CCUNS_zero"
(set_attr "length" "8")])
 
 
-;; logical-logical fusion pattern generated by gen_2logical
+;; logical-logical fusion pattern generated by gen_logical_addsubf
 ;; scalar and -> and
 (define_insn "*fuse_and_and"
   [(set (match_operand:GPR 3 "gpc_reg_operand" "=0,1,,r")
-(and:GPR (and:GPR (match_operand:GPR 0 "gpc_reg_operand" "r,r,r,r") 
+(and:GPR (and:GPR (match_operand:GPR 0 "gpc_reg_operand" "r,r,r,r")
   (match_operand:GPR 1 "gpc_reg_operand" "%r,r,r,r"))
  (match_operand:GPR 2 "gpc_reg_operand" "r,r,r,r")))
(clobber (match_scratch:GPR 4 "=X,X,X,"))]
@@ -373,11 +373,11 @@ (define_insn "*fuse_and_and"
(set_attr "cost" "6")
(set_attr "length" "8")])
 
-;; logical-logical fusion pattern generated by gen_2logical
+;; logical-logical fusion pattern generated by gen_logical_addsubf
 ;; scalar andc -> and
 (define_insn "*fuse_andc_and"
   [(set (match_operand:GPR 3 "gpc_reg_operand" "=0,1,,r")
-(and:GPR (and:GPR (not:GPR (match_operand:GPR 0 "gpc_reg_operand" 
"r,r,r,r")) 
+(and:GPR (and:GPR (not:GPR (match_operand:GPR 0 "gpc_reg_operand" 
"r,r,r,r"))
   (match_operand:GPR 1 "gpc_reg_operand" "r,r,r,r"))
  (match_operand:GPR 2 "gpc_reg_operand" "r,r,r,r")))
(clobber (match_scratch:GPR 4 "=X,X,X,"))]
@@ -391,11 +391,11 @@ (define_insn "*fuse_andc_and"
(set_attr "cost" "6")
(set_attr "length" "8")])
 
-;; logical-logical fusion pattern generated by gen_2logical
+;; logical-logical fusion pattern generated by gen_logical_addsubf
 ;; scalar eqv -> and
 (define_insn "*fuse_eqv_and"
   [(set (match_operand:GPR 3 "gpc_reg_operand" "=0,1,,r")
-(and:GPR (not:GPR (xor:GPR (match_operand:GPR 0 "gpc_reg_operand" 
"r,r,r,r") 
+(and:GPR (not:GPR (xor:GPR (match_operand:GPR 0 "gpc_reg_operand" 
"r,r,r,r")
   (match_operand:GPR 1 "gpc_reg_operand" "r,r,r,r")))
  (match_operand:GPR 2 "gpc_reg_operand" "r,r,r,r")))
(clobber (match_scratch:GPR 4 "=X,X,X,"))]
@@ -409,11 +409,11 @@ (define_insn "*fuse_eqv_and"
(set_attr "cost" "6")
(set_attr "length" "8")])
 
-;; logical-logical fusion pattern generated by gen_2logical
+;; logical-logical fusion pattern generated by gen_logical_addsubf
 ;; scalar nand -> and
 (define_insn "*fuse_nand_and"
   [(set (match_operand:GPR 3 "gpc_reg_operand" "=0,1,,r")
-(and:GPR (ior:GPR (not:GPR (match_operand:GPR 0 "gpc_reg_operand" 
"r,r,r,r")) 
+(and:GPR (ior:GPR (not:GPR (match_operand:GPR 0 "gpc_reg_operand" 
"r,r,r,r"))
   (not:GPR (match_operand:GPR 1 "gpc_reg_operand" 
"r,r,r,r")))
  (match_operand:GPR 2 "gpc_reg_operand" "r,r,r,r")))
(clobber (match_scratch:GPR 4 "=X,X,X,"))]
@@ -427,11 +427,11 @@ (define_insn "*fuse_nand_and"
(set_attr "cost" "6")
(set_attr "length" "8")])
 
-;; logical-logical fusion pattern generated by gen_2logical

[PUSHED] VARYING ranges of different sizes should not be equal.

2021-05-24 Thread Aldy Hernandez via Gcc-patches
VARYING ranges are just normal ranges that span the entire domain.  Such
ranges have had end-points for a few releases now, and the fact that the
legacy code was still treating all VR_VARYING the same was an oversight.

This patch fixes the oversight to match the multi-range behavior.

Tested on x86-64 Linux.

gcc/ChangeLog:

* value-range.cc (irange::legacy_equal_p): Check type when
comparing VR_VARYING types.
(range_tests_legacy): Test comparing VARYING ranges of different
sizes.
---
 gcc/value-range.cc | 13 -
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/gcc/value-range.cc b/gcc/value-range.cc
index 865344fcc3e..8d7b46c0239 100644
--- a/gcc/value-range.cc
+++ b/gcc/value-range.cc
@@ -28,6 +28,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "ssa.h"
 #include "tree-pretty-print.h"
 #include "fold-const.h"
+#include "gimple-range.h"
 
 // Here we copy between any two irange's.  The ranges can be legacy or
 // multi-ranges, and copying between any combination works correctly.
@@ -454,8 +455,10 @@ irange::legacy_equal_p (const irange ) const
 
   if (m_kind != other.m_kind)
return false;
-  if (m_kind == VR_UNDEFINED || m_kind == VR_VARYING)
+  if (m_kind == VR_UNDEFINED)
 return true;
+  if (m_kind == VR_VARYING)
+return range_compatible_p (type (), other.type ());
   return (vrp_operand_equal_p (tree_lower_bound (0),
   other.tree_lower_bound (0))
  && vrp_operand_equal_p (tree_upper_bound (0),
@@ -2245,6 +2248,14 @@ range_tests_legacy ()
 copy = legacy_range;
 ASSERT_TRUE (copy.varying_p ());
   }
+
+  // VARYING of different sizes should not be equal.
+  int_range_max r0 (integer_type_node);
+  int_range_max r1 (short_integer_type_node);
+  ASSERT_TRUE (r0 != r1);
+  value_range vr0 (integer_type_node);
+  int_range_max vr1 (short_integer_type_node);
+  ASSERT_TRUE (vr0 != vr1);
 }
 
 // Simulate -fstrict-enums where the domain of a type is less than the
-- 
2.31.1



Re: [PATCH 4/5] Convert remaining passes to RANGE_QUERY.

2021-05-24 Thread Martin Sebor via Gcc-patches

On 5/21/21 5:39 AM, Aldy Hernandez via Gcc-patches wrote:

This patch converts the remaining users of get_range_info and
get_ptr_nonnull to the range_query API.

No effort was made to move passes away from VR_ANTI_RANGE, or any other
use of deprecated methods.  This was a straight up conversion to the new
API, nothing else.


A question about the uses of the RANGE_QUERY() and GLOBAL_RANGE_QUERY()
macros (hopefully functions): some clients in this patch call one or
the other based on whether cfun is set or null, while others call it
without such testing.  That suggests that the former clients might
be making the assumption that cfun is null while the latter ones
make the opposite assumption that cfun is not null.  It seems that
the code would be safer/more future-proof if it avoided making
these assumptions.

That could be done by introducing a function like this one:

  range_query&
  get_range_query (const function *func = cfun)
  {
if (func)
  return func->x_range_query;
return *get_global_range_query ();
  }

This function would be easier to use since clients wouldn't have
to worry about when cfun is null.

Since all clients assume the result is nonnull the function returns
a reference rather a pointer.  (That's presumably also true for
get_global_range_query()).

Martin



Tested on x86-64 Linux.

OK?

gcc/ChangeLog:

* builtins.c (check_nul_terminated_array): Convert to RANGE_QUERY.
(expand_builtin_strnlen): Same.
(determine_block_size): Same.
* fold-const.c (expr_not_equal_to): Same.
* gimple-fold.c (size_must_be_zero_p): Same.
* gimple-match-head.c: Include gimple-range.h.
* gimple-pretty-print.c (dump_ssaname_info): Convert to RANGE_QUERY.
* gimple-ssa-warn-restrict.c
(builtin_memref::extend_offset_range): Same.
* graphite-sese-to-poly.c (add_param_constraints): Same.
* internal-fn.c (get_min_precision): Same.
* ipa-fnsummary.c (set_switch_stmt_execution_predicate): Same.
* ipa-prop.c (ipa_compute_jump_functions_for_edge): Same.
* match.pd: Same.
* tree-data-ref.c (split_constant_offset): Same.
(dr_step_indicator): Same.
* tree-dfa.c (get_ref_base_and_extent): Same.
* tree-scalar-evolution.c (iv_can_overflow_p): Same.
* tree-ssa-loop-niter.c (refine_value_range_using_guard): Same.
(determine_value_range): Same.
(record_nonwrapping_iv): Same.
(infer_loop_bounds_from_signedness): Same.
(scev_var_range_cant_overflow): Same.
* tree-ssa-phiopt.c (two_value_replacement): Same.
* tree-ssa-pre.c (insert_into_preds_of_block): Same.
* tree-ssa-reassoc.c (optimize_range_tests_to_bit_test): Same.
* tree-ssa-strlen.c (handle_builtin_stxncpy_strncat): Same.
(get_range): Same.
(dump_strlen_info): Same.
(set_strlen_range): Same.
(maybe_diag_stxncpy_trunc): Same.
(get_len_or_size): Same.
(handle_integral_assign): Same.
* tree-ssa-structalias.c (find_what_p_points_to): Same.
* tree-ssa-uninit.c (find_var_cmp_const): Same.
* tree-switch-conversion.c (bit_test_cluster::emit): Same.
* tree-vect-patterns.c (vect_get_range_info): Same.
(vect_recog_divmod_pattern): Same.
* tree-vrp.c (intersect_range_with_nonzero_bits): Same.
(register_edge_assert_for_2): Same.
(determine_value_range_1): Same.
* tree.c (get_range_pos_neg): Same.
* vr-values.c (vr_values::get_lattice_entry): Same.
(vr_values::update_value_range): Same.
(simplify_conversion_using_ranges): Same.
---
  gcc/builtins.c | 40 ++--
  gcc/fold-const.c   |  8 +++-
  gcc/gimple-fold.c  |  7 ++-
  gcc/gimple-match-head.c|  1 +
  gcc/gimple-pretty-print.c  | 12 -
  gcc/gimple-ssa-warn-restrict.c |  8 +++-
  gcc/graphite-sese-to-poly.c|  9 +++-
  gcc/internal-fn.c  | 14 +++---
  gcc/ipa-fnsummary.c| 11 -
  gcc/ipa-prop.c | 16 +++
  gcc/match.pd   | 19 ++--
  gcc/tree-data-ref.c| 24 --
  gcc/tree-dfa.c | 14 +-
  gcc/tree-scalar-evolution.c| 13 +-
  gcc/tree-ssa-loop-niter.c  | 81 +---
  gcc/tree-ssa-phiopt.c  | 11 -
  gcc/tree-ssa-pre.c | 19 
  gcc/tree-ssa-reassoc.c |  9 ++--
  gcc/tree-ssa-strlen.c  | 85 --
  gcc/tree-ssa-structalias.c |  8 ++--
  gcc/tree-ssa-uninit.c  |  8 +++-
  gcc/tree-switch-conversion.c   | 10 ++--
  gcc/tree-vect-patterns.c   | 18 +--
  gcc/tree-vrp.c | 21 -
  gcc/tree.c | 13 +++---
  gcc/vr-values.c| 12 +++--
  26 files changed, 332 insertions(+), 159 deletions(-)

diff --git a/gcc/builtins.c 

Re: [PATCH 1/5] Common API for accessing global and on-demand ranges.

2021-05-24 Thread Martin Sebor via Gcc-patches

On 5/21/21 5:39 AM, Aldy Hernandez via Gcc-patches wrote:

This patch provides a generic API for accessing global ranges.  It is
meant to replace get_range_info() and get_ptr_nonnull() with one
common interface.  It uses the same API as the ranger (class
range_query), so there will now be one API for accessing local and
global ranges alike.

Follow-up patches will convert all users of get_range_info and
get_ptr_nonnull to this API.

For get_range_info, instead of:

   if (!POINTER_TYPE_P (TREE_TYPE (name)) && SSA_NAME_RANGE_INFO (name))
 get_range_info (name, vr);

You can now do:

   RANGE_QUERY (cfun)->range_of_expr (vr, name, [stmt]);

...as well as any other of the range_query methods (range_on_edge,
range_of_stmt, value_of_expr, value_on_edge, value_on_stmt, etc).

As per the API, range_of_expr will work on constants, SSA names, and
anything we support in irange::supports_type_p().

For pointers, the interface is the same, so instead of:

   else if (POINTER_TYPE_P (TREE_TYPE (name)) && SSA_NAME_PTR_INFO (name))
 {
   if (get_ptr_nonnull (name))
 stuff();
 }

One can do:

   RANGE_QUERY (cfun)->range_of_expr (vr, name, [stmt]);
   if (vr.nonzero_p ())
 stuff ();

Along with this interface, we are providing a mechanism by which a
pass can use an on-demand ranger transparently, without having to
change its code.  Of course, this assumes all get_range_info() and
get_ptr_nonnull() users have been converted to the new API, which
follow-up patches will do.

If a pass would prefer to use an on-demand ranger with finer grained
and context aware ranges, all it would have to do is call
enable_ranger() at the beginning of the pass, and disable_ranger() at
the end of the pass.

Note, that to use context aware ranges, any user of range_of_expr()
would need to pass additional context.  For example, the optional
gimple statement (or perhaps use range_on_edge or range_of_stmt).

The observant reader will note that RANGE_QUERY is tied to cfun, which
may not be available in certain contexts, such as at RTL time,
gimple-fold, or some other places where we may or may not have cfun
set.

For cases where we are sure there is no cfun, you can use
GLOBAL_RANGE_QUERY instead of RANGE_QUERY(cfun).  The API is the same.

For cases where a function may be called with or without a function,
you could use the following idiom:

   range_query *query = cfun ? RANGE_QUERY (cfun) : GLOBAL_RANGE_QUERY;

   query->range_of_expr (range, expr, [stmt]);

By default RANGE_QUERY uses GLOBAL_RANGE_QUERY, unless the user has
enabled an on-demand ranger with enable_ranger(), in which case it
will use the currently active ranger.  That is, until disable_ranger()
is called, at which point, we revert back to GLOBAL_RANGE_QUERY.

We think this provides a generic way of accessing ranges, both
globally and locally, without having to keep track of types,
SSA_NAME_RANGE_INFO, and SSA_NAME_PTR_INFO.  We also hope this can be
used to transition passes from global to on-demand ranges when
appropriate.


Thanks for the heads up!  This sounds great (and thanks for all
the work converting the existing uses).  Just a few comments on
the changes.



Tested on x86-64 Linux.

OK?

gcc/ChangeLog:

* function.c (allocate_struct_function): Set cfun->x_range_query.
* function.h (struct function): Declare x_range_query.
(RANGE_QUERY): New.
(get_global_range_query): New.
(GLOBAL_RANGE_QUERY): New.
* gimple-range-cache.cc (ssa_global_cache::ssa_global_cache):
Remove call to safe_grow_cleared.
* gimple-range.cc (get_range_global): New.
(gimple_range_global): Move from gimple-range.h.
(get_global_range_query): New.
(global_range_query::range_of_expr): New.
(enable_ranger): New.
(disable_ranger): New.
* gimple-range.h (gimple_range_global): Move to gimple-range.cc.
(class global_range_query): New.
(enable_ranger): New.
(disable_ranger): New.
* gimple-ssa-evrp.c (evrp_folder::~evrp_folder): Rename
dump_all_value_ranges to dump.
* tree-vrp.c (vrp_prop::finalize): Same.
* value-query.cc (range_query::dump): New.
* value-query.h (range_query::dump): New.
* vr-values.c (vr_values::dump_all_value_ranges): Rename to...
(vr_values::dump): ...this.
* vr-values.h (class vr_values): Rename dump_all_value_ranges to
dump and make virtual.
---
  gcc/function.c|   4 ++
  gcc/function.h|  16 +
  gcc/gimple-range-cache.cc |   1 -
  gcc/gimple-range.cc   | 130 ++
  gcc/gimple-range.h|  60 +-
  gcc/gimple-ssa-evrp.c |   2 +-
  gcc/tree-vrp.c|   2 +-
  gcc/value-query.cc|   5 ++
  gcc/value-query.h |   1 +
  gcc/vr-values.c   |   2 +-
  gcc/vr-values.h   |   2 +-
  11 files changed, 175 insertions(+), 50 deletions(-)


Re: [PATCH] libstdc++: Fix iterator caching inside range adaptors [PR100479]

2021-05-24 Thread Jonathan Wakely via Gcc-patches

On 18/05/21 00:53 -0400, Patrick Palka via Libstdc++ wrote:

On Mon, 17 May 2021, Tim Song wrote:


On Mon, May 17, 2021 at 2:59 PM Patrick Palka  wrote:
>
> +   constexpr _CachedPosition&
> +   operator=(_CachedPosition&& __other) noexcept
> +   {
> + if (std::__addressof(__other) != this)

I don't think we need this check - self-move-assigning the underlying
view isn't required to be a no-op, so we should still invalidate.


Sounds good, so like so:


Looks good to me (but then so did the previous one ;-)

Please push, as this is an improvement on what's on trunk now. If Tim
spots any more problems they can be fixed later.


Thanks both of you.



[committed] libstdc++: Qualify functions used in tests

2021-05-24 Thread Jonathan Wakely via Gcc-patches
These tests rely on ADL for some functions, probably unintentionally.
The calls only work because the iterator wrappers derive from
std::iterator and so namespace std is an associated namespace.

libstdc++-v3/ChangeLog:

* testsuite/25_algorithms/inplace_merge/constrained.cc: Qualify
call to ranges::next.
* testsuite/25_algorithms/is_sorted/constrained.cc: Likewise.
* testsuite/25_algorithms/is_sorted_until/constrained.cc:
Likewise.
* testsuite/25_algorithms/swap_ranges/1.cc: Qualify call to
swap_ranges.

Tested powerpc64le-linux. Committed to trunk.

commit 6fdc59f196c3e1b4aeeb8a0407d4eb40645c5251
Author: Jonathan Wakely 
Date:   Mon May 24 18:42:09 2021

libstdc++: Qualify functions used in tests

These tests rely on ADL for some functions, probably unintentionally.
The calls only work because the iterator wrappers derive from
std::iterator and so namespace std is an associated namespace.

libstdc++-v3/ChangeLog:

* testsuite/25_algorithms/inplace_merge/constrained.cc: Qualify
call to ranges::next.
* testsuite/25_algorithms/is_sorted/constrained.cc: Likewise.
* testsuite/25_algorithms/is_sorted_until/constrained.cc:
Likewise.
* testsuite/25_algorithms/swap_ranges/1.cc: Qualify call to
swap_ranges.

diff --git a/libstdc++-v3/testsuite/25_algorithms/inplace_merge/constrained.cc 
b/libstdc++-v3/testsuite/25_algorithms/inplace_merge/constrained.cc
index e1f59bf86b5..2f3d5d6955a 100644
--- a/libstdc++-v3/testsuite/25_algorithms/inplace_merge/constrained.cc
+++ b/libstdc++-v3/testsuite/25_algorithms/inplace_merge/constrained.cc
@@ -41,7 +41,7 @@ test01()
ranges::sort(v);
 
test_range rz(v.data(), 
v.data()+i+j);
-   auto result = ranges::inplace_merge(rz, next(ranges::begin(rz), i));
+   auto result = ranges::inplace_merge(rz, ranges::next(ranges::begin(rz), 
i));
VERIFY( result == rz.end() );
 
VERIFY( ranges::is_sorted(rz) );
diff --git a/libstdc++-v3/testsuite/25_algorithms/is_sorted/constrained.cc 
b/libstdc++-v3/testsuite/25_algorithms/is_sorted/constrained.cc
index c3764846090..92440bb7bd7 100644
--- a/libstdc++-v3/testsuite/25_algorithms/is_sorted/constrained.cc
+++ b/libstdc++-v3/testsuite/25_algorithms/is_sorted/constrained.cc
@@ -46,7 +46,7 @@ test02()
   test_range rx(x);
   VERIFY( ranges::is_sorted(rx) );
   VERIFY( !ranges::is_sorted(ranges::begin(rx),
-next(ranges::begin(rx), 2),
+ranges::next(ranges::begin(rx), 2),
 ranges::greater{}) );
 }
 
diff --git 
a/libstdc++-v3/testsuite/25_algorithms/is_sorted_until/constrained.cc 
b/libstdc++-v3/testsuite/25_algorithms/is_sorted_until/constrained.cc
index 9d23ebc81fe..bc323348313 100644
--- a/libstdc++-v3/testsuite/25_algorithms/is_sorted_until/constrained.cc
+++ b/libstdc++-v3/testsuite/25_algorithms/is_sorted_until/constrained.cc
@@ -50,9 +50,9 @@ test02()
   test_range rx(x);
   VERIFY( ranges::is_sorted_until(rx) == ranges::end(rx) );
   VERIFY( ranges::is_sorted_until(ranges::begin(rx),
- next(ranges::begin(rx), 2),
+ ranges::next(ranges::begin(rx), 2),
  ranges::greater{})
- == next(ranges::begin(rx), 1) );
+ == ranges::next(ranges::begin(rx), 1) );
 }
 
 constexpr bool
diff --git a/libstdc++-v3/testsuite/25_algorithms/swap_ranges/1.cc 
b/libstdc++-v3/testsuite/25_algorithms/swap_ranges/1.cc
index 31eee31cd6d..4660199af50 100644
--- a/libstdc++-v3/testsuite/25_algorithms/swap_ranges/1.cc
+++ b/libstdc++-v3/testsuite/25_algorithms/swap_ranges/1.cc
@@ -24,7 +24,7 @@
 using __gnu_test::test_container;
 using __gnu_test::forward_iterator_wrapper;
 
-typedef test_container Container; 
+typedef test_container Container;
 
 
 void
@@ -46,10 +46,10 @@ test2()
   int array2[] = {1};
   Container con1(array1, array1);
   Container con2(array2, array2);
-  VERIFY(swap_ranges(con1.begin(), con1.end(), con2.begin()).ptr == array2);
+  VERIFY(std::swap_ranges(con1.begin(), con1.end(), con2.begin()).ptr == 
array2);
 }
 
-int 
+int
 main()
 {
   test1();


Re: [GOVERNANCE] Where to file complaints re project-maintainers?

2021-05-24 Thread abebeos via Gcc-patches
Please, get serious.

=> this topic is closed for me, so STOP CC''ing ME, it is not welcome.


On Sun, 23 May 2021 at 19:03, Mike Stump  wrote:

> This isn't a patch to gcc, please stop posting non-technical content to
> this list.  Please review what this list is for and the rules for this list
> before you post again, thanks.
>
> > On May 14, 2021, at 7:47 AM, abebeos via Gcc-patches <
> gcc-patches@gcc.gnu.org> wrote:
> >
> > Hi there IT-fascists, clowns, master-clowns,
> > totally-confused-incompetent-code-plumbers,
> > activity-trapped-silent-high-performers,
> > stay-out-of-trouble-silent-high-performers! (Guess where G.J. Lay fits in
> > the collection...).
> >
> > Please be aware that I do not read any messages here (including the one
> I'm
> > replying to), in this unregulated circus-show ("The GCC Project"). I've
> > polluted my mind enough with your nonsense justifications, to be honest
> it
> > is becoming quite disgusting.
> >
> > If any serious person from the FSF (as to my tiny research, the FSF is in
> > the end legally and ethically responsible for what happens on GCC) want
> to
> > comment on this, please send me additionally a copy of your message.
> >
> > FSF:
> >
> > Copyright: https://www.fsf.org/about/dmca-notice
> > Privacy:
> https://www.fsf.org/about/free-software-foundation-privacy-policy
> > IT-fascists, Bullying, discrimination, workers-abuse, rigged voting
> > processes: ???
>


[PATCH] c++: constexpr and copy elision within mem init [PR100368]

2021-05-24 Thread Patrick Palka via Gcc-patches
In the testcase below, the initializer for C::b inside C's default
constructor is encoded as a TARGET_EXPR wrapping the CALL_EXPR f() in
C++17 mode.  During massaging of this constexpr constructor,
build_target_expr_with_type called from bot_manip ends up trying to use
B's implicitly deleted copy constructor rather than preserving the
copy elision.

This patch makes bot_manip use force_target_expr instead of
build_target_expr_with_type so that it copies TARGET_EXPRs in a more
oblivious manner.

Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK
for trunk?

PR c++/100368

gcc/cp/ChangeLog:

* tree.c (build_target_expr_with_type): Simplify now that
bot_manip is no longer a caller.
(bot_manip): Use force_target_expr instead of
build_target_expr_with_type.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1z/elide6.C: New test.
---
 gcc/cp/tree.c   |  8 +++-
 gcc/testsuite/g++.dg/cpp1z/elide6.C | 16 
 2 files changed, 19 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp1z/elide6.C

diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 72f498f4b3b..84b84621d35 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -848,12 +848,10 @@ build_target_expr_with_type (tree init, tree type, 
tsubst_flags_t complain)
   || init == error_mark_node)
 return init;
   else if (CLASS_TYPE_P (type) && type_has_nontrivial_copy_init (type)
-  && !VOID_TYPE_P (TREE_TYPE (init))
   && TREE_CODE (init) != COND_EXPR
   && TREE_CODE (init) != CONSTRUCTOR
   && TREE_CODE (init) != VA_ARG_EXPR)
-/* We need to build up a copy constructor call.  A void initializer
-   means we're being called from bot_manip.  COND_EXPR is a special
+/* We need to build up a copy constructor call.  COND_EXPR is a special
case because we already have copies on the arms and we don't want
another one here.  A CONSTRUCTOR is aggregate initialization, which
is handled separately.  A VA_ARG_EXPR is magic creation of an
@@ -3112,8 +3110,8 @@ bot_manip (tree* tp, int* walk_subtrees, void* data_)
AGGR_INIT_ZERO_FIRST (TREE_OPERAND (u, 1)) = true;
}
   else
-   u = build_target_expr_with_type (TREE_OPERAND (t, 1), TREE_TYPE (t),
-tf_warning_or_error);
+   u = force_target_expr (TREE_TYPE (t), TREE_OPERAND (t, 1),
+  tf_warning_or_error);
 
   TARGET_EXPR_IMPLICIT_P (u) = TARGET_EXPR_IMPLICIT_P (t);
   TARGET_EXPR_LIST_INIT_P (u) = TARGET_EXPR_LIST_INIT_P (t);
diff --git a/gcc/testsuite/g++.dg/cpp1z/elide6.C 
b/gcc/testsuite/g++.dg/cpp1z/elide6.C
new file mode 100644
index 000..399e1a9a1ef
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/elide6.C
@@ -0,0 +1,16 @@
+// PR c++/100368
+// { dg-do compile { target c++11 } }
+
+struct A {
+  A() = default;
+  A(const A&) = delete;
+};
+
+struct B { A a; }; // { dg-error "deleted" "" { target c++14_down } }
+
+constexpr B f() { return {}; }
+
+struct C {
+  constexpr C() : b(f()) {} // { dg-error "deleted" "" { target c++14_down } }
+  B b;
+};
-- 
2.32.0.rc0



[PATCH] add missing GTY support for hash-map (PR 100463)

2021-05-24 Thread Martin Sebor via Gcc-patches

Instantiating a hash_map on a number of integer types including,
for example, int or unsigned int (such as location_t), or
HOST_WIDE_INT, and using it with the garbage collector causes many
cryptic compilation errors due to incomplete support for such types
(the PR shows a few examples).  I ran into these errors as I was
prototyping a new feature and they took me egregiously long to
figure out, even with help from others.

The attached patch adds the missing functions necessary to complete
the support for all integer types to avoid these errors.  This is
prerequisite for a future patch of mine.  The patch uses just one
of these hash_map instances but others shouldn't have to run into
the same errors if they happen to choose one of them.

Tested on x86_64-linux.

Martin
PR other/100463 - many errors using GTY and hash_map

gcc/ChangeLog:
	* ggc.h (gt_ggc_mx): Add overloads for all integers.
	(gt_pch_nx):  Same.
	* hash-map.h (class hash_map): Add pch_nx_helper overloads for all
	integers.
	(hash_map::operator==): New function.

diff --git a/gcc/ggc.h b/gcc/ggc.h
index 65f6cb4d19d..92884717f5c 100644
--- a/gcc/ggc.h
+++ b/gcc/ggc.h
@@ -332,19 +332,30 @@ gt_pch_nx (const char *)
 {
 }
 
-inline void
-gt_ggc_mx (int)
-{
-}
-
-inline void
-gt_pch_nx (int)
-{
-}
-
-inline void
-gt_pch_nx (unsigned int)
-{
-}
+inline void gt_pch_nx (bool) { }
+inline void gt_pch_nx (char) { }
+inline void gt_pch_nx (signed char) { }
+inline void gt_pch_nx (unsigned char) { }
+inline void gt_pch_nx (short) { }
+inline void gt_pch_nx (unsigned short) { }
+inline void gt_pch_nx (int) { }
+inline void gt_pch_nx (unsigned int) { }
+inline void gt_pch_nx (long int) { }
+inline void gt_pch_nx (unsigned long int) { }
+inline void gt_pch_nx (long long int) { }
+inline void gt_pch_nx (unsigned long long int) { }
+
+inline void gt_ggc_mx (bool) { }
+inline void gt_ggc_mx (char) { }
+inline void gt_ggc_mx (signed char) { }
+inline void gt_ggc_mx (unsigned char) { }
+inline void gt_ggc_mx (short) { }
+inline void gt_ggc_mx (unsigned short) { }
+inline void gt_ggc_mx (int) { }
+inline void gt_ggc_mx (unsigned int) { }
+inline void gt_ggc_mx (long int) { }
+inline void gt_ggc_mx (unsigned long int) { }
+inline void gt_ggc_mx (long long int) { }
+inline void gt_ggc_mx (unsigned long long int) { }
 
 #endif
diff --git a/gcc/hash-map.h b/gcc/hash-map.h
index 0779c930f0a..dd039f10343 100644
--- a/gcc/hash-map.h
+++ b/gcc/hash-map.h
@@ -107,27 +107,31 @@ class GTY((user)) hash_map
 	  gt_pch_nx (, op, cookie);
 	}
 
-static void
-  pch_nx_helper (int, gt_pointer_operator, void *)
-	{
-	}
-
-static void
-  pch_nx_helper (unsigned int, gt_pointer_operator, void *)
-	{
-	}
-
-static void
-  pch_nx_helper (bool, gt_pointer_operator, void *)
-	{
-	}
-
 template
   static void
   pch_nx_helper (T *, gt_pointer_operator op, void *cookie)
 	{
 	  op (, cookie);
 	}
+
+/* The overloads below should match those in ggc.h.  */
+#define DEFINE_PCH_HELPER(T)			\
+static void pch_nx_helper (T, gt_pointer_operator, void *) { }
+
+DEFINE_PCH_HELPER (bool);
+DEFINE_PCH_HELPER (char);
+DEFINE_PCH_HELPER (signed char);
+DEFINE_PCH_HELPER (unsigned char);
+DEFINE_PCH_HELPER (short);
+DEFINE_PCH_HELPER (unsigned short);
+DEFINE_PCH_HELPER (int);
+DEFINE_PCH_HELPER (unsigned int);
+DEFINE_PCH_HELPER (long);
+DEFINE_PCH_HELPER (unsigned long);
+DEFINE_PCH_HELPER (long long);
+DEFINE_PCH_HELPER (unsigned long long);
+
+#undef DEFINE_PCH_HELPER
   };
 
 public:
@@ -273,8 +277,12 @@ public:
   return reference_pair (e.m_key, e.m_value);
 }
 
-bool
-operator != (const iterator ) const
+bool operator== (const iterator ) const
+{
+  return m_iter == other.m_iter;
+}
+
+bool operator != (const iterator ) const
 {
   return m_iter != other.m_iter;
 }



Re: [PATCH] x86-64: Remove HAVE_LD_PIE_COPYRELOC

2021-05-24 Thread Fāng-ruì Sòng via Gcc-patches
Ping https://gcc.gnu.org/pipermail/gcc-patches/2021-May/570139.html

On Tue, May 11, 2021 at 8:29 PM Fangrui Song  wrote:
>
> This was introduced in 2014-12 to use local binding for external symbols
> for -fPIE. Now that we have H.J. Lu's GOTPCRELX for years which mostly
> nullify the benefit of HAVE_LD_PIE_COPYRELOC, HAVE_LD_PIE_COPYRELOC
> should retire now.
>
> One design goal of -fPIE was to avoid copy relocations.
> HAVE_LD_PIE_COPYRELOC has deviated from the goal.  With this change, the
> -fPIE behavior of x86-64 will be closer to x86-32 and other targets.
>
> ---
>
> See https://gcc.gnu.org/legacy-ml/gcc/2019-05/msg00215.html for a list
> of fixed and unfixed (e.g. gold incompatibility with protected
> https://sourceware.org/bugzilla/show_bug.cgi?id=19823) issues.
>
> If you prefer a longer write-up, see
> https://maskray.me/blog/2021-01-09-copy-relocations-canonical-plt-entries-and-protected
> ---
>  gcc/config.in |  6 ---
>  gcc/config/i386/i386.c| 11 +---
>  gcc/configure | 52 ---
>  gcc/configure.ac  | 48 -
>  gcc/doc/sourcebuild.texi  |  3 --
>  .../gcc.target/i386/pie-copyrelocs-1.c| 14 -
>  .../gcc.target/i386/pie-copyrelocs-2.c| 14 -
>  .../gcc.target/i386/pie-copyrelocs-3.c| 14 -
>  .../gcc.target/i386/pie-copyrelocs-4.c| 17 --
>  gcc/testsuite/lib/target-supports.exp | 47 -
>  10 files changed, 2 insertions(+), 224 deletions(-)
>  delete mode 100644 gcc/testsuite/gcc.target/i386/pie-copyrelocs-1.c
>  delete mode 100644 gcc/testsuite/gcc.target/i386/pie-copyrelocs-2.c
>  delete mode 100644 gcc/testsuite/gcc.target/i386/pie-copyrelocs-3.c
>  delete mode 100644 gcc/testsuite/gcc.target/i386/pie-copyrelocs-4.c
>
> diff --git a/gcc/config.in b/gcc/config.in
> index e54f59ce0c3..a65bf5d4176 100644
> --- a/gcc/config.in
> +++ b/gcc/config.in
> @@ -1659,12 +1659,6 @@
>  #endif
>
>
> -/* Define 0/1 if your linker supports -pie option with copy reloc. */
> -#ifndef USED_FOR_TARGET
> -#undef HAVE_LD_PIE_COPYRELOC
> -#endif
> -
> -
>  /* Define if your PowerPC linker has .gnu.attributes long double support. */
>  #ifndef USED_FOR_TARGET
>  #undef HAVE_LD_PPC_GNU_ATTR_LONG_DOUBLE
> diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
> index 915f89f571a..5ec3c6fd0c9 100644
> --- a/gcc/config/i386/i386.c
> +++ b/gcc/config/i386/i386.c
> @@ -10579,11 +10579,7 @@ legitimate_pic_address_disp_p (rtx disp)
> return true;
> }
>   else if (!SYMBOL_REF_FAR_ADDR_P (op0)
> -  && (SYMBOL_REF_LOCAL_P (op0)
> -  || (HAVE_LD_PIE_COPYRELOC
> -  && flag_pie
> -  && !SYMBOL_REF_WEAK (op0)
> -  && !SYMBOL_REF_FUNCTION_P (op0)))
> +  && SYMBOL_REF_LOCAL_P (op0)
>&& ix86_cmodel != CM_LARGE_PIC)
> return true;
>   break;
> @@ -22892,10 +22888,7 @@ ix86_atomic_assign_expand_fenv (tree *hold, tree 
> *clear, tree *update)
>  static bool
>  ix86_binds_local_p (const_tree exp)
>  {
> -  return default_binds_local_p_3 (exp, flag_shlib != 0, true, true,
> - (!flag_pic
> -  || (TARGET_64BIT
> -  && HAVE_LD_PIE_COPYRELOC != 0)));
> +  return default_binds_local_p_3 (exp, flag_shlib != 0, true, true, 
> !flag_pic);
>  }
>  #endif
>
> diff --git a/gcc/configure b/gcc/configure
> index f03fe888384..c500f5ca11e 100755
> --- a/gcc/configure
> +++ b/gcc/configure
> @@ -29968,58 +29968,6 @@ fi
>  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_ld_pie" >&5
>  $as_echo "$gcc_cv_ld_pie" >&6; }
>
> -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking linker PIE support with 
> copy reloc" >&5
> -$as_echo_n "checking linker PIE support with copy reloc... " >&6; }
> -gcc_cv_ld_pie_copyreloc=no
> -if test $gcc_cv_ld_pie = yes ; then
> -  if test $in_tree_ld = yes ; then
> -if test "$gcc_cv_gld_major_version" -eq 2 -a "$gcc_cv_gld_minor_version" 
> -ge 25 -o "$gcc_cv_gld_major_version" -gt 2; then
> -  gcc_cv_ld_pie_copyreloc=yes
> -fi
> -  elif test x$gcc_cv_as != x -a x$gcc_cv_ld != x ; then
> -# Check if linker supports -pie option with copy reloc
> -case "$target" in
> -i?86-*-linux* | x86_64-*-linux*)
> -  cat > conftest1.s < -   .globl  a_glob
> -   .data
> -   .type   a_glob, @object
> -   .size   a_glob, 4
> -a_glob:
> -   .long   2
> -EOF
> -  cat > conftest2.s < -   .text
> -   .globl  main
> -   .type   main, @function
> -main:
> -   movl%eax, a_glob(%rip)
> -   .size   main, .-main
> -   .globl  ptr
> -   .section.data.rel,"aw",@progbits
> -   .type   ptr, @object
> -ptr:
> -   .quad   

Re: [PATCH 1/5] Common API for accessing global and on-demand ranges.

2021-05-24 Thread Aldy Hernandez via Gcc-patches




On 5/21/21 1:39 PM, Aldy Hernandez wrote:

This patch provides a generic API for accessing global ranges.  It is
meant to replace get_range_info() and get_ptr_nonnull() with one
common interface.  It uses the same API as the ranger (class
range_query), so there will now be one API for accessing local and
global ranges alike.

Follow-up patches will convert all users of get_range_info and
get_ptr_nonnull to this API.

For get_range_info, instead of:

   if (!POINTER_TYPE_P (TREE_TYPE (name)) && SSA_NAME_RANGE_INFO (name))
 get_range_info (name, vr);

You can now do:

   RANGE_QUERY (cfun)->range_of_expr (vr, name, [stmt]);


BTW, we're not wed to the idea of putting the current range object in 
cfun.  The important thing is that the API is consistent across, not 
where it lives.


We're open to suggestions: a global variable, cfun, the pass manager, or 
even a pass property:


  ( PROP_blah | PROP_ranger ), /* properties_required */

I personally like cfun, but we're open to suggestions.

Aldy



Ping [PATCH 2/2] Fix tests when running on power10, PR testsuite/100166

2021-05-24 Thread Michael Meissner via Gcc-patches
Ping patch.

| Date: Tue, 18 May 2021 16:59:12 -0400
| Subject: [PATCH 2/2] Fix tests when running on power10, PR testsuite/100166
| Message-ID: <20210518205912.gb18...@ibm-toto.the-meissners.org>

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


Re: [PATCH 1/2] Deal with prefixed loads/stores in tests, PR testsuite/100166

2021-05-24 Thread Michael Meissner via Gcc-patches
Ping patch.  This is independent of the other patches.

| Date: Tue, 18 May 2021 16:57:59 -0400
| Subject: [PATCH 1/2] Deal with prefixed loads/stores in tests, PR 
testsuite/100166
| Message-ID: <20210518205759.ga18...@ibm-toto.the-meissners.org>

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


Ping [PATCH 2/2] Fix xxeval predicates.

2021-05-24 Thread Michael Meissner via Gcc-patches
Ping patch.

| Date: Tue, 18 May 2021 16:47:58 -0400
| Subject: [PATCH 2/2] Fix xxeval predicates.
| Message-ID: <20210518204758.gb16...@ibm-toto.the-meissners.org>

This needs the following patch to have been applied:

| Date: Tue, 18 May 2021 16:46:47 -0400
| Subject: [PATCH 1/2] Move xx* builtins to vsx.md.
| Message-ID: <20210518204647.ga16...@ibm-toto.the-meissners.org>

If the first patch is rejected, this patch should still be considered (but it
would be against alivect.md instead of vsx.md).

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


Ping [PATCH 1/2] Move xx* builtins to vsx.md.

2021-05-24 Thread Michael Meissner via Gcc-patches
Ping patch.  This patch is a set of 2 patches.  The second patch will need this
patch applied.  In addition, the next 3 patches that I will be submitting (to
add support for generating XXSPLTIW, XXSPLTIDP, and XXSPLTI32DX) will need this
patch applied (or else I would just have to reformulate the patch if this is
rejected).

| Date: Tue, 18 May 2021 16:46:47 -0400
| Subject: [PATCH 1/2] Move xx* builtins to vsx.md.
| Message-ID: <20210518204647.ga16...@ibm-toto.the-meissners.org>


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


Ping [PATCH] Change rs6000_const_f32_to_i32 return type.

2021-05-24 Thread Michael Meissner via Gcc-patches
Ping patch.  This is independent of the other patches.

| Date: Tue, 18 May 2021 16:39:28 -0400
| Subject: [PATCH] Change rs6000_const_f32_to_i32 return type.
| Message-ID: <20210518203928.ga15...@ibm-toto.the-meissners.org>

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


Ping [PATCH] Allow __ibm128 on older PowerPC systems.

2021-05-24 Thread Michael Meissner via Gcc-patches
Ping patch.  This is independent of the other patches.

| Date: Tue, 18 May 2021 16:36:32 -0400
| Subject: [PATCH] Allow __ibm128 on older PowerPC systems.
| Message-ID: <20210518203632.ga15...@ibm-toto.the-meissners.org>

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


Ping [PATCH] Fix long double tests when default long double is not IBM.

2021-05-24 Thread Michael Meissner via Gcc-patches
Ping patch.  This is independent of the other patches.

| Date: Tue, 18 May 2021 16:32:33 -0400
| Subject: [PATCH] Fix long double tests when default long double is not IBM.
| Message-ID: <20210518203233.ga15...@ibm-toto.the-meissners.org>

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


Ping [PATCH 2/2] Add IEEE 128-bit fp conditional move on PowerPC.

2021-05-24 Thread Michael Meissner via Gcc-patches
Ping patch.

| Subject: [PATCH 2/2] Add IEEE 128-bit fp conditional move on PowerPC.
| Message-ID: <20210518202827.gb14...@ibm-toto.the-meissners.org>

Note this patch needs the following patch before it can be applied.

| Subject: [PATCH 1/2] Add IEEE 128-bit min/max support on PowerPC.
| Message-ID: <20210518202606.ga14...@ibm-toto.the-meissners.org>

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


Ping [PATCH 1/2] Add IEEE 128-bit min/max support on PowerPC.

2021-05-24 Thread Michael Meissner via Gcc-patches
Ping patch:

| Subject: [PATCH 1/2] Add IEEE 128-bit min/max support on PowerPC.
| Message-ID: <20210518202606.ga14...@ibm-toto.the-meissners.org>

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


Re: [Patch] OpenMP/Fortran: Handle polymorphic scalars in data-sharing FIRSTPRIVATE [PR86470]

2021-05-24 Thread Jakub Jelinek via Gcc-patches
On Wed, Mar 10, 2021 at 11:55:43AM +0100, Tobias Burnus wrote:
> --- a/gcc/fortran/trans-openmp.c
> +++ b/gcc/fortran/trans-openmp.c
> @@ -360,6 +360,39 @@ gfc_has_alloc_comps (tree type, tree decl)
>return false;
>  }
>  
> +/* Return true if TYPE is polymorphic but not with pointer attribute.  */
> +
> +static bool
> +gfc_is_polymorphic_nonptr (tree type)
> +{
> +  if (POINTER_TYPE_P (type))
> +type = TREE_TYPE (type);
> +  return GFC_CLASS_TYPE_P (type);
> +}
> +
> +/* Return true if TYPE is unlimited polymorphic but not with pointer 
> attribute;
> +   unlimited means also intrinsic types are handled and _len is used.  */
> +
> +static bool
> +gfc_is_unlimited_polymorphic_nonptr (tree type)
> +{
> +  if (POINTER_TYPE_P (type))
> +type = TREE_TYPE (type);
> +  if (!GFC_CLASS_TYPE_P (type))
> +return false;
> +
> +  tree field = TYPE_FIELDS (type); /* _data */
> +  gcc_assert (field);
> +  field = DECL_CHAIN (field); /* _vptr */
> +  gcc_assert (field);
> +  field = DECL_CHAIN (field);
> +  if (!field)
> +return false;
> +  gcc_assert (0 == strcmp ("_len", IDENTIFIER_POINTER (DECL_NAME (field;

strcmp (...) == 0 instead please.

> +  return true;
> +}
> +
> +
>  /* Return true if DECL in private clause needs
> OMP_CLAUSE_PRIVATE_OUTER_REF on the private clause.  */
>  bool
> @@ -743,12 +776,88 @@ tree
>  gfc_omp_clause_copy_ctor (tree clause, tree dest, tree src)
>  {
>tree type = TREE_TYPE (dest), ptr, size, call;
> +  tree decl_type = TREE_TYPE (OMP_CLAUSE_DECL (clause));
>tree cond, then_b, else_b;
>stmtblock_t block, cond_block;
>  
>gcc_assert (OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_FIRSTPRIVATE
> || OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_LINEAR);
>  
> +  if (DECL_ARTIFICIAL (OMP_CLAUSE_DECL (clause))
> +  && DECL_LANG_SPECIFIC (OMP_CLAUSE_DECL (clause))
> +  && GFC_DECL_SAVED_DESCRIPTOR (OMP_CLAUSE_DECL (clause)))
> +decl_type
> + = TREE_TYPE (GFC_DECL_SAVED_DESCRIPTOR (OMP_CLAUSE_DECL (clause)));

Indentation, decl_type is indented by 4 spaces, but this line by tab (== 8 sp).

Otherwise LGTM, sorry for the delay.

Jakub



[PATCH 1/4] C-SKY: Add fpuv3 instructions and CK860 arch.

2021-05-24 Thread Geng Qi via Gcc-patches
gcc/ChangeLog:

* config/csky/constraints.md ("W"): New constriant for mem operand
with base reg, index register.
("Q"): Renamed and modified "csky_valid_fpuv2_mem_operand" to
"csky_valid_mem_constraint_operand" to deal with both "Q" and "W"
constraint.
("Dv"): New constraint for const double value that can be used at
fmovi instruction.
* config/csky/csky-modes.def (HFmode): New mode.
* config/csky/csky-protos.h (csky_valid_fpuv2_mem_operand): Rename
to "csky_valid_mem_constraint_operand" and support new constraint
"W".
(csky_get_movedouble_length): New.
(fpuv3_output_move): New.
(fpuv3_const_double): New.
* config/csky/csky.c (csky_option_override): New arch CK860 with fpv3.
(decompose_csky_address): Refine.
(csky_print_operand): New "CONST_DOUBLE" operand.
(csky_output_move): Support fpv3 instructions.
(csky_get_movedouble_length): New.
(fpuv3_output_move): New.
(fpuv3_const_double): New.
(csky_emit_compare): Cover float comparsion.
(csky_emit_compare_float): Refine.
(csky_vaild_fpuv2_mem_operand): Rename to
"csky_valid_mem_constraint_operand" and support new constraint "W".
(ck860_rtx_costs): New.
(csky_rtx_costs): Add the cost calculation of CK860.
(regno_reg_class): New vregs for fpuv3.
(csky_dbx_regno): Likewise.
(csky_cpu_cpp_builtins): New builtin macro for fpuv3.
(csky_conditional_register_usage): Suporrot fpuv3.
(csky_dwarf_register_span): Suporrot fpuv3.
(csky_init_builtins, csky_mangle_type): Support "__fp16" type.
(ck810_legitimate_index_p): Support fp16.
* gcc/config/csky/csky.h (TARGET_TLS): ADD CK860.
(CSKY_VREG_P, CSKY_VREG_LO_P, CSKY_VREG_HI_P): Support fpuv3.
(TARGET_SINGLE_FPU): Support fpuv3.
(TARGET_SUPPORT_FPV3): New.
(FIRST_PSEUDO_REGISTER): Change to 202 to hold the new fpuv3 registers.
(FIXED_REGISTERS, CALL_REALLY_USED_REGISTERS, REGISTER_NAMES,
 REG_CLASS_CONTENTS): Support fpuv3.
* gcc/config/csky/csky.md (movsf): Move to cksy_insn_fpu.md and refine.
(csky_movsf_fpv2): Likewise.
(ck801_movsf): Likewise.
(csky_movsf): Likewise.
(movdf): Likewise.
(csky_movdf_fpv2): Likewise.
(ck801_movdf): Likewise.
(csky_movdf): Likewise.
(movsicc): Refine. Use "comparison_operatior" instead of
"ordered_comparison_operatior".
(addsicc): Likewise.
(CSKY_FIRST_VFP3_REGNUM, CSKY_LAST_VFP3_REGNUM): New constant.
(call_value_internal_vh): New.
* config/csky/csky_cores.def (CK860): New arch and cpu.
(fpv3_hf): New.
(fpv3_hsf): New.
(fpv3_sdf): New.
(fpv3): New.
* config/csky/csky_insn_fpu.md: Refactor. Separate all float patterns
into emit-patterns and match-patterns, remain the emit-patterns here,
and move the match-patterns to csky_insn_fpuv2.md or
csky_insn_fpuv3.md.
* config/csky/csky_insn_fpuv2.md: New file for fpuv2 instructions.
* config/csky/csky_insn_fpuv3.md: New file and new patterns for fpuv3
isntructions.
* config/csky/csky_isa.def (fcr): New.
(fpv3_hi): New.
(fpv3_hf): New.
(fpv3_sf): New.
(fpv3_df): New.
(CK860): New definition for ck860.
* gcc/config/csky/csky_tables.opt (ck860): New processors ck860,
ck860f. And new arch ck860.
(fpv3_hf): New.
(fpv3_hsf): New.
(fpv3_hdf): New.
(fpv3): New.
* config/csky/predicates.md (csky_float_comparsion_operator): Delete
"geu", "gtu", "leu", "ltu", which will never appear at float comparison.
* config/cksy/t-csky-elf, config/csky/t-csky-linux: Support 860.
* doc/md.texi: Add "Q" and "W" constraints for C-SKY.
---
 gcc/config/csky/constraints.md |  13 +-
 gcc/config/csky/csky-modes.def |   2 +
 gcc/config/csky/csky-protos.h  |   7 +-
 gcc/config/csky/csky.c | 644 ++
 gcc/config/csky/csky.h | 162 ++--
 gcc/config/csky/csky.md| 127 ++
 gcc/config/csky/csky_cores.def |  13 +
 gcc/config/csky/csky_insn_fpu.md   | 798 +++--
 gcc/config/csky/csky_insn_fpuv2.md | 470 ++
 gcc/config/csky/csky_insn_fpuv3.md | 497 +++
 gcc/config/csky/csky_isa.def   |  15 +
 gcc/config/csky/csky_tables.opt|  21 +
 gcc/config/csky/predicates.md  |   3 +-
 gcc/config/csky/t-csky-elf |   9 +-
 gcc/config/csky/t-csky-linux   |  11 +-
 gcc/doc/md.texi|   8 +
 16 files changed, 2125 insertions(+), 675 deletions(-)
 create mode 100644 gcc/config/csky/csky-modes.def
 create mode 100644 gcc/config/csky/csky_insn_fpuv2.md
 create mode 

[PATCH 4/4] C-SKY: Separate FRAME_POINTER_REGNUM into FRAME_POINTER_REGNUM and HARD_FRAME_POINTER_REGNUM.

2021-05-24 Thread Geng Qi via Gcc-patches
gcc/ChangeLog:

* config/csky/csky.h
(FRAME_POINTER_REGNUM): Use HARD_FRAME_POINTER_REGNUM and
FRAME_POINTER_REGNUM instead of the signle definition. The
signle definition may not work well at simplify_subreg_regno().
(ELIMINABLE_REGS): Add for HARD_FRAME_POINTER_REGNUM.
* config/csky/csky.c (get_csky_live_regs, csky_can_eliminate,
csky_initial_elimination_offset, csky_expand_prologue,
csky_expand_epilogue): Add for HARD_FRAME_POINTER_REGNUM.
---
 gcc/config/csky/csky.c | 15 +--
 gcc/config/csky/csky.h |  7 +--
 2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/gcc/config/csky/csky.c b/gcc/config/csky/csky.c
index 1a6cfd7..7f2af82 100644
--- a/gcc/config/csky/csky.c
+++ b/gcc/config/csky/csky.c
@@ -1751,12 +1751,12 @@ get_csky_live_regs (int *count)
save = true;
 
   /* Frame pointer marked used.  */
-  else if (frame_pointer_needed && reg == FRAME_POINTER_REGNUM)
+  else if (frame_pointer_needed && reg == HARD_FRAME_POINTER_REGNUM)
save = true;
 
   /* This is required for CK801/802 where FP is a fixed reg, otherwise
 we end up with no FP value available to the DWARF-2 unwinder.  */
-  else if (crtl->calls_eh_return && reg == FRAME_POINTER_REGNUM)
+  else if (crtl->calls_eh_return && reg == HARD_FRAME_POINTER_REGNUM)
save = true;
 
   /* CK801/802 also need special handling for LR because it's clobbered
@@ -1832,6 +1832,8 @@ csky_layout_stack_frame (void)
 static bool
 csky_can_eliminate (const int from ATTRIBUTE_UNUSED, const int to)
 {
+  if (to == FRAME_POINTER_REGNUM)
+return from != ARG_POINTER_REGNUM;
   if (to == STACK_POINTER_REGNUM)
 return !frame_pointer_needed;
   return true;
@@ -1852,6 +1854,7 @@ csky_initial_elimination_offset (int from, int to)
   switch (from)
 {
 case FRAME_POINTER_REGNUM:
+case HARD_FRAME_POINTER_REGNUM:
   offset = cfun->machine->reg_offset;
   break;
 
@@ -1866,7 +1869,7 @@ csky_initial_elimination_offset (int from, int to)
   /* If we are asked for the offset to the frame pointer instead,
  then subtract the difference between the frame pointer and stack
  pointer.  */
-  if (to == FRAME_POINTER_REGNUM)
+  if (to == FRAME_POINTER_REGNUM || to == HARD_FRAME_POINTER_REGNUM)
 offset -= cfun->machine->reg_offset;
   return offset;
 }
@@ -5785,7 +5788,7 @@ csky_expand_prologue (void)
  of the register save area.  */
   if (frame_pointer_needed)
 {
-  insn = emit_insn (gen_movsi (frame_pointer_rtx, stack_pointer_rtx));
+  insn = emit_insn (gen_movsi (hard_frame_pointer_rtx, stack_pointer_rtx));
   RTX_FRAME_RELATED_P (insn) = 1;
 }
 
@@ -5848,7 +5851,7 @@ csky_expand_epilogue (void)
   /* Restore the SP to the base of the register save area.  */
   if (frame_pointer_needed)
 {
-  insn = emit_move_insn (stack_pointer_rtx, frame_pointer_rtx);
+  insn = emit_move_insn (stack_pointer_rtx, hard_frame_pointer_rtx);
   RTX_FRAME_RELATED_P (insn) = 1;
 }
   else
@@ -6004,7 +6007,7 @@ csky_set_eh_return_address (rtx source, rtx scratch)
 
   if (frame_pointer_needed)
{
- basereg = frame_pointer_rtx;
+ basereg = hard_frame_pointer_rtx;
  delta = 0;
}
   else
diff --git a/gcc/config/csky/csky.h b/gcc/config/csky/csky.h
index 1fd72d0..f2b0d1c 100644
--- a/gcc/config/csky/csky.h
+++ b/gcc/config/csky/csky.h
@@ -342,7 +342,8 @@ extern int csky_arch_isa_features[];
 #define STACK_POINTER_REGNUM  CSKY_SP_REGNUM
 
 /* Base register for access to local variables of the function.  */
-#define FRAME_POINTER_REGNUM  8
+#define FRAME_POINTER_REGNUM  36
+#define HARD_FRAME_POINTER_REGNUM  8
 
 /* Base register for access to arguments of the function.  This is a fake
register that is always eliminated.  */
@@ -370,7 +371,9 @@ extern int csky_arch_isa_features[];
 #define ELIMINABLE_REGS  \
 {{ ARG_POINTER_REGNUM,   STACK_POINTER_REGNUM},\
  { ARG_POINTER_REGNUM,   FRAME_POINTER_REGNUM},\
- { FRAME_POINTER_REGNUM,  STACK_POINTER_REGNUM   }}
+ { ARG_POINTER_REGNUM,   HARD_FRAME_POINTER_REGNUM   },\
+ { FRAME_POINTER_REGNUM,  STACK_POINTER_REGNUM   },\
+ { FRAME_POINTER_REGNUM,  HARD_FRAME_POINTER_REGNUM  }}
 
 /* Define the offset between two registers, one to be eliminated, and the
other its replacement, at the start of a routine.  */
-- 
2.7.4



[PATCH 3/4] C-SKY: Bug fix for bad setting of TARGET_DSP and TARGET_DIV.

2021-05-24 Thread Geng Qi via Gcc-patches
gcc/ChangeLog:

* config/csky/csky.c (csky_option_override):
Init csky_arch_isa_features[]  advanced, so TARGET_DSP
and TARGET_DIV can be set well.
---
 gcc/config/csky/csky.c | 24 
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/gcc/config/csky/csky.c b/gcc/config/csky/csky.c
index b2160b9..1a6cfd7 100644
--- a/gcc/config/csky/csky.c
+++ b/gcc/config/csky/csky.c
@@ -2680,6 +2680,18 @@ csky_option_override (void)
   TARGET_FDIVDU = 0;
 }
 
+  /* Initialize boolean versions of the architectural flags, for use
+ in the .md file.  */
+
+#undef CSKY_ISA
+#define CSKY_ISA(IDENT, DESC)\
+  {  \
+csky_arch_isa_features[CSKY_ISA_FEATURE_GET (IDENT)] =\
+  bitmap_bit_p (csky_active_target.isa, CSKY_ISA_FEATURE_GET (IDENT)); \
+  }
+#include "csky_isa.def"
+#undef CSKY_ISA
+
   /* Extended LRW instructions are enabled by default on CK801, disabled
  otherwise.  */
   if (TARGET_ELRW == -1)
@@ -2752,18 +2764,6 @@ csky_option_override (void)
   TARGET_MULTIPLE_STLD = 0;
 }
 
-  /* Initialize boolean versions of the architectural flags, for use
- in the .md file.  */
-
-#undef CSKY_ISA
-#define CSKY_ISA(IDENT, DESC)\
-  {  \
-csky_arch_isa_features[CSKY_ISA_FEATURE_GET (IDENT)] =\
-  bitmap_bit_p (csky_active_target.isa, CSKY_ISA_FEATURE_GET (IDENT)); \
-  }
-#include "csky_isa.def"
-#undef CSKY_ISA
-
   /* TODO  */
 
   /* Resynchronize the saved target options.  */
-- 
2.7.4



[PATCH 2/4] C-SKY: Delete LO_REGS and HI_REGS, use HILO_REGS instead.

2021-05-24 Thread Geng Qi via Gcc-patches
gcc/ChangeLog:

* config/csky/constraints.md ("l", "h"): Delete.
* config/csky/csky.h (reg_class, REG_CLASS_NAMES,
REG_CLASS_CONTENTS):  Delete LO_REGS and HI_REGS.
* config/csky/csky.c (regno_reg_classm,
csky_secondary_reload, csky_register_move_cost):
Use HILO_REGS instead of LO_REGS and HI_REGS.
---
 gcc/config/csky/constraints.md | 2 --
 gcc/config/csky/csky.c | 7 +++
 gcc/config/csky/csky.h | 8 
 3 files changed, 3 insertions(+), 14 deletions(-)

diff --git a/gcc/config/csky/constraints.md b/gcc/config/csky/constraints.md
index 937cb81..c9bc9f2 100644
--- a/gcc/config/csky/constraints.md
+++ b/gcc/config/csky/constraints.md
@@ -24,8 +24,6 @@
 (define_register_constraint "b" "LOW_REGS"  "r0 - r15")
 (define_register_constraint "c" "C_REGS" "C register")
 (define_register_constraint "y" "HILO_REGS" "HI and LO registers")
-(define_register_constraint "l" "LO_REGS" "LO register")
-(define_register_constraint "h" "HI_REGS" "HI register")
 (define_register_constraint "v" "V_REGS" "vector registers")
 (define_register_constraint "z" "SP_REGS" "SP register")
 
diff --git a/gcc/config/csky/csky.c b/gcc/config/csky/csky.c
index 6e97994..b2160b9 100644
--- a/gcc/config/csky/csky.c
+++ b/gcc/config/csky/csky.c
@@ -112,7 +112,7 @@ enum reg_class regno_reg_class[FIRST_PSEUDO_REGISTER] =
   /* Reserved.  */
   RESERVE_REGS,
   /* CC,HI,LO registers.  */
-  C_REGS,  HI_REGS, LO_REGS,
+  C_REGS,  HILO_REGS, HILO_REGS,
   /* Reserved.  */
   RESERVE_REGS, RESERVE_REGS, RESERVE_REGS, RESERVE_REGS,
   RESERVE_REGS, RESERVE_REGS, RESERVE_REGS, RESERVE_REGS,
@@ -2477,8 +2477,7 @@ csky_secondary_reload (bool in_p ATTRIBUTE_UNUSED, rtx x,
   /* We always require a general register when copying anything to
  HI/LO_REGNUM, except when copying an SImode value from HI/LO_REGNUM
  to a general register, or when copying from register 0.  */
-  if ((rclass == HILO_REGS || rclass == LO_REGS || rclass == HI_REGS)
-  && !CSKY_GENERAL_REGNO_P (regno))
+  if (rclass == HILO_REGS && !CSKY_GENERAL_REGNO_P (regno))
 return GENERAL_REGS;
 
   if (rclass == V_REGS && !CSKY_GENERAL_REGNO_P (regno))
@@ -6546,7 +6545,7 @@ csky_register_move_cost (machine_mode mode 
ATTRIBUTE_UNUSED,
|| (CLASS) == LOW_REGS)
 
 #define HILO_REG_CLASS_P(CLASS) \
-  ((CLASS) == HI_REGS || (CLASS) == LO_REGS || (CLASS) == HILO_REGS)
+  ((CLASS) == HILO_REGS)
 
 #define V_REG_CLASS_P(CLASS) \
   ((CLASS) == V_REGS)
diff --git a/gcc/config/csky/csky.h b/gcc/config/csky/csky.h
index f535c42..1fd72d0 100644
--- a/gcc/config/csky/csky.h
+++ b/gcc/config/csky/csky.h
@@ -685,8 +685,6 @@ enum reg_class
   LOW_REGS,
   GENERAL_REGS,
   C_REGS,
-  HI_REGS,
-  LO_REGS,
   HILO_REGS,
   V_REGS,
   OTHER_REGS,
@@ -706,8 +704,6 @@ enum reg_class
   "LOW_REGS",  \
   "GENERAL_REGS",  \
   "C_REGS",\
-  "HI_REGS",   \
-  "LO_REGS",   \
   "HILO_REGS", \
   "V_REGS",\
   "OTHER_REGS",\
@@ -731,10 +727,6 @@ enum reg_class
0x, 0x, 0x},/* GENERAL_REGS 
 */   \
   {0x, 0x0002, 0x, 0x,   \
0x, 0x, 0x},/* C_REGS   
 */   \
-  {0x, 0x0004, 0x, 0x,   \
-   0x, 0x, 0x},/* HI_REG   
 */   \
-  {0x, 0x0008, 0x, 0x,   \
-   0x, 0x, 0x},/* LO_REG   
 */   \
   {0x, 0x000c, 0x, 0x,   \
0x, 0x, 0x},/* HILO_REGS
 */   \
   {0x, 0xFFF0, 0x007FFF8F, 0x,   \
-- 
2.7.4



RE: [PATCH 9/9] arm: Auto-vectorization for MVE: vld4/vst4

2021-05-24 Thread Kyrylo Tkachov via Gcc-patches



> -Original Message-
> From: Gcc-patches  On Behalf Of
> Christophe Lyon via Gcc-patches
> Sent: 30 April 2021 15:10
> To: gcc-patches@gcc.gnu.org
> Subject: [PATCH 9/9] arm: Auto-vectorization for MVE: vld4/vst4
> 
> This patch enables MVE vld4/vst4 instructions for auto-vectorization.
> We move the existing expanders from neon.md and enable them for MVE,
> calling the respective emitter.

Ok.
Thanks,
Kyrill

> 
> 2021-03-12  Christophe Lyon  
> 
>   gcc/
>   * config/arm/neon.md (vec_load_lanesxi)
>   (vec_store_lanexoi): Move ...
>   * config/arm/vec-common.md: here.
> 
>   gcc/testsuite/
>   * gcc.target/arm/simd/mve-vld4.c: New test, derived from
>   slp-perm-3.c
> ---
>  gcc/config/arm/neon.md   |  20 
>  gcc/config/arm/vec-common.md |  26 +
>  gcc/testsuite/gcc.target/arm/simd/mve-vld4.c | 140
> +++
>  3 files changed, 166 insertions(+), 20 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/arm/simd/mve-vld4.c
> 
> diff --git a/gcc/config/arm/neon.md b/gcc/config/arm/neon.md
> index bc8775c..fb58baf 100644
> --- a/gcc/config/arm/neon.md
> +++ b/gcc/config/arm/neon.md
> @@ -5617,16 +5617,6 @@ (define_insn "neon_vld4"
>  (const_string "neon_load4_4reg")))]
>  )
> 
> -(define_expand "vec_load_lanesxi"
> -  [(match_operand:XI 0 "s_register_operand")
> -   (match_operand:XI 1 "neon_struct_operand")
> -   (unspec:VQ2 [(const_int 0)] UNSPEC_VSTRUCTDUMMY)]
> -  "TARGET_NEON"
> -{
> -  emit_insn (gen_neon_vld4 (operands[0], operands[1]));
> -  DONE;
> -})
> -
>  (define_expand "neon_vld4"
>[(match_operand:XI 0 "s_register_operand")
> (match_operand:XI 1 "neon_struct_operand")
> @@ -5818,16 +5808,6 @@ (define_insn "neon_vst4"
>  (const_string "neon_store4_4reg")))]
>  )
> 
> -(define_expand "vec_store_lanesxi"
> -  [(match_operand:XI 0 "neon_struct_operand")
> -   (match_operand:XI 1 "s_register_operand")
> -   (unspec:VQ2 [(const_int 0)] UNSPEC_VSTRUCTDUMMY)]
> -  "TARGET_NEON"
> -{
> -  emit_insn (gen_neon_vst4 (operands[0], operands[1]));
> -  DONE;
> -})
> -
>  (define_expand "neon_vst4"
>[(match_operand:XI 0 "neon_struct_operand")
> (match_operand:XI 1 "s_register_operand")
> diff --git a/gcc/config/arm/vec-common.md b/gcc/config/arm/vec-
> common.md
> index 7abefea..d46b78d 100644
> --- a/gcc/config/arm/vec-common.md
> +++ b/gcc/config/arm/vec-common.md
> @@ -512,3 +512,29 @@ (define_expand "vec_store_lanesoi"
>  emit_insn (gen_mve_vst2q (operands[0], operands[1]));
>DONE;
>  })
> +
> +(define_expand "vec_load_lanesxi"
> +  [(match_operand:XI 0 "s_register_operand")
> +   (match_operand:XI 1 "neon_struct_operand")
> +   (unspec:VQ2 [(const_int 0)] UNSPEC_VSTRUCTDUMMY)]
> +  "TARGET_NEON || TARGET_HAVE_MVE"
> +{
> +  if (TARGET_NEON)
> +emit_insn (gen_neon_vld4 (operands[0], operands[1]));
> +  else
> +emit_insn (gen_mve_vld4q (operands[0], operands[1]));
> +  DONE;
> +})
> +
> +(define_expand "vec_store_lanesxi"
> +  [(match_operand:XI 0 "neon_struct_operand")
> +   (match_operand:XI 1 "s_register_operand")
> +   (unspec:VQ2 [(const_int 0)] UNSPEC_VSTRUCTDUMMY)]
> +  "TARGET_NEON || TARGET_HAVE_MVE"
> +{
> +  if (TARGET_NEON)
> +emit_insn (gen_neon_vst4 (operands[0], operands[1]));
> +  else
> +emit_insn (gen_mve_vst4q (operands[0], operands[1]));
> +  DONE;
> +})
> diff --git a/gcc/testsuite/gcc.target/arm/simd/mve-vld4.c
> b/gcc/testsuite/gcc.target/arm/simd/mve-vld4.c
> new file mode 100644
> index 000..ce3e755
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/arm/simd/mve-vld4.c
> @@ -0,0 +1,140 @@
> +/* { dg-do assemble } */
> +/* { dg-require-effective-target arm_v8_1m_mve_fp_ok } */
> +/* { dg-add-options arm_v8_1m_mve_fp } */
> +/* { dg-additional-options "-O3" } */
> +
> +#include 
> +
> +#define M00 100
> +#define M10 216
> +#define M20 23
> +#define M30 237
> +#define M01 1322
> +#define M11 13
> +#define M21 27271
> +#define M31 2280
> +#define M02 74
> +#define M12 191
> +#define M22 500
> +#define M32 111
> +#define M03 134
> +#define M13 117
> +#define M23 11
> +#define M33 771
> +
> +#define N 128
> +
> +/* Integer tests.  */
> +#define FUNC(SIGN, TYPE, BITS)
>   \
> +  void foo_##SIGN##BITS##x (TYPE##BITS##_t *__restrict__ pInput, \
> + TYPE##BITS##_t *__restrict__ pOutput)   \
> +  {  \
> +unsigned int i;  \
> +TYPE##BITS##_t  a, b, c, d;  
> \
> + \
> +for (i = 0; i < N / BITS; i++)   \
> +  {  
> \
> + a = *pInput++;  \
> + b = *pInput++;   

RE: [PATCH 8/9] arm: Auto-vectorization for MVE: vld2/vst2

2021-05-24 Thread Kyrylo Tkachov via Gcc-patches



> -Original Message-
> From: Gcc-patches  On Behalf Of
> Christophe Lyon via Gcc-patches
> Sent: 30 April 2021 15:10
> To: gcc-patches@gcc.gnu.org
> Subject: [PATCH 8/9] arm: Auto-vectorization for MVE: vld2/vst2
> 
> This patch enables MVE vld2/vst2 instructions for auto-vectorization.
> We move the existing expanders from neon.md and enable them for MVE,
> calling the respective emitter.

Ok.
Thanks,
Kyrill

> 
> 2021-03-12  Christophe Lyon  
> 
>   gcc/
>   * config/arm/neon.md (vec_load_lanesoi)
>   (vec_store_lanesoi): Move ...
>   * config/arm/vec-common.md: here.
> 
>   gcc/testsuite/
>   * gcc.target/arm/simd/mve-vld2.c: New test, derived from
>   slp-perm-2.c
> ---
>  gcc/config/arm/neon.md   | 14 
>  gcc/config/arm/vec-common.md | 27 
>  gcc/testsuite/gcc.target/arm/simd/mve-vld2.c | 96
> 
>  3 files changed, 123 insertions(+), 14 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/arm/simd/mve-vld2.c
> 
> diff --git a/gcc/config/arm/neon.md b/gcc/config/arm/neon.md
> index 6660846..bc8775c 100644
> --- a/gcc/config/arm/neon.md
> +++ b/gcc/config/arm/neon.md
> @@ -5063,13 +5063,6 @@ (define_insn "neon_vld2"
>  (const_string "neon_load2_2reg")))]
>  )
> 
> -(define_expand "vec_load_lanesoi"
> -  [(set (match_operand:OI 0 "s_register_operand")
> -(unspec:OI [(match_operand:OI 1 "neon_struct_operand")
> -(unspec:VQ2 [(const_int 0)] UNSPEC_VSTRUCTDUMMY)]
> -UNSPEC_VLD2))]
> -  "TARGET_NEON")
> -
>  (define_insn "neon_vld2"
>[(set (match_operand:OI 0 "s_register_operand" "=w")
>  (unspec:OI [(match_operand:OI 1 "neon_struct_operand" "Um")
> @@ -5197,13 +5190,6 @@ (define_insn "neon_vst2"
>  (const_string "neon_store2_one_lane")))]
>  )
> 
> -(define_expand "vec_store_lanesoi"
> -  [(set (match_operand:OI 0 "neon_struct_operand")
> - (unspec:OI [(match_operand:OI 1 "s_register_operand")
> -(unspec:VQ2 [(const_int 0)] UNSPEC_VSTRUCTDUMMY)]
> -   UNSPEC_VST2))]
> -  "TARGET_NEON")
> -
>  (define_insn "neon_vst2"
>[(set (match_operand:OI 0 "neon_struct_operand" "=Um")
>   (unspec:OI [(match_operand:OI 1 "s_register_operand" "w")
> diff --git a/gcc/config/arm/vec-common.md b/gcc/config/arm/vec-
> common.md
> index 3fd341c..7abefea 100644
> --- a/gcc/config/arm/vec-common.md
> +++ b/gcc/config/arm/vec-common.md
> @@ -482,6 +482,33 @@ (define_expand
> "vcond_mask_"
>  }
>else
>  gcc_unreachable ();
> +  DONE;
> +})
> 
> +(define_expand "vec_load_lanesoi"
> +  [(set (match_operand:OI 0 "s_register_operand")
> +(unspec:OI [(match_operand:OI 1 "neon_struct_operand")
> +(unspec:VQ2 [(const_int 0)] UNSPEC_VSTRUCTDUMMY)]
> +UNSPEC_VLD2))]
> +  "TARGET_NEON || TARGET_HAVE_MVE"
> +{
> +  if (TARGET_NEON)
> +emit_insn (gen_neon_vld2 (operands[0], operands[1]));
> +  else
> +emit_insn (gen_mve_vld2q (operands[0], operands[1]));
> +  DONE;
> +})
> +
> +(define_expand "vec_store_lanesoi"
> +  [(set (match_operand:OI 0 "neon_struct_operand")
> + (unspec:OI [(match_operand:OI 1 "s_register_operand")
> +(unspec:VQ2 [(const_int 0)] UNSPEC_VSTRUCTDUMMY)]
> +   UNSPEC_VST2))]
> +  "TARGET_NEON || TARGET_HAVE_MVE"
> +{
> +  if (TARGET_NEON)
> +emit_insn (gen_neon_vst2 (operands[0], operands[1]));
> +  else
> +emit_insn (gen_mve_vst2q (operands[0], operands[1]));
>DONE;
>  })
> diff --git a/gcc/testsuite/gcc.target/arm/simd/mve-vld2.c
> b/gcc/testsuite/gcc.target/arm/simd/mve-vld2.c
> new file mode 100644
> index 000..9c7c3f5
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/arm/simd/mve-vld2.c
> @@ -0,0 +1,96 @@
> +/* { dg-do assemble } */
> +/* { dg-require-effective-target arm_v8_1m_mve_fp_ok } */
> +/* { dg-add-options arm_v8_1m_mve_fp } */
> +/* { dg-additional-options "-O3" } */
> +
> +#include 
> +
> +#define M00 100
> +#define M10 216
> +#define M01 1322
> +#define M11 13
> +
> +#define N 128
> +
> +
> +/* Integer tests.  */
> +#define FUNC(SIGN, TYPE, BITS)
>   \
> +  void foo_##SIGN##BITS##x (TYPE##BITS##_t *__restrict__ pInput, \
> + TYPE##BITS##_t *__restrict__ pOutput)   \
> +  {  \
> +unsigned int i;  \
> +TYPE##BITS##_t  a, b;\
> + \
> +for (i = 0; i < N / BITS; i++)   \
> +  {  
> \
> + a = *pInput++;  \
> + b = *pInput++;  \
> +  

[PATCH v2] AArch64: Improve GOT addressing

2021-05-24 Thread Wilco Dijkstra via Gcc-patches
Version v2 uses movsi/di for GOT accesses until after reload as suggested. This
caused worse spilling, however improving the costs of GOT accesses resulted in
better codesize and performance gains:

Improve GOT addressing by treating the instructions as a pair.  This reduces
register pressure and improves code quality significantly.  SPECINT2017 improves
by 0.30% with -fPIC and codesize is 0.7% smaller.  Perlbench has 0.9% smaller
codesize, 1.5% fewer executed instructions and is 1.8% faster on Neoverse N1.

Passes bootstrap and regress. OK for commit?

ChangeLog:
2021-05-21  Wilco Dijkstra  

* config/aarch64/aarch64.md (movsi): Split GOT accesses after reload.
(movdi): Likewise.
* config/aarch64/aarch64.c (aarch64_load_symref_appropriately): Delay
splitting of GOT accesses until after reload.
(aarch64_rtx_costs): Set rematerialization cost for GOT accesses.
(aarch64_macro_fusion_pair_p): Fuse GOT accesses.

---

diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index 
641c83b479e76cbcc75b299eb7ae5f634d9db7cd..75b3caa94dd8a52342bbddbfcb73ab06a7418907
 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -3615,6 +3615,14 @@ aarch64_load_symref_appropriately (rtx dest, rtx imm,
 
 case SYMBOL_SMALL_GOT_4G:
   {
+   /* Don't split into ADRP/LDR until after reload - this improves
+  CSE and rematerialization of GOT accesses.  */
+   if (!reload_completed)
+ {
+   emit_insn (gen_rtx_SET (dest, imm));
+   return;
+ }
+
/* In ILP32, the mode of dest can be either SImode or DImode,
   while the got entry is always of SImode size.  The mode of
   dest depends on how dest is used: if dest is assigned to a
@@ -13460,6 +13468,14 @@ cost_plus:
  *cost += COSTS_N_INSNS (1);
  if (speed)
*cost += 2 * extra_cost->alu.arith;
+
+ /* Set a low remateralization cost for GOT accesses - this blocks
+them from being spilled and reduces register pressure.  */
+ if (aarch64_cmodel == AARCH64_CMODEL_SMALL_PIC
+ && aarch64_classify_symbol (x, 0) == SYMBOL_SMALL_GOT_4G)
+   *cost = COSTS_N_INSNS (1) / 2;
+
+ return true;
}
   else if (aarch64_cmodel == AARCH64_CMODEL_TINY
   || aarch64_cmodel == AARCH64_CMODEL_TINY_PIC)
@@ -19930,6 +19946,11 @@ aarch64_mov_operand_p (rtx x, machine_mode mode)
   return aarch64_simd_valid_immediate (x, NULL);
 }
 
+  /* GOT accesses are split after regalloc.  */
+  if (SYMBOL_REF_P (x)
+  && aarch64_classify_symbolic_expression (x) == SYMBOL_SMALL_GOT_4G)
+return true;
+
   x = strip_salt (x);
   if (SYMBOL_REF_P (x) && mode == DImode && CONSTANT_ADDRESS_P (x))
 return true;
@@ -23746,6 +23767,24 @@ aarch_macro_fusion_pair_p (rtx_insn *prev, rtx_insn 
*curr)
 }
 }
 
+  /* Always treat GOT accesses as a pair to ensure they can be easily
+ identified and optimized in linkers.  */
+  if (simple_sets_p)
+{
+  /*  We're trying to match:
+ prev (adrp) == (set (reg r1) (high (symbol_ref ("SYM"
+ curr (add) == (set (reg r0)
+   (unspec [(mem (lo_sum (reg r1) (symbol_ref ("SYM"]
+UNSPEC_GOTSMALLPIC))  */
+
+  if (satisfies_constraint_Ush (SET_SRC (prev_set))
+ && REG_P (SET_DEST (prev_set))
+ && REG_P (SET_DEST (curr_set))
+ && GET_CODE (SET_SRC (curr_set)) == UNSPEC
+ && XINT (SET_SRC (curr_set), 1) == UNSPEC_GOTSMALLPIC)
+   return true;
+}
+
   if (simple_sets_p && aarch64_fusion_enabled_p (AARCH64_FUSE_MOVK_MOVK))
 {
 
diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md
index 
abfd84526745d029ad4953eabad6dd17b159a218..2527c96576a78f2071da20721143a27adeb1551b
 100644
--- a/gcc/config/aarch64/aarch64.md
+++ b/gcc/config/aarch64/aarch64.md
@@ -1283,8 +1283,11 @@ (define_insn_and_split "*movsi_aarch64"
fmov\\t%w0, %s1
fmov\\t%s0, %s1
* return aarch64_output_scalar_simd_mov_immediate (operands[1], SImode);"
-  "CONST_INT_P (operands[1]) && !aarch64_move_imm (INTVAL (operands[1]), 
SImode)
-&& REG_P (operands[0]) && GP_REGNUM_P (REGNO (operands[0]))"
+  "(CONST_INT_P (operands[1]) && !aarch64_move_imm (INTVAL (operands[1]), 
SImode)
+&& REG_P (operands[0]) && GP_REGNUM_P (REGNO (operands[0])))
+|| (reload_completed
+   && (aarch64_classify_symbolic_expression (operands[1])
+   == SYMBOL_SMALL_GOT_4G))"
[(const_int 0)]
"{
aarch64_expand_mov_immediate (operands[0], operands[1]);
@@ -1319,8 +1322,11 @@ (define_insn_and_split "*movdi_aarch64"
fmov\\t%x0, %d1
fmov\\t%d0, %d1
* return aarch64_output_scalar_simd_mov_immediate (operands[1], DImode);"
-   "(CONST_INT_P (operands[1]) && !aarch64_move_imm (INTVAL (operands[1]), 
DImode))
-&& REG_P (operands[0]) && GP_REGNUM_P (REGNO 

Re: [PATCH] Hashtable PR96088

2021-05-24 Thread Jonathan Wakely via Gcc-patches

On 22/05/21 18:35 +0200, François Dumont wrote:

This was indeed the right approach.

    The only minor drawback is that __is_noexcept_invocable<> combines 
noexcept qualification of the conversion and of the hash functor. So 
if the hash functor is not noexcept we could end up creating 
temporaries for nothing.


    So I've eventually used this condition:

__and_<__is_nothrow_invocable<_Hash&, const key_type&>,
         __not_<__is_nothrow_invocable<_Hash&, _Kt>>>::value,

    so that we do not create a temporary key_type if invoking _Hash 
with it can still throw.


    libstdc++: Limit allocation on iterator insertion in Hashtable [PR 
96088]


    When inserting into unordered_multiset or unordered_multimap first 
instantiate
    the node to store and compute the hash code from it to avoid a 
potential

    intermediate key_type instantiation.

    When inserting into unordered_set or unordered_map check if 
invoking the hash
    functor with container key_type is noexcept and invoking the same 
hash functor
    with key part of the iterator value_type can throw. In this case 
create a
    temporary key_type instance at Hashtable level and use it to 
compute the hash
    code. This temporary instance is moved to the final storage 
location if needed.


    libstdc++-v3/ChangeLog:

    PR libstdc++/96088
    * include/bits/hashtable_policy.h (_Select2nd): New.
    (_NodeBuilder<>): New.
    (_ReuseOrAllocNode<>::operator()): Use variadic template args.
    (_AllocNode<>::operator()): Likewise.
    * include/bits/hashtable.h
    (_Hashtable<>::__node_builder_t): New.
(_Hashtable<>::_M_insert_unique<>(_Kt&&, _Arg&&, const _NodeGenerator&)):
 New.
    (_Hashtable<>::_S_forward_key): New.
    (_Hashtable<>::_M_insert): Use latter.
    (_Hashtable<>::_M_insert(const_iterator, _Arg&&, const 
_NodeGenerator&, false_type)):

    Instantiate node first, compute hash code second.
    * testsuite/23_containers/unordered_map/96088.cc: New test.
    * testsuite/23_containers/unordered_multimap/96088.cc: New 
test.
    * testsuite/23_containers/unordered_multiset/96088.cc: New 
test.

    * testsuite/23_containers/unordered_set/96088.cc: New test.
    * testsuite/util/replacement_memory_operators.h
    (counter::_M_increment): New.
    (counter::_M_decrement): New.
    (counter::reset()): New.

Tested under Linux x64.

Ok to commit ?


OK for trunk, thanks.




Re: [PATCH] Hashtable PR96088

2021-05-24 Thread Jonathan Wakely via Gcc-patches

On 24/05/21 11:31 +0200, François Dumont wrote:

On 20/05/21 6:44 pm, Jonathan Wakely wrote:

On 06/05/21 22:03 +0200, François Dumont via Libstdc++ wrote:

Hi

    Considering your feedback on backtrace in debug mode is going 
to take me some time so here is another one.


    Compared to latest submission I've added a _Hash_arg_t partial 
specialization for std::hash<>. It is not strictly necessary for 
the moment but when we will eventually remove its nested 
argument_type it will be. I also wonder if it is not easier to 
handle for the compiler, not sure about that thought.


The std::hash specializations in libstdc++ define argument_type, but
I'm already working on one that doesn't (forstd::stacktrace).

And std::hash can be specialized by users,
and is not required to provide argument_type.

So it's already not valid to assume that std::hash::argument_type
exists.


@@ -850,9 +852,56 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
iterator
_M_emplace(const_iterator, false_type __uks, _Args&&... __args);

+  template
+    std::pair
+    _M_insert_unique(_Kt&&, _Arg&&, const _NodeGenerator&);
+
+  // Detect nested argument_type.
+  template>
+    struct _Hash_arg_t
+    { typedef _Kt argument_type; };
+
+  // std::hash
+  template
+    struct _Hash_arg_t<_Kt, std::hash<_Arg>>
+    { typedef _Arg argument_type; };
+
+  // Nested argument_type.
+  template
+    struct _Hash_arg_t<_Kt, _Ht,
+  __void_t>
+    { typedef typename _Ht::argument_type argument_type; };
+
+  // Function pointer.
+  template
+    struct _Hash_arg_t<_Kt, std::size_t(*)(const _Arg&)>
+    { typedef _Arg argument_type; };
+
+  template::argument_type>
+    static typename conditional<
+  __is_nothrow_convertible<_Kt, _ArgType>::value, _Kt&&, 
key_type>::type


Please use __conditional_t<...> here instead of
typename conditional<...>::type.


I forgot to say in my new proposal that I didn't find the 
__conditional_t. I can see a std::condition_t but only in C++14.


Do you want to add a __conditional_t for C++11 ?


Doh, I forgot that's only in my fork not in the gcc.gnu.org repo.

No need to add it, using typename conditional<>::type is fine here.




Re: [PATCH] C-SKY: Add fpuv3 instructions and CK860 arch.

2021-05-24 Thread Xianmiao Qu

Hi Geng Qi,


I tested this patch but it got the following error when compiling libgcc,

during RTL pass: 
reload/lhome/quxm/build-csky-upstream/source//gcc/libgcc/libgcc2.c: In 
function 
'__mulsc3':/lhome/quxm/build-csky-upstream/source//gcc/libgcc/libgcc2.c:2010:1: 
internal compiler error: maximum number of generated reload insns per 
insn achieved 
(90)/lhome/quxm/build-csky-upstream/source//gcc/libgcc/libgcc2.c: In 
function 
'__divsc3':/lhome/quxm/build-csky-upstream/source//gcc/libgcc/libgcc2.c:2175:1: 
internal compiler error: maximum number of generated reload insns per 
insn achieved (90)


Is it related to the patches you send later? If so, please use [PATCH 
n/m] format to merge them together.



Thanks,

Xianmiao


On 4/30/21 8:21 PM, Geng Qi wrote:

gcc/ChangeLog:

* config/csky/constraints.md ("W"): New constriant for mem operand
with base reg, index register.
("Q"): Renamed and modified "csky_valid_fpuv2_mem_operand" to
"csky_valid_mem_constraint_operand" to deal with both "Q" and "W"
constraint.
("Dv"): New constraint for const double value that can be used at
fmovi instruction.
* config/csky/csky-modes.def (HFmode): New mode.
* config/csky/csky-protos.h (csky_valid_fpuv2_mem_operand): Rename
to "csky_valid_mem_constraint_operand" and new support for constraint
"W".
(csky_get_movedouble_length): New.
(fpuv3_output_move): New.
(fpuv3_const_double): New.
* config/csky/csky.c (csky_option_override): New arch CK860 with fpv3.
(decompose_csky_address): Robustness adjust.
(csky_print_operand): New "CONST_DOUBLE" operand.
(csky_output_move): New support for fpv3 instructions.
(csky_get_movedouble_length): New.
(fpuv3_output_move): New.
(fpuv3_const_double): New.
(csky_emit_compare): New cover for float comparsion.
(csky_emit_compare_float): Refine.
(csky_vaild_fpuv2_mem_operand): Rename to
"csky_valid_mem_constraint_operand" and new support for constraint "W".
(ck860_rtx_costs): New.
(csky_rtx_costs): New subcall for CK860.
(regno_reg_class): New vregs for fpuv3.
(csky_dbx_regno): Likewise.
(csky_cpu_cpp_builtins): New builtin macro for fpuv3.
(csky_conditional_register_usage): New suporrot for fpuv3.
(csky_dwarf_register_span): New suporrot for fpuv3.
(csky_init_builtins, csky_mangle_type): New support for "__fp16" type.
(ck810_legitimate_index_p): New support for fp16.
* gcc/config/csky/csky.h (TARGET_TLS): ADD CK860.
(CSKY_VREG_P, CSKY_VREG_LO_P, CSKY_VREG_HI_P): New support for fpuv3.
(TARGET_SINGLE_FPU): New support for fpuv3.
(TARGET_SUPPORT_FPV3): New macro.
(FIRST_PSEUDO_REGISTER): Value change, since the new fpuv3 regs.
(FIXED_REGISTERS, CALL_REALLY_USED_REGISTERS, REGISTER_NAMES,
 REG_CLASS_CONTENTS): Support for fpuv3.
* gcc/config/csky/csky.md (movsf): Move to cksy_insn_fpu.md and adjust.
(csky_movsf_fpv2): Likewise.
(ck801_movsf): Likewise.
(csky_movsf): Likewise.
(movdf): Likewise.
(csky_movdf_fpv2): Likewise.
(ck801_movdf): Likewise.
(csky_movdf): Likewise.
(movsicc): Refine. Use "comparison_operatior" instead of
"ordered_comparison_operatior".
(addsicc): Likewise.
(CSKY_FIRST_VFP3_REGNUM, CSKY_LAST_VFP3_REGNUM): New constant.
(call_value_internal_vh): New insn.
* config/csky/csky_cores.def (CK860): New arch and cpu.
(fpv3): New 4 fpus: fpv3_hf, fpv3_hsf, fpv3_sdf and fpv3.
* config/csky/csky_insn_fpu.md (mov): Move the float mov
patterns from csky.md here.
(fpuv2 instructions): Refactor. Separate all float patterns into
emit-patterns and match-patterns, remain the emit-patterns here, and
move the match-patterns to csky_insn_fpuv2.md.
(fpuv3 instructions): Add patterns and fuse part of them with the
fpuv2's.
* config/csky/csky_insn_fpuv2.md: New file for fpuv2 instructions.
* config/csky/csky_insn_fpuv3.md: New flie and new patterns for fpuv3
isntructions.
* config/csky/csky_isa.def (fcr): New.
(fpv3): New 4 isa sets: fpv3_hi, fpv3_hf, fpv3_sf and fpv3_df.
(CK860): New definition for ck860.
* gcc/config/csky/csky_tables.opt (ck860): New processors ck860,
ck860f. And new arch ck860.
(fpv3): New 4 fpus: fpv3_hf, fpv3_hsf, fpv3_sdf and fpv3.
* config/csky/predicates.md (csky_float_comparsion_operator): Delete
"geu", "gtu", "leu", "ltu", which will never appear at float comparison.
* config/cksy/t-csky-elf, config/csky/t-csky-linux: New for ck860.
* doc/md.texi: Add "Q" and "W" constraints for C-SKY.
---
  gcc/config/csky/constraints.md |  13 +-
  gcc/config/csky/csky-modes.def 

Re: [PATCH][vect] Use main loop's thresholds and vectorization factor to narrow upper_bound of epilogue

2021-05-24 Thread Richard Sandiford via Gcc-patches
"Andre Vieira (lists)"  writes:
> Hi,
>
> When vectorizing with --param vect-partial-vector-usage=1 the vectorizer 
> uses an unpredicated (all-true predicate for SVE) main loop and a 
> predicated tail loop. The way this was implemented seems to mean it 
> re-uses the same vector-mode for both loops, which means the tail loop 
> isn't an actual loop but only executes one iteration.
>
> This patch uses the knowledge of the conditions to enter an epilogue 
> loop to help come up with a potentially more restricive upper bound.
>
> Regression tested on aarch64-linux-gnu and also ran the testsuite using 
> '--param vect-partial-vector-usage=1' detecting no ICEs and no execution 
> failures.
>
> Would be good to have this tested for PPC too as I believe they are the 
> main users of the --param vect-partial-vector-usage=1 option. Can 
> someone help me test (and maybe even benchmark?) this on a PPC target?
>
> Kind regards,
> Andre

LGTM.  OK if no objections and if the Power testing comes back clean.

Thanks,
Richard

> gcc/ChangeLog:
>
>      * tree-vect-loop.c (vect_transform_loop): Use main loop's 
> various' thresholds
>      to narrow the upper bound on epilogue iterations.
>
> gcc/testsuite/ChangeLog:
>
>      * gcc.target/aarch64/sve/part_vect_single_iter_epilog.c: New test.
>
> diff --git 
> a/gcc/testsuite/gcc.target/aarch64/sve/part_vect_single_iter_epilog.c 
> b/gcc/testsuite/gcc.target/aarch64/sve/part_vect_single_iter_epilog.c
> new file mode 100644
> index 
> ..a03229eb55585f637ebd5288fb4c00f8f921d44c
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/aarch64/sve/part_vect_single_iter_epilog.c
> @@ -0,0 +1,11 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O3 --param vect-partial-vector-usage=1" } */
> +
> +void
> +foo (short * __restrict__ a, short * __restrict__ b, short * __restrict__ c, 
> int n)
> +{
> +  for (int i = 0; i < n; ++i)
> +c[i] = a[i] + b[i];
> +}
> +
> +/* { dg-final { scan-assembler-times {\twhilelo\tp[0-9]+.h, wzr, [xw][0-9]+} 
> 1 } } */
> diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
> index 
> 3e973e774af8f9205be893e01ad9263281116885..81e9c5cc42415a0a92b765bc46640105670c4e6b
>  100644
> --- a/gcc/tree-vect-loop.c
> +++ b/gcc/tree-vect-loop.c
> @@ -9723,12 +9723,31 @@ vect_transform_loop (loop_vec_info loop_vinfo, gimple 
> *loop_vectorized_call)
>/* In these calculations the "- 1" converts loop iteration counts
>   back to latch counts.  */
>if (loop->any_upper_bound)
> -loop->nb_iterations_upper_bound
> -  = (final_iter_may_be_partial
> -  ? wi::udiv_ceil (loop->nb_iterations_upper_bound + bias_for_lowest,
> -   lowest_vf) - 1
> -  : wi::udiv_floor (loop->nb_iterations_upper_bound + bias_for_lowest,
> -lowest_vf) - 1);
> +{
> +  loop_vec_info main_vinfo = LOOP_VINFO_ORIG_LOOP_INFO (loop_vinfo);
> +  loop->nb_iterations_upper_bound
> + = (final_iter_may_be_partial
> +? wi::udiv_ceil (loop->nb_iterations_upper_bound + bias_for_lowest,
> + lowest_vf) - 1
> +: wi::udiv_floor (loop->nb_iterations_upper_bound + bias_for_lowest,
> +  lowest_vf) - 1);
> +  if (main_vinfo)
> + {
> +   unsigned int bound;
> +   poly_uint64 main_iters
> + = upper_bound (LOOP_VINFO_VECT_FACTOR (main_vinfo),
> +LOOP_VINFO_COST_MODEL_THRESHOLD (main_vinfo));
> +   main_iters
> + = upper_bound (main_iters,
> +LOOP_VINFO_VERSIONING_THRESHOLD (main_vinfo));
> +   if (can_div_away_from_zero_p (main_iters,
> + LOOP_VINFO_VECT_FACTOR (loop_vinfo),
> + ))
> + loop->nb_iterations_upper_bound
> +   = wi::umin ((widest_int) (bound - 1),
> +   loop->nb_iterations_upper_bound);
> +  }
> +  }
>if (loop->any_likely_upper_bound)
>  loop->nb_iterations_likely_upper_bound
>= (final_iter_may_be_partial


Re: [PATCH] avoid -Wnonnull with lambda (PR 100684)

2021-05-24 Thread Martin Liška

On 5/20/21 10:03 AM, Richard Biener wrote:

Martin - was this intended?  Can you fix it up please?  (g:cb50701ec2c7)


It was not intentional. Fixed in the attached patch (where I did
a refactoring as well).

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
Martin
>From fa91b695b595d2fa1a6245eafe26a83b7aeb0787 Mon Sep 17 00:00:00 2001
From: Martin Liska 
Date: Mon, 24 May 2021 11:18:21 +0200
Subject: [PATCH] LTO: stream properly FUNCTION_DECL_DECL_TYPE.

gcc/lto/ChangeLog:

	* lto-common.c (compare_tree_sccs_1): Compare
	FUNCTION_DECL_DECL_TYPE.

gcc/ChangeLog:

	* tree-streamer-in.c (unpack_ts_function_decl_value_fields):
	Unpack FUNCTION_DECL_DECL_TYPE.
	* tree-streamer-out.c (pack_ts_function_decl_value_fields):
	Stream FUNCTION_DECL_DECL_TYPE instead of
	DECL_IS_OPERATOR_NEW_P.
	* tree.h (set_function_decl_type): Use FUNCTION_DECL_DECL_TYPE
	macro.
	(DECL_IS_OPERATOR_NEW_P): Likewise.
	(DECL_IS_OPERATOR_DELETE_P): Likewise.
	(DECL_LAMBDA_FUNCTION_P): Likewise.
---
 gcc/lto/lto-common.c| 2 +-
 gcc/tree-streamer-in.c  | 2 +-
 gcc/tree-streamer-out.c | 2 +-
 gcc/tree.h  | 8 
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/gcc/lto/lto-common.c b/gcc/lto/lto-common.c
index 02d16f49c11..bfe52a2e942 100644
--- a/gcc/lto/lto-common.c
+++ b/gcc/lto/lto-common.c
@@ -1235,7 +1235,7 @@ compare_tree_sccs_1 (tree t1, tree t2, tree **map)
   compare_values (DECL_IS_NOVOPS);
   compare_values (DECL_IS_RETURNS_TWICE);
   compare_values (DECL_IS_MALLOC);
-  compare_values (DECL_IS_OPERATOR_NEW_P);
+  compare_values (FUNCTION_DECL_DECL_TYPE);
   compare_values (DECL_DECLARED_INLINE_P);
   compare_values (DECL_STATIC_CHAIN);
   compare_values (DECL_NO_INLINE_WARNING_P);
diff --git a/gcc/tree-streamer-in.c b/gcc/tree-streamer-in.c
index 984b1e269cf..e0522bf2ac1 100644
--- a/gcc/tree-streamer-in.c
+++ b/gcc/tree-streamer-in.c
@@ -333,7 +333,7 @@ unpack_ts_function_decl_value_fields (struct bitpack_d *bp, tree expr)
   DECL_IS_NOVOPS (expr) = (unsigned) bp_unpack_value (bp, 1);
   DECL_IS_RETURNS_TWICE (expr) = (unsigned) bp_unpack_value (bp, 1);
   DECL_IS_MALLOC (expr) = (unsigned) bp_unpack_value (bp, 1);
-  DECL_SET_IS_OPERATOR_NEW (expr, (unsigned) bp_unpack_value (bp, 1));
+  FUNCTION_DECL_DECL_TYPE (expr) = (function_decl_type) bp_unpack_value (bp, 2);
   DECL_SET_IS_OPERATOR_DELETE (expr, (unsigned) bp_unpack_value (bp, 1));
   DECL_DECLARED_INLINE_P (expr) = (unsigned) bp_unpack_value (bp, 1);
   DECL_STATIC_CHAIN (expr) = (unsigned) bp_unpack_value (bp, 1);
diff --git a/gcc/tree-streamer-out.c b/gcc/tree-streamer-out.c
index 1a43534d117..855d1cd59b9 100644
--- a/gcc/tree-streamer-out.c
+++ b/gcc/tree-streamer-out.c
@@ -298,7 +298,7 @@ pack_ts_function_decl_value_fields (struct bitpack_d *bp, tree expr)
   bp_pack_value (bp, DECL_IS_NOVOPS (expr), 1);
   bp_pack_value (bp, DECL_IS_RETURNS_TWICE (expr), 1);
   bp_pack_value (bp, DECL_IS_MALLOC (expr), 1);
-  bp_pack_value (bp, DECL_IS_OPERATOR_NEW_P (expr), 1);
+  bp_pack_value (bp, FUNCTION_DECL_DECL_TYPE (expr), 2);
   bp_pack_value (bp, DECL_IS_OPERATOR_DELETE_P (expr), 1);
   bp_pack_value (bp, DECL_DECLARED_INLINE_P (expr), 1);
   bp_pack_value (bp, DECL_STATIC_CHAIN (expr), 1);
diff --git a/gcc/tree.h b/gcc/tree.h
index 37aca8963fe..143311a2071 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -3106,7 +3106,7 @@ set_function_decl_type (tree decl, function_decl_type t, bool set)
 {
   gcc_assert (FUNCTION_DECL_DECL_TYPE (decl) == NONE
 		  || FUNCTION_DECL_DECL_TYPE (decl) == t);
-  decl->function_decl.decl_type = t;
+  FUNCTION_DECL_DECL_TYPE (decl) = t;
 }
   else if (FUNCTION_DECL_DECL_TYPE (decl) == t)
 FUNCTION_DECL_DECL_TYPE (decl) = NONE;
@@ -3121,7 +3121,7 @@ set_function_decl_type (tree decl, function_decl_type t, bool set)
C++ operator new, meaning that it returns a pointer for which we
should not use type based aliasing.  */
 #define DECL_IS_OPERATOR_NEW_P(NODE) \
-  (FUNCTION_DECL_CHECK (NODE)->function_decl.decl_type == OPERATOR_NEW)
+  (FUNCTION_DECL_DECL_TYPE (FUNCTION_DECL_CHECK (NODE)) == OPERATOR_NEW)
 
 #define DECL_IS_REPLACEABLE_OPERATOR_NEW_P(NODE) \
   (DECL_IS_OPERATOR_NEW_P (NODE) && DECL_IS_REPLACEABLE_OPERATOR (NODE))
@@ -3132,7 +3132,7 @@ set_function_decl_type (tree decl, function_decl_type t, bool set)
 /* Nonzero in a FUNCTION_DECL means this function should be treated as
C++ operator delete.  */
 #define DECL_IS_OPERATOR_DELETE_P(NODE) \
-  (FUNCTION_DECL_CHECK (NODE)->function_decl.decl_type == OPERATOR_DELETE)
+  (FUNCTION_DECL_DECL_TYPE (FUNCTION_DECL_CHECK (NODE)) == OPERATOR_DELETE)
 
 #define DECL_SET_IS_OPERATOR_DELETE(NODE, VAL) \
   set_function_decl_type (FUNCTION_DECL_CHECK (NODE), OPERATOR_DELETE, VAL)
@@ -3283,7 +3283,7 @@ extern vec **decl_debug_args_insert (tree);
 
 /* In FUNCTION_DECL, this is set if this function is a lambda function.  */
 #define 

[PATCH] Extend is_cond_scalar_reduction to handle nop_expr after/before scalar reduction.[PR98365]

2021-05-24 Thread Hongtao Liu via Gcc-patches
Hi:
  Details described in PR.
  Bootstrapped and regtest on
x86_64-linux-gnu{-m32,}/x86_64-linux-gnu{-m32\
-march=cascadelake,-march=cascadelake}
  Ok for trunk?

  gcc/ChangeLog:

PR tree-optimization/pr98365
* tree-if-conv.c (strip_nop_cond_scalar_reduction): New function.
(is_cond_scalar_reduction): Handle nop_expr in cond scalar reduction.
(convert_scalar_cond_reduction): Ditto.
(predicate_scalar_phi): Ditto.

gcc/testsuite/ChangeLog:

PR tree-optimization/pr98365
* gcc.target/i386/pr98365.c: New test.

-- 
BR,
Hongtao
From 0248efe310454a31e4bbeb1430f907ec663c39ae Mon Sep 17 00:00:00 2001
From: liuhongt 
Date: Wed, 6 Jan 2021 16:33:27 +0800
Subject: [PATCH] Extend is_cond_scalar_reduction to handle nop_expr
 after/before scalar reduction.[PR98365]

gcc/ChangeLog:

	PR tree-optimization/pr98365
	* tree-if-conv.c (strip_nop_cond_scalar_reduction): New function.
	(is_cond_scalar_reduction): Handle nop_expr in cond scalar reduction.
	(convert_scalar_cond_reduction): Ditto.
	(predicate_scalar_phi): Ditto.

gcc/testsuite/ChangeLog:

	PR tree-optimization/pr98365
	* gcc.target/i386/pr98365.c: New test.
---
 gcc/testsuite/gcc.target/i386/pr98365.c |  22 
 gcc/tree-if-conv.c  | 131 +---
 2 files changed, 141 insertions(+), 12 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr98365.c

diff --git a/gcc/testsuite/gcc.target/i386/pr98365.c b/gcc/testsuite/gcc.target/i386/pr98365.c
new file mode 100644
index 000..652210dcdd5
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr98365.c
@@ -0,0 +1,22 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mavx2 -ftree-vectorize -fdump-tree-vect-details" } */
+/* { dg-final { scan-tree-dump-times "vectorized \[1-3] loops" 2 "vect" } } */
+short foo1 (short* a, short* c, int n)
+{
+  int i;
+  short cnt=0;
+  for (int i = 0;i != n; i++)
+if (a[i] == c[i])
+  cnt++;
+  return cnt;
+}
+
+char foo2 (char* a, char* c, int n)
+{
+  int i;
+  char cnt=0;
+  for (int i = 0;i != n; i++)
+if (a[i] == c[i])
+  cnt++;
+  return cnt;
+}
diff --git a/gcc/tree-if-conv.c b/gcc/tree-if-conv.c
index 716eae44a21..5811eb00478 100644
--- a/gcc/tree-if-conv.c
+++ b/gcc/tree-if-conv.c
@@ -1579,6 +1579,31 @@ if_convertible_loop_p (class loop *loop)
   return res;
 }
 
+/* Return reduc_1 if has_nop.
+
+   if (...)
+ tmp1 = (unsigned type) reduc_1;
+ tmp2 = tmp1 + rhs2;
+ reduc_3 = (signed type) tmp2.  */
+static tree
+strip_nop_cond_scalar_reduction (bool has_nop, tree op)
+{
+  if (!has_nop)
+return op;
+
+  if (TREE_CODE (op) != SSA_NAME)
+return NULL_TREE;
+
+  gimple* stmt = SSA_NAME_DEF_STMT (op);
+  if (!stmt
+  || gimple_code (stmt) != GIMPLE_ASSIGN
+  || gimple_has_volatile_ops (stmt)
+  || gimple_assign_rhs_code (stmt) != NOP_EXPR)
+return NULL_TREE;
+
+  return gimple_assign_rhs1 (stmt);
+}
+
 /* Returns true if def-stmt for phi argument ARG is simple increment/decrement
which is in predicated basic block.
In fact, the following PHI pattern is searching:
@@ -1595,9 +1620,10 @@ if_convertible_loop_p (class loop *loop)
 
 static bool
 is_cond_scalar_reduction (gimple *phi, gimple **reduc, tree arg_0, tree arg_1,
-			  tree *op0, tree *op1, bool extended)
+			  tree *op0, tree *op1, bool extended, bool* has_nop,
+			  gimple **nop_reduc)
 {
-  tree lhs, r_op1, r_op2;
+  tree lhs, r_op1, r_op2, r_nop1, r_nop2;
   gimple *stmt;
   gimple *header_phi = NULL;
   enum tree_code reduction_op;
@@ -1608,7 +1634,7 @@ is_cond_scalar_reduction (gimple *phi, gimple **reduc, tree arg_0, tree arg_1,
   use_operand_p use_p;
   edge e;
   edge_iterator ei;
-  bool result = false;
+  bool result = *has_nop = false;
   if (TREE_CODE (arg_0) != SSA_NAME || TREE_CODE (arg_1) != SSA_NAME)
 return false;
 
@@ -1656,18 +1682,78 @@ is_cond_scalar_reduction (gimple *phi, gimple **reduc, tree arg_0, tree arg_1,
 return false;
 
   reduction_op = gimple_assign_rhs_code (stmt);
+
+/* Catch something like below
+
+ loop-header:
+ reduc_1 = PHI <..., reduc_2>
+ ...
+ if (...)
+ tmp1 = (unsigned type) reduc_1;
+ tmp2 = tmp1 + rhs2;
+ reduc_3 = (signed type) tmp2;
+
+ reduc_2 = PHI 
+
+ and convert to
+
+ reduc_2 = PHI <0, reduc_3>
+ tmp1 = (unsigned type)reduce_1;
+ ifcvt = cond_expr ? rhs2 : 0
+ tmp2 = tmp1 +/- ifcvt;
+ reduce_1 = (signed type)tmp2;  */
+
+  if (reduction_op == NOP_EXPR)
+{
+  lhs = gimple_assign_rhs1 (stmt);
+  if (TREE_CODE (lhs) != SSA_NAME
+	  || !has_single_use (lhs))
+	return false;
+
+  *nop_reduc = stmt;
+  stmt = SSA_NAME_DEF_STMT (lhs);
+  if (gimple_bb (stmt) != gimple_bb (*nop_reduc)
+	  || gimple_code (stmt) != GIMPLE_ASSIGN
+	  || gimple_has_volatile_ops (stmt))
+	return false;
+
+  *has_nop = true;
+  reduction_op = gimple_assign_rhs_code (stmt);
+}
+
   if (reduction_op != PLUS_EXPR && reduction_op != 

[PATCH] [i386] Support avx512 vector shift with vector [PR98434]

2021-05-24 Thread Hongtao Liu via Gcc-patches
Hi:
  This patch is about to add expanders for vashl,
vlshr,
vashr and vashr.

Besides there's some assumption in expand_mult_const that mul and
add must be available at the same time, but for i386, addv8qi is
restricted under TARGET_64BIT, but mulv8qi not, that could cause ICE.
So restrict mulv8qi and shiftv8qi under TARGET_64BIT.
  Bootstrap and regtested on x86_64-linux-gnu{-m32,} and
x86_64-linux-gnu{-m32\ -march=cascadelake,-march=cascadelake}

gcc/ChangeLog:

PR target/98434
* config/i386/i386-expand.c (ix86_expand_vec_interleave):
Adjust comments for ix86_expand_vecop_qihi2.
(ix86_expand_vecmul_qihi): Renamed to ..
(ix86_expand_vecop_qihi2): Adjust function prototype to
support shift operation, add static to definition.
(ix86_expand_vec_shift_qihi_constant): Add static to definition.
(ix86_expand_vecop_qihi): Call ix86_expand_vecop_qihi2 and
ix86_expand_vec_shift_qihi_constant.
* config/i386/i386-protos.h (ix86_expand_vecmul_qihi): Deleted.
(ix86_expand_vec_shift_qihi_constant): Deleted.
* config/i386/sse.md (mulv8qi3): Call ix86_expand_vecop_qihi
directly, add condition TARGET_64BIT.
(mul3): Ditto.
(3): Ditto.
(vlshr3): Extend to support avx512 vlshr.
(v3): New expander for
vashr/vlshr/vashl.
(vv8qi3): Ditto.
(vashrv8hi3): Renamed to ..
(vashr3): And extend to support V16QImode for avx512.
(vashrv16qi3): Deleted.
(vashrv2di3): Extend expander to support avx512
instruction.

gcc/testsuite/ChangeLog:

PR target/98434
* gcc.target/i386/pr98434-1.c: New test.
* gcc.target/i386/pr98434-2.c: New test.
* gcc.target/i386/avx512vl-pr95488-1.c: Adjust testcase.
From 4c423a49dd1af5b0808a89c356f94454dde8109f Mon Sep 17 00:00:00 2001
From: liuhongt 
Date: Tue, 26 Jan 2021 16:29:32 +0800
Subject: [PATCH] i386: Add missing expander for vector/vector shift [PR98434]

Add expanders for vashl, vlshr,
vashr and vashr.

Besides there's some assumption in expand_mult_const that mul and
add must be available at the same time, but for i386, addv8qi is
restricted under TARGET_64BIT, but mulv8qi not, that could cause ICE.
So restrict mulv8qi and shiftv8qi under TARGET_64BIT.

gcc/ChangeLog:

	PR target/98434
	* config/i386/i386-expand.c (ix86_expand_vec_interleave):
	Adjust comments for ix86_expand_vecop_qihi2.
	(ix86_expand_vecmul_qihi): Renamed to ..
	(ix86_expand_vecop_qihi2): Adjust function prototype to
	support shift operation, add static to definition.
	(ix86_expand_vec_shift_qihi_constant): Add static to definition.
	(ix86_expand_vecop_qihi): Call ix86_expand_vecop_qihi2 and
	ix86_expand_vec_shift_qihi_constant.
	* config/i386/i386-protos.h (ix86_expand_vecmul_qihi): Deleted.
	(ix86_expand_vec_shift_qihi_constant): Deleted.
	* config/i386/sse.md (mulv8qi3): Call ix86_expand_vecop_qihi
	directly, add condition TARGET_64BIT.
	(mul3): Ditto.
	(3): Ditto.
	(vlshr3): Extend to support avx512 vlshr.
	(v3): New expander for
	vashr/vlshr/vashl.
	(vv8qi3): Ditto.
	(vashrv8hi3): Renamed to ..
	(vashr3): And extend to support V16QImode for avx512.
	(vashrv16qi3): Deleted.
	(vashrv2di3): Extend expander to support avx512
	instruction.

gcc/testsuite/ChangeLog:

	PR target/98434
	* gcc.target/i386/pr98434-1.c: New test.
	* gcc.target/i386/pr98434-2.c: New test.
	* gcc.target/i386/avx512vl-pr95488-1.c: Adjust testcase.
---
 gcc/config/i386/i386-expand.c |  73 +++---
 gcc/config/i386/i386-protos.h |   3 -
 gcc/config/i386/sse.md| 111 ++-
 .../gcc.target/i386/avx512vl-pr95488-1.c  |   6 +-
 gcc/testsuite/gcc.target/i386/pr98434-1.c |  64 +
 gcc/testsuite/gcc.target/i386/pr98434-2.c | 131 ++
 6 files changed, 331 insertions(+), 57 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr98434-1.c
 create mode 100644 gcc/testsuite/gcc.target/i386/pr98434-2.c

diff --git a/gcc/config/i386/i386-expand.c b/gcc/config/i386/i386-expand.c
index 9f3d41955a2..fba6c666769 100644
--- a/gcc/config/i386/i386-expand.c
+++ b/gcc/config/i386/i386-expand.c
@@ -20377,8 +20377,9 @@ ix86_expand_vec_interleave (rtx targ, rtx op0, rtx op1, bool high_p)
   gcc_assert (ok);
 }
 
-/* Optimize vector MUL generation for V8QI, V16QI and V32QI
-   under TARGET_AVX512BW. i.e. for v16qi a * b, it has
+/* This function is similar as ix86_expand_vecop_qihi,
+   but optimized under AVX512BW by using vpmovwb.
+   For example, optimize vector MUL generation like
 
vpmovzxbw ymm2, xmm0
vpmovzxbw ymm3, xmm1
@@ -20388,13 +20389,14 @@ ix86_expand_vec_interleave (rtx targ, rtx op0, rtx op1, bool high_p)
it would take less instructions than ix86_expand_vecop_qihi.
Return true if success.  */
 
-bool
-ix86_expand_vecmul_qihi (rtx dest, rtx op1, rtx op2)
+static bool
+ix86_expand_vecop_qihi2 (enum rtx_code code, rtx dest, 

Re: [PATCH] Hashtable PR96088

2021-05-24 Thread François Dumont via Gcc-patches

On 20/05/21 6:44 pm, Jonathan Wakely wrote:

On 06/05/21 22:03 +0200, François Dumont via Libstdc++ wrote:

Hi

    Considering your feedback on backtrace in debug mode is going to 
take me some time so here is another one.


    Compared to latest submission I've added a _Hash_arg_t partial 
specialization for std::hash<>. It is not strictly necessary for the 
moment but when we will eventually remove its nested argument_type it 
will be. I also wonder if it is not easier to handle for the 
compiler, not sure about that thought.


The std::hash specializations in libstdc++ define argument_type, but
I'm already working on one that doesn't (forstd::stacktrace).

And std::hash can be specialized by users,
and is not required to provide argument_type.

So it's already not valid to assume that std::hash::argument_type
exists.


@@ -850,9 +852,56 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
iterator
_M_emplace(const_iterator, false_type __uks, _Args&&... __args);

+  template
+    std::pair
+    _M_insert_unique(_Kt&&, _Arg&&, const _NodeGenerator&);
+
+  // Detect nested argument_type.
+  template>
+    struct _Hash_arg_t
+    { typedef _Kt argument_type; };
+
+  // std::hash
+  template
+    struct _Hash_arg_t<_Kt, std::hash<_Arg>>
+    { typedef _Arg argument_type; };
+
+  // Nested argument_type.
+  template
+    struct _Hash_arg_t<_Kt, _Ht,
+  __void_t>
+    { typedef typename _Ht::argument_type argument_type; };
+
+  // Function pointer.
+  template
+    struct _Hash_arg_t<_Kt, std::size_t(*)(const _Arg&)>
+    { typedef _Arg argument_type; };
+
+  template::argument_type>
+    static typename conditional<
+  __is_nothrow_convertible<_Kt, _ArgType>::value, _Kt&&, 
key_type>::type


Please use __conditional_t<...> here instead of
typename conditional<...>::type.


I forgot to say in my new proposal that I didn't find the 
__conditional_t. I can see a std::condition_t but only in C++14.


Do you want to add a __conditional_t for C++11 ?




[PATCH] rs6000: Remove unspecs for vec_mrghl[bhw]

2021-05-24 Thread Xionghu Luo via Gcc-patches
From: Xiong Hu Luo 

vmrghb only accepts permute index {0, 16, 1, 17, 2, 18, 3, 19, 4, 20,
5, 21, 6, 22, 7, 23} no matter for BE or LE in ISA, similarly for vmrghlb.
Remove UNSPEC_VMRGH_DIRECT/UNSPEC_VMRGL_DIRECT pattern as vec_select
+ vec_concat as normal RTL.

Tested pass on P8LE, P9LE and P8BE{m32}, ok for trunk?

gcc/ChangeLog:

* config/rs6000/altivec.md (*altivec_vmrghb_internal): Delete.
(altivec_vmrghb_direct): New.
(*altivec_vmrghh_internal): Delete.
(altivec_vmrghh_direct): New.
(*altivec_vmrghw_internal): Delete.
(altivec_vmrghw_direct_): New.
(altivec_vmrghw_direct): Delete.
(*altivec_vmrglb_internal): Delete.
(altivec_vmrglb_direct): New.
(*altivec_vmrglh_internal): Delete.
(altivec_vmrglh_direct): New.
(*altivec_vmrglw_internal): Delete.
(altivec_vmrglw_direct_): New.
(altivec_vmrglw_direct): Delete.
* config/rs6000/rs6000-p8swap.c (rtx_is_swappable_p): Adjust.
* config/rs6000/rs6000.c (altivec_expand_vec_perm_const):
Adjust.
* config/rs6000/vsx.md (vsx_xxmrghw_): Adjust.
(vsx_xxmrglw_):

gcc/testsuite/ChangeLog:

* gcc.target/powerpc/builtins-1.c: Update instruction counts.
---
 gcc/config/rs6000/altivec.md  | 231 ++
 gcc/config/rs6000/rs6000-p8swap.c |   2 -
 gcc/config/rs6000/rs6000.c|  10 +-
 gcc/config/rs6000/vsx.md  |  18 +-
 gcc/testsuite/gcc.target/powerpc/builtins-1.c |   8 +-
 5 files changed, 95 insertions(+), 174 deletions(-)

diff --git a/gcc/config/rs6000/altivec.md b/gcc/config/rs6000/altivec.md
index 208d6343225..cae05be2c2d 100644
--- a/gcc/config/rs6000/altivec.md
+++ b/gcc/config/rs6000/altivec.md
@@ -143,8 +143,6 @@ (define_c_enum "unspec"
UNSPEC_VUPKHU_V4SF
UNSPEC_VUPKLU_V4SF
UNSPEC_VGBBD
-   UNSPEC_VMRGH_DIRECT
-   UNSPEC_VMRGL_DIRECT
UNSPEC_VSPLT_DIRECT
UNSPEC_VMRGEW_DIRECT
UNSPEC_VMRGOW_DIRECT
@@ -1291,44 +1289,29 @@ (define_expand "altivec_vmrghb"
(use (match_operand:V16QI 2 "register_operand"))]
   "TARGET_ALTIVEC"
 {
-  rtvec v = gen_rtvec (16, GEN_INT (0), GEN_INT (16), GEN_INT (1), GEN_INT 
(17),
-  GEN_INT (2), GEN_INT (18), GEN_INT (3), GEN_INT (19),
-  GEN_INT (4), GEN_INT (20), GEN_INT (5), GEN_INT (21),
-  GEN_INT (6), GEN_INT (22), GEN_INT (7), GEN_INT (23));
-  rtx x = gen_rtx_VEC_CONCAT (V32QImode, operands[1], operands[2]);
-  x = gen_rtx_VEC_SELECT (V16QImode, x, gen_rtx_PARALLEL (VOIDmode, v));
-  emit_insn (gen_rtx_SET (operands[0], x));
+  if (BYTES_BIG_ENDIAN)
+emit_insn (
+  gen_altivec_vmrghb_direct (operands[0], operands[1], operands[2]));
+  else
+emit_insn (
+  gen_altivec_vmrglb_direct (operands[0], operands[2], operands[1]));
   DONE;
 })
 
-(define_insn "*altivec_vmrghb_internal"
+(define_insn "altivec_vmrghb_direct"
   [(set (match_operand:V16QI 0 "register_operand" "=v")
-(vec_select:V16QI
+(vec_select:V16QI
  (vec_concat:V32QI
(match_operand:V16QI 1 "register_operand" "v")
(match_operand:V16QI 2 "register_operand" "v"))
- (parallel [(const_int 0) (const_int 16)
-(const_int 1) (const_int 17)
-(const_int 2) (const_int 18)
-(const_int 3) (const_int 19)
-(const_int 4) (const_int 20)
-(const_int 5) (const_int 21)
-(const_int 6) (const_int 22)
-(const_int 7) (const_int 23)])))]
-  "TARGET_ALTIVEC"
-{
-  if (BYTES_BIG_ENDIAN)
-return "vmrghb %0,%1,%2";
-  else
-return "vmrglb %0,%2,%1";
-}
-  [(set_attr "type" "vecperm")])
-
-(define_insn "altivec_vmrghb_direct"
-  [(set (match_operand:V16QI 0 "register_operand" "=v")
-   (unspec:V16QI [(match_operand:V16QI 1 "register_operand" "v")
-  (match_operand:V16QI 2 "register_operand" "v")]
- UNSPEC_VMRGH_DIRECT))]
+ (parallel [(const_int  0) (const_int 16)
+(const_int  1) (const_int 17)
+(const_int  2) (const_int 18)
+(const_int  3) (const_int 19)
+(const_int  4) (const_int 20)
+(const_int  5) (const_int 21)
+(const_int  6) (const_int 22)
+(const_int  7) (const_int 23)])))]
   "TARGET_ALTIVEC"
   "vmrghb %0,%1,%2"
   [(set_attr "type" "vecperm")])
@@ -1339,16 +1322,16 @@ (define_expand "altivec_vmrghh"
(use (match_operand:V8HI 2 "register_operand"))]
   "TARGET_ALTIVEC"
 {
-  rtvec v = gen_rtvec (8, GEN_INT (0), GEN_INT (8), GEN_INT (1), GEN_INT (9),
-  GEN_INT (2), GEN_INT (10), GEN_INT (3), GEN_INT (11));
-  rtx x = gen_rtx_VEC_CONCAT (V16HImode, operands[1], operands[2]);
-
-  x = gen_rtx_VEC_SELECT (V8HImode, x, gen_rtx_PARALLEL (VOIDmode, v));
-  

Re: RFA: save/restore target options in handle_optimize_attribute

2021-05-24 Thread Martin Liška

On 5/20/21 9:55 AM, Richard Biener wrote:

On Thu, May 20, 2021 at 12:29 AM Joern Wolfgang Rennecke
 wrote:


We set default for some target options in TARGET_OPTION_OPTIMIZATION_TABLE,
but these can be overridden by specifying the corresponding explicit
-mXXX / -mno-XXX options.
When a function bears the attribue
__attribute__ ((optimize("02")))
the target options are set to the default for that optimization level,
which can be different from what was selected for the file as a whole.
As handle_optimize_attribute is right now, it will thus clobber the
target options, and with enable_checking it will then abort.

The attached patch makes it save and restore the target options.

Bootstrapped and regression tested on x86_64-pc-linux-gnu.


Interesting, I prepared very similar patch for this stage1. My patch covers few 
more
cases where target options interfere with optimize options (and vice versa).



That looks reasonable but of course it doesn't solve the issue that those
altered target options will not be in effect on the optimize("O2") function.

IIRC Martin has changes in the works to unify target & optimize here
which should obsolete this fix.  Martin - what's the state of this?  Do you
think this patch makes sense in the mean time (and maybe also on
the branch though the assert is not in effect there but the behavior
is still observed and unexpected).


Well, I really tried doing the merge but I failed. It's pretty huge task and I 
was
unable to get something reasonable for x86_64 target :/ However, my patch 
mitigates
2 more cases.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
Martin



Thanks,
Richard.



>From 156fb01d35ab6222719d260e0fb3386d53f314b0 Mon Sep 17 00:00:00 2001
From: Martin Liska 
Date: Wed, 10 Mar 2021 15:12:31 +0100
Subject: [PATCH] Improve global state for options.

gcc/c-family/ChangeLog:

	PR tree-optimization/92860
	PR target/99592
	* c-attribs.c (handle_optimize_attribute): Save target node
	before calling parse_optimize_options and save it in case
	it changes.
	* c-pragma.c (handle_pragma_target): Similarly for pragma.
	(handle_pragma_pop_options): Likewise here.

gcc/ChangeLog:

	PR tree-optimization/92860
	PR target/99592
	* optc-save-gen.awk: Remove exceptions.
---
 gcc/c-family/c-attribs.c |  9 +
 gcc/c-family/c-pragma.c  | 16 
 gcc/optc-save-gen.awk|  9 -
 3 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c
index ccf9e4ccf0b..96305250d98 100644
--- a/gcc/c-family/c-attribs.c
+++ b/gcc/c-family/c-attribs.c
@@ -5363,6 +5363,8 @@ handle_optimize_attribute (tree *node, tree name, tree args,
 
   /* Save current options.  */
   cl_optimization_save (_opts, _options, _options_set);
+  tree prev_target_node = build_target_option_node (_options,
+			_options_set);
 
   /* If we previously had some optimization options, use them as the
 	 default.  */
@@ -5381,10 +5383,17 @@ handle_optimize_attribute (tree *node, tree name, tree args,
   parse_optimize_options (args, true);
   DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node)
 	= build_optimization_node (_options, _options_set);
+  tree target_node = build_target_option_node (_options,
+		   _options_set);
+  if (prev_target_node != target_node)
+	DECL_FUNCTION_SPECIFIC_TARGET (*node) = target_node;
 
   /* Restore current options.  */
   cl_optimization_restore (_options, _options_set,
 			   _opts);
+  cl_target_option_restore (_options, _options_set,
+TREE_TARGET_OPTION (prev_target_node));
+
   if (saved_global_options != NULL)
 	{
 	  cl_optimization_compare (saved_global_options, _options);
diff --git a/gcc/c-family/c-pragma.c b/gcc/c-family/c-pragma.c
index 4f8e8e0128c..7f658ea5646 100644
--- a/gcc/c-family/c-pragma.c
+++ b/gcc/c-family/c-pragma.c
@@ -918,6 +918,12 @@ handle_pragma_target(cpp_reader *ARG_UNUSED(dummy))
 
   if (targetm.target_option.pragma_parse (args, NULL_TREE))
 	current_target_pragma = chainon (current_target_pragma, args);
+
+  /* A target pragma can also influence optimization options. */
+  tree current_optimize
+	= build_optimization_node (_options, _options_set);
+  if (current_optimize != optimization_current_node)
+	optimization_current_node = current_optimize;
 }
 }
 
@@ -1078,12 +1084,14 @@ handle_pragma_pop_options (cpp_reader *ARG_UNUSED(dummy))
   target_option_current_node = p->target_binary;
 }
 
+  /* Always restore optimization options as optimization_current_node is
+   * overwritten by invoke_set_current_function_hook.  */
+  cl_optimization_restore (_options, _options_set,
+			   TREE_OPTIMIZATION (p->optimize_binary));
+
   if (p->optimize_binary != optimization_current_node)
 {
-  tree old_optimize = optimization_current_node;
-  cl_optimization_restore (_options, _options_set,
-			   TREE_OPTIMIZATION 

Re: [PATCH] lto-dump : Fix an ICE when lto-dump try to call 'get_size()' on thunk symbols.

2021-05-24 Thread Martin Liška

On 5/21/21 12:25 PM, 王留帅 via Gcc-patches wrote:

|Hi, ​ We, ByteDance, have seen an ICE on trunk which can be reproduced with the 
following symbol testcase. The problem is caused by referencing a null pointer 
when applying 'n_basic_blocks_for_fn' on a thunk symbol. For the thunk symbol, 
'DECL_STRUCT_FUNCTION (cnode->decl)' will return an empty pointer. ​|


Hello.

Thank you for the patch, I've just installed the patch
as 
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=0f3cd532fa02d1787960bdd380d0a3f78343f024

Thanks,
Martin


Re: [PATCH] Add no_sanitize_coverage attribute.

2021-05-24 Thread Marco Elver via Gcc-patches
On Mon, 24 May 2021 at 10:03, Martin Liška  wrote:
> On 5/21/21 2:39 PM, Marco Elver wrote:
> > On Fri, May 21, 2021 at 10:50AM +0200, Martin Liška wrote:
> >> On 5/20/21 12:55 PM, Marco Elver wrote:
> >>> I think this came up with other no_sanitize [1] based on what I had
> >>> written to you last year [2].
> >>>
> >>> [1]https://gcc.gnu.org/pipermail/gcc-patches/2020-June/547618.html
> >>> [2]https://lore.kernel.org/lkml/canpmjnnrz5ovkb6pe7k6gjfogbht_zhypkng9ad+kjndzk7...@mail.gmail.com/
> >>
> >> Ah, you're right. I've just updated the patch to address that.
> >>
> >> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
> >>
> >> Ready to be installed?
> >
> > Looks good, I also just built a kernel with the no_sanitize_coverage
> > attribute (without the objtool nop-workaround) and works as expected.
>
> Good, thanks!
>
> >
> > Not sure if required, but would such an additional test be useful:
>
> Yes, it is, thanks for it.
[...]
> > Otherwise, please go ahead. I assume this is targeting GCC 12?
>
> Yep.
>
> There's V3 I'm sending.
>
> Ready for master?

>From my side this looks good. Thank you!

-- Marco


Re: [PATCH] Try LTO partial linking. (Was: Speed of compiling gimple-match.c)

2021-05-24 Thread Martin Liška

On 5/21/21 2:35 PM, David Edelsohn wrote:

Please remember that not all targets support LTO so a fallback to a
non-partial-LTO build needs to be provided and automatically invoked
for those targets.


Sure, for now it's definitely going to be a opt-in, enabled by something like:
make PARTIAL_LTO=1.

Thanks,
Martin


Re: [PATCH] Add no_sanitize_coverage attribute.

2021-05-24 Thread Martin Liška

On 5/21/21 2:39 PM, Marco Elver wrote:

On Fri, May 21, 2021 at 10:50AM +0200, Martin Liška wrote:

On 5/20/21 12:55 PM, Marco Elver wrote:

I think this came up with other no_sanitize [1] based on what I had
written to you last year [2].

[1]https://gcc.gnu.org/pipermail/gcc-patches/2020-June/547618.html
[2]https://lore.kernel.org/lkml/canpmjnnrz5ovkb6pe7k6gjfogbht_zhypkng9ad+kjndzk7...@mail.gmail.com/


Ah, you're right. I've just updated the patch to address that.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?


Looks good, I also just built a kernel with the no_sanitize_coverage
attribute (without the objtool nop-workaround) and works as expected.


Good, thanks!



Not sure if required, but would such an additional test be useful:


Yes, it is, thanks for it.



---

diff --git a/gcc/testsuite/gcc.dg/sancov/attribute.c 
b/gcc/testsuite/gcc.dg/sancov/attribute.c
index bf6dbd4bae7..7cfa9134ff1 100644
--- a/gcc/testsuite/gcc.dg/sancov/attribute.c
+++ b/gcc/testsuite/gcc.dg/sancov/attribute.c
@@ -11,5 +11,17 @@ bar(void)
  {
  }
  
+static void inline

+__attribute__((always_inline))
+inline_fn(void)
+{
+}
+
+void
+__attribute__((no_sanitize_coverage))
+baz(void)
+{
+  inline_fn();
+}
  
  /* { dg-final { scan-tree-dump-times "__builtin___sanitizer_cov_trace_pc \\(\\)" 1 "optimized" } } */


---

Otherwise, please go ahead. I assume this is targeting GCC 12?


Yep.

There's V3 I'm sending.

Ready for master?
Thanks,
Martin



Thanks,
-- Marco



>From 15053b32a870cd62641ad62a9e76a78558489f4a Mon Sep 17 00:00:00 2001
From: Martin Liska 
Date: Thu, 20 May 2021 09:32:29 +0200
Subject: [PATCH] Add no_sanitize_coverage attribute.

gcc/ChangeLog:

	* asan.h (sanitize_coverage_p): New function.
	* doc/extend.texi: Document it.
	* fold-const.c (fold_range_test): Use sanitize_flags_p
	instead of flag_sanitize_coverage.
	(fold_truth_andor): Likewise.
	* sancov.c: Likewise.
	* tree-ssa-ifcombine.c (ifcombine_ifandif): Likewise.
	* ipa-inline.c (sanitize_attrs_match_for_inline_p): Handle
	-fsanitize-coverage when inlining.

gcc/c-family/ChangeLog:

	* c-attribs.c (handle_no_sanitize_coverage_attribute): New.

gcc/testsuite/ChangeLog:

	* gcc.dg/sancov/attribute.c: New test.
---
 gcc/asan.h  | 10 +
 gcc/c-family/c-attribs.c| 20 ++
 gcc/doc/extend.texi |  6 ++
 gcc/fold-const.c|  4 ++--
 gcc/ipa-inline.c|  3 +++
 gcc/sancov.c|  4 ++--
 gcc/testsuite/gcc.dg/sancov/attribute.c | 27 +
 gcc/tree-ssa-ifcombine.c|  4 +++-
 8 files changed, 73 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/sancov/attribute.c

diff --git a/gcc/asan.h b/gcc/asan.h
index f110f1db563..8c0b2baf170 100644
--- a/gcc/asan.h
+++ b/gcc/asan.h
@@ -249,4 +249,14 @@ sanitize_flags_p (unsigned int flag, const_tree fn = current_function_decl)
   return result_flags;
 }
 
+/* Return true when coverage sanitization should happend for FN function.  */
+
+static inline bool
+sanitize_coverage_p (const_tree fn = current_function_decl)
+{
+  return (flag_sanitize_coverage
+	  && lookup_attribute ("no_sanitize_coverage",
+			   DECL_ATTRIBUTES (fn)) == NULL_TREE);
+}
+
 #endif /* TREE_ASAN */
diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c
index ccf9e4ccf0b..671b27c3200 100644
--- a/gcc/c-family/c-attribs.c
+++ b/gcc/c-family/c-attribs.c
@@ -62,6 +62,8 @@ static tree handle_no_address_safety_analysis_attribute (tree *, tree, tree,
 			 int, bool *);
 static tree handle_no_sanitize_undefined_attribute (tree *, tree, tree, int,
 		bool *);
+static tree handle_no_sanitize_coverage_attribute (tree *, tree, tree, int,
+		   bool *);
 static tree handle_asan_odr_indicator_attribute (tree *, tree, tree, int,
 		 bool *);
 static tree handle_stack_protect_attribute (tree *, tree, tree, int, bool *);
@@ -449,6 +451,8 @@ const struct attribute_spec c_common_attribute_table[] =
 			  handle_no_sanitize_thread_attribute, NULL },
   { "no_sanitize_undefined",  0, 0, true, false, false, false,
 			  handle_no_sanitize_undefined_attribute, NULL },
+  { "no_sanitize_coverage",   0, 0, true, false, false, false,
+			  handle_no_sanitize_coverage_attribute, NULL },
   { "asan odr indicator", 0, 0, true, false, false, false,
 			  handle_asan_odr_indicator_attribute, NULL },
   { "warning",		  1, 1, true,  false, false, false,
@@ -1211,6 +1215,22 @@ handle_no_sanitize_undefined_attribute (tree *node, tree name, tree, int,
   return NULL_TREE;
 }
 
+/* Handle a "no_sanitize_coverage" attribute; arguments as in
+   struct attribute_spec.handler.  */
+
+static tree
+handle_no_sanitize_coverage_attribute (tree *node, tree name, tree, int,
+   bool *no_add_attrs)
+{
+  if (TREE_CODE (*node) != FUNCTION_DECL)
+{
+  warning 

Re: [wwwdocs, patch] htdocs/gitwrite.html: Clarify ChangeLog generation

2021-05-24 Thread Gerald Pfeifer
On Sun, 23 May 2021, Tobias Burnus wrote:
> As there was some confusion regarding when the ChangeLog is generated,
> I propose the attached wwwdocs patch. Comments?

-Apply the patch to your local tree.  ChangeLog entries will be
-automatically added to the corresponding ChangeLog files based
-on the git commit message.  See the documentation of
+Apply the patch to your local tree.  On the release branches, ChangeLog
+entries will be automatically added to the corresponding ChangeLog files based
+on the git commit message by the daily-bump commit.

Just "On release branches".

And "by the daily-dump commit based on git commit messages" (plural 
for commit messages and different order).


Can we assume everyone knows about the "daily-dump commit" here, or 
should we just write "once a day" or something like that?

And a question for my understanding: Why only on release branches?
>From what I can tell the same applies for trunk?

Gerald

PS: Nice change, too, Martin. Thank you!


Re: [PATCH, rs6000] Remove mode promotion of SSA variables

2021-05-24 Thread HAO CHEN GUI via Gcc-patches

Hi,

On 20/5/2021 下午 9:08, Segher Boessenkool wrote:

Hi!

On Thu, May 20, 2021 at 04:29:07PM +0800, HAO CHEN GUI wrote:

On 19/5/2021 下午 9:20, Segher Boessenkool wrote:

On Wed, May 19, 2021 at 04:36:00PM +0800, HAO CHEN GUI wrote:

-/* Define this macro if it is advisable to hold scalars in registers
-   in a wider mode than that declared by the program.  In such cases,
-   the value is constrained to be within the bounds of the declared
-   type, but kept valid in the wider mode.  The signedness of the
-   extension may differ from that of the type.  */
-
-#define PROMOTE_MODE(MODE,UNSIGNEDP,TYPE)  \
-  if (GET_MODE_CLASS (MODE) == MODE_INT\
-  && GET_MODE_SIZE (MODE) < (TARGET_32BIT ? 4 : 8)) \
-(MODE) = TARGET_32BIT ? SImode : DImode;
-

And this part needs some more words in the commit message :-)

[ ... ]


Also, how about something like

#define PROMOTE_MODE(MODE,UNSIGNEDP,TYPE)   \
   if (GET_MODE_CLASS (MODE) == MODE_INT\
   && GET_MODE_SIZE (MODE) < 4)  \
 (MODE) = SImode;

(that is, promoting modes smaller than SImode to SImode).  How does that
compare?

It hits an ICE when assigning a function return value to a variable. The
mode of variable is promoted to SImode, but the mode of return value is
promoted to DImode. Current GCC logical is either the mode of set_dest
is unchanged or the mode of set_dest matches the mode of function return
value.

So that sounds like a bug in the generic code?


By the way, I tested the patch on ppc64 with m32 option. The SPECint
shows a little improvement(0.4%). So it's better not do any mode promotions.

Interesting!  Do you have an example that shows improved code for that,
just like that "SI->DI promotion gets a superfluous extension" testcase
you sent?


perlbench and omnetpp_r got 3-4% performance improvement with the patch 
on ppc64 m32.  I tried to find an example in these two benchmarks, but I 
failed. The improvement of perlbench comes from the different sequence 
of basic block. For omnetpp, one of improvement comes from condition 
register not spilling.  But it is not directly related to the mode 
promotion.


By examming the ISA, I found there is no instructions for QI and HI 
mode(except load and store). So QI and HI are extended to SI mode 
automatically when they're used in an expression with the patch. So with 
the patch, gcc does implicit mode promotion for QI and HI. With original 
gcc, it does explicit mode promotion. They should have almost the same 
behavior.




Segher


Re: [PATCH][vect] Use main loop's thresholds and vectorization factor to narrow upper_bound of epilogue

2021-05-24 Thread Kewen.Lin via Gcc-patches
Hi Andre,

on 2021/5/24 下午2:17, Andre Vieira (lists) via Gcc-patches wrote:
> Hi,
> 
> When vectorizing with --param vect-partial-vector-usage=1 the vectorizer uses 
> an unpredicated (all-true predicate for SVE) main loop and a predicated tail 
> loop. The way this was implemented seems to mean it re-uses the same 
> vector-mode for both loops, which means the tail loop isn't an actual loop 
> but only executes one iteration.
> 
> This patch uses the knowledge of the conditions to enter an epilogue loop to 
> help come up with a potentially more restricive upper bound.
> 
> Regression tested on aarch64-linux-gnu and also ran the testsuite using 
> '--param vect-partial-vector-usage=1' detecting no ICEs and no execution 
> failures.
> 
> Would be good to have this tested for PPC too as I believe they are the main 
> users of the --param vect-partial-vector-usage=1 option. Can someone help me 
> test (and maybe even benchmark?) this on a PPC target?
> 


Thanks for doing this!  I can test it on Power10 which enables this parameter
by default, also evaluate its impact on SPEC2017 Ofast/unroll.

Do you have any preference for the baseline commit?  I'll use r12-0 if it's 
fine.

BR,
Kewen


Re: [PATCH 9/9] arm: Auto-vectorization for MVE: vld4/vst4

2021-05-24 Thread Christophe Lyon via Gcc-patches
ping?

On Mon, 17 May 2021 at 11:55, Christophe Lyon
 wrote:
>
> ping?
>
> On Tue, 4 May 2021 at 16:57, Christophe Lyon  
> wrote:
> >
> > On Tue, 4 May 2021 at 14:03, Andre Vieira (lists)
> >  wrote:
> > >
> > > Hi Christophe,
> > >
> > > The series LGTM but you'll need the approval of an arm port maintainer
> > > before committing. I only did code-review, did not try to build/run tests.
> > >
> >
> > Hi Andre,
> >
> > Thanks for the comments!
> >
> > > Kind regards,
> > > Andre
> > >
> > > On 30/04/2021 15:09, Christophe Lyon via Gcc-patches wrote:
> > > > This patch enables MVE vld4/vst4 instructions for auto-vectorization.
> > > > We move the existing expanders from neon.md and enable them for MVE,
> > > > calling the respective emitter.
> > > >
> > > > 2021-03-12  Christophe Lyon  
> > > >
> > > >   gcc/
> > > >   * config/arm/neon.md (vec_load_lanesxi)
> > > >   (vec_store_lanexoi): Move ...
> > > >   * config/arm/vec-common.md: here.
> > > >
> > > >   gcc/testsuite/
> > > >   * gcc.target/arm/simd/mve-vld4.c: New test, derived from
> > > >   slp-perm-3.c
> > > > ---
> > > >   gcc/config/arm/neon.md   |  20 
> > > >   gcc/config/arm/vec-common.md |  26 +
> > > >   gcc/testsuite/gcc.target/arm/simd/mve-vld4.c | 140 
> > > > +++
> > > >   3 files changed, 166 insertions(+), 20 deletions(-)
> > > >   create mode 100644 gcc/testsuite/gcc.target/arm/simd/mve-vld4.c
> > > >
> > > > diff --git a/gcc/config/arm/neon.md b/gcc/config/arm/neon.md
> > > > index bc8775c..fb58baf 100644
> > > > --- a/gcc/config/arm/neon.md
> > > > +++ b/gcc/config/arm/neon.md
> > > > @@ -5617,16 +5617,6 @@ (define_insn "neon_vld4"
> > > >   (const_string "neon_load4_4reg")))]
> > > >   )
> > > >
> > > > -(define_expand "vec_load_lanesxi"
> > > > -  [(match_operand:XI 0 "s_register_operand")
> > > > -   (match_operand:XI 1 "neon_struct_operand")
> > > > -   (unspec:VQ2 [(const_int 0)] UNSPEC_VSTRUCTDUMMY)]
> > > > -  "TARGET_NEON"
> > > > -{
> > > > -  emit_insn (gen_neon_vld4 (operands[0], operands[1]));
> > > > -  DONE;
> > > > -})
> > > > -
> > > >   (define_expand "neon_vld4"
> > > > [(match_operand:XI 0 "s_register_operand")
> > > >  (match_operand:XI 1 "neon_struct_operand")
> > > > @@ -5818,16 +5808,6 @@ (define_insn "neon_vst4"
> > > >   (const_string "neon_store4_4reg")))]
> > > >   )
> > > >
> > > > -(define_expand "vec_store_lanesxi"
> > > > -  [(match_operand:XI 0 "neon_struct_operand")
> > > > -   (match_operand:XI 1 "s_register_operand")
> > > > -   (unspec:VQ2 [(const_int 0)] UNSPEC_VSTRUCTDUMMY)]
> > > > -  "TARGET_NEON"
> > > > -{
> > > > -  emit_insn (gen_neon_vst4 (operands[0], operands[1]));
> > > > -  DONE;
> > > > -})
> > > > -
> > > >   (define_expand "neon_vst4"
> > > > [(match_operand:XI 0 "neon_struct_operand")
> > > >  (match_operand:XI 1 "s_register_operand")
> > > > diff --git a/gcc/config/arm/vec-common.md b/gcc/config/arm/vec-common.md
> > > > index 7abefea..d46b78d 100644
> > > > --- a/gcc/config/arm/vec-common.md
> > > > +++ b/gcc/config/arm/vec-common.md
> > > > @@ -512,3 +512,29 @@ (define_expand "vec_store_lanesoi"
> > > >   emit_insn (gen_mve_vst2q (operands[0], operands[1]));
> > > > DONE;
> > > >   })
> > > > +
> > > > +(define_expand "vec_load_lanesxi"
> > > > +  [(match_operand:XI 0 "s_register_operand")
> > > > +   (match_operand:XI 1 "neon_struct_operand")
> > > > +   (unspec:VQ2 [(const_int 0)] UNSPEC_VSTRUCTDUMMY)]
> > > > +  "TARGET_NEON || TARGET_HAVE_MVE"
> > > > +{
> > > > +  if (TARGET_NEON)
> > > > +emit_insn (gen_neon_vld4 (operands[0], operands[1]));
> > > > +  else
> > > > +emit_insn (gen_mve_vld4q (operands[0], operands[1]));
> > > > +  DONE;
> > > > +})
> > > > +
> > > > +(define_expand "vec_store_lanesxi"
> > > > +  [(match_operand:XI 0 "neon_struct_operand")
> > > > +   (match_operand:XI 1 "s_register_operand")
> > > > +   (unspec:VQ2 [(const_int 0)] UNSPEC_VSTRUCTDUMMY)]
> > > > +  "TARGET_NEON || TARGET_HAVE_MVE"
> > > > +{
> > > > +  if (TARGET_NEON)
> > > > +emit_insn (gen_neon_vst4 (operands[0], operands[1]));
> > > > +  else
> > > > +emit_insn (gen_mve_vst4q (operands[0], operands[1]));
> > > > +  DONE;
> > > > +})
> > > > diff --git a/gcc/testsuite/gcc.target/arm/simd/mve-vld4.c 
> > > > b/gcc/testsuite/gcc.target/arm/simd/mve-vld4.c
> > > > new file mode 100644
> > > > index 000..ce3e755
> > > > --- /dev/null
> > > > +++ b/gcc/testsuite/gcc.target/arm/simd/mve-vld4.c
> > > > @@ -0,0 +1,140 @@
> > > > +/* { dg-do assemble } */
> > > > +/* { dg-require-effective-target arm_v8_1m_mve_fp_ok } */
> > > > +/* { dg-add-options arm_v8_1m_mve_fp } */
> > > > +/* { dg-additional-options "-O3" } */
> > > > +
> > > > +#include 
> > > > +
> > > > +#define M00 100
> > > > +#define M10 216
> > > > +#define M20 23
> > > > +#define M30 237
> > > > +#define M01 1322
> > > > +#define M11 13
> > > > +#define 

Re: [PATCH 8/9] arm: Auto-vectorization for MVE: vld2/vst2

2021-05-24 Thread Christophe Lyon via Gcc-patches
ping?

On Mon, 17 May 2021 at 11:55, Christophe Lyon
 wrote:
>
> ping?
>
> On Fri, 30 Apr 2021 at 16:09, Christophe Lyon
>  wrote:
> >
> > This patch enables MVE vld2/vst2 instructions for auto-vectorization.
> > We move the existing expanders from neon.md and enable them for MVE,
> > calling the respective emitter.
> >
> > 2021-03-12  Christophe Lyon  
> >
> > gcc/
> > * config/arm/neon.md (vec_load_lanesoi)
> > (vec_store_lanesoi): Move ...
> > * config/arm/vec-common.md: here.
> >
> > gcc/testsuite/
> > * gcc.target/arm/simd/mve-vld2.c: New test, derived from
> > slp-perm-2.c
> > ---
> >  gcc/config/arm/neon.md   | 14 
> >  gcc/config/arm/vec-common.md | 27 
> >  gcc/testsuite/gcc.target/arm/simd/mve-vld2.c | 96 
> > 
> >  3 files changed, 123 insertions(+), 14 deletions(-)
> >  create mode 100644 gcc/testsuite/gcc.target/arm/simd/mve-vld2.c
> >
> > diff --git a/gcc/config/arm/neon.md b/gcc/config/arm/neon.md
> > index 6660846..bc8775c 100644
> > --- a/gcc/config/arm/neon.md
> > +++ b/gcc/config/arm/neon.md
> > @@ -5063,13 +5063,6 @@ (define_insn "neon_vld2"
> >  (const_string "neon_load2_2reg")))]
> >  )
> >
> > -(define_expand "vec_load_lanesoi"
> > -  [(set (match_operand:OI 0 "s_register_operand")
> > -(unspec:OI [(match_operand:OI 1 "neon_struct_operand")
> > -(unspec:VQ2 [(const_int 0)] UNSPEC_VSTRUCTDUMMY)]
> > -  UNSPEC_VLD2))]
> > -  "TARGET_NEON")
> > -
> >  (define_insn "neon_vld2"
> >[(set (match_operand:OI 0 "s_register_operand" "=w")
> >  (unspec:OI [(match_operand:OI 1 "neon_struct_operand" "Um")
> > @@ -5197,13 +5190,6 @@ (define_insn "neon_vst2"
> >  (const_string "neon_store2_one_lane")))]
> >  )
> >
> > -(define_expand "vec_store_lanesoi"
> > -  [(set (match_operand:OI 0 "neon_struct_operand")
> > -   (unspec:OI [(match_operand:OI 1 "s_register_operand")
> > -(unspec:VQ2 [(const_int 0)] UNSPEC_VSTRUCTDUMMY)]
> > -   UNSPEC_VST2))]
> > -  "TARGET_NEON")
> > -
> >  (define_insn "neon_vst2"
> >[(set (match_operand:OI 0 "neon_struct_operand" "=Um")
> > (unspec:OI [(match_operand:OI 1 "s_register_operand" "w")
> > diff --git a/gcc/config/arm/vec-common.md b/gcc/config/arm/vec-common.md
> > index 3fd341c..7abefea 100644
> > --- a/gcc/config/arm/vec-common.md
> > +++ b/gcc/config/arm/vec-common.md
> > @@ -482,6 +482,33 @@ (define_expand "vcond_mask_"
> >  }
> >else
> >  gcc_unreachable ();
> > +  DONE;
> > +})
> >
> > +(define_expand "vec_load_lanesoi"
> > +  [(set (match_operand:OI 0 "s_register_operand")
> > +(unspec:OI [(match_operand:OI 1 "neon_struct_operand")
> > +(unspec:VQ2 [(const_int 0)] UNSPEC_VSTRUCTDUMMY)]
> > +  UNSPEC_VLD2))]
> > +  "TARGET_NEON || TARGET_HAVE_MVE"
> > +{
> > +  if (TARGET_NEON)
> > +emit_insn (gen_neon_vld2 (operands[0], operands[1]));
> > +  else
> > +emit_insn (gen_mve_vld2q (operands[0], operands[1]));
> > +  DONE;
> > +})
> > +
> > +(define_expand "vec_store_lanesoi"
> > +  [(set (match_operand:OI 0 "neon_struct_operand")
> > +   (unspec:OI [(match_operand:OI 1 "s_register_operand")
> > +(unspec:VQ2 [(const_int 0)] UNSPEC_VSTRUCTDUMMY)]
> > +   UNSPEC_VST2))]
> > +  "TARGET_NEON || TARGET_HAVE_MVE"
> > +{
> > +  if (TARGET_NEON)
> > +emit_insn (gen_neon_vst2 (operands[0], operands[1]));
> > +  else
> > +emit_insn (gen_mve_vst2q (operands[0], operands[1]));
> >DONE;
> >  })
> > diff --git a/gcc/testsuite/gcc.target/arm/simd/mve-vld2.c 
> > b/gcc/testsuite/gcc.target/arm/simd/mve-vld2.c
> > new file mode 100644
> > index 000..9c7c3f5
> > --- /dev/null
> > +++ b/gcc/testsuite/gcc.target/arm/simd/mve-vld2.c
> > @@ -0,0 +1,96 @@
> > +/* { dg-do assemble } */
> > +/* { dg-require-effective-target arm_v8_1m_mve_fp_ok } */
> > +/* { dg-add-options arm_v8_1m_mve_fp } */
> > +/* { dg-additional-options "-O3" } */
> > +
> > +#include 
> > +
> > +#define M00 100
> > +#define M10 216
> > +#define M01 1322
> > +#define M11 13
> > +
> > +#define N 128
> > +
> > +
> > +/* Integer tests.  */
> > +#define FUNC(SIGN, TYPE, BITS) \
> > +  void foo_##SIGN##BITS##x (TYPE##BITS##_t *__restrict__ pInput,   \
> > +   TYPE##BITS##_t *__restrict__ pOutput)   \
> > +  {\
> > +unsigned int i;\
> > +TYPE##BITS##_t  a, b;  \
> > +   \
> > +for (i = 0; i < N / BITS; i++) \
> > +  { 

Re: [wwwdocs, patch] htdocs/gitwrite.html: Clarify ChangeLog generation

2021-05-24 Thread Martin Liška

On 5/23/21 2:37 PM, Tobias Burnus wrote:

As there was some confusion regarding when the ChangeLog is generated,
I propose the attached wwwdocs patch. Comments?


I support the change. Moreover, I'm going to install the following
patch that adds a note about ChangeLog entries.

Martin



(Side remark: The cron-script commit by gccadmin@ is labelled "Daily bump."
and updates gcc/DATESTAMP besides the ChangeLog files.)

Tobias

-
Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München 
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank 
Thürauf


>From 7a8e19e68c9c73ce18aeea02fc7e82fd4326a5a2 Mon Sep 17 00:00:00 2001
From: Martin Liska 
Date: Mon, 24 May 2021 09:16:01 +0200
Subject: [PATCH] gcc-changelog: Add note about ChangeLog entries

contrib/ChangeLog:

	* gcc-changelog/git_commit.py: Add note that ChangeLog entries
	are added automatically.
	* gcc-changelog/test_email.py: Update test.
---
 contrib/gcc-changelog/git_commit.py | 8 +---
 contrib/gcc-changelog/test_email.py | 2 +-
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/contrib/gcc-changelog/git_commit.py b/contrib/gcc-changelog/git_commit.py
index 4958ab9c159..bd8c1ff7af2 100755
--- a/contrib/gcc-changelog/git_commit.py
+++ b/contrib/gcc-changelog/git_commit.py
@@ -326,9 +326,11 @@ class GitCommit:
 # All modified files are only MISC files
 return
 elif project_files:
-self.errors.append(Error('ChangeLog, DATESTAMP, BASE-VER and '
- 'DEV-PHASE updates should be done '
- 'separately from normal commits'))
+err = 'ChangeLog, DATESTAMP, BASE-VER and DEV-PHASE updates ' \
+  'should be done separately from normal commits\n' \
+  '(note: ChangeLog entries will be automatically ' \
+  'added by a cron job)'
+self.errors.append(Error(err))
 return
 
 all_are_ignored = (len(project_files) + len(ignored_files)
diff --git a/contrib/gcc-changelog/test_email.py b/contrib/gcc-changelog/test_email.py
index 7472762e66d..6d6596370c4 100755
--- a/contrib/gcc-changelog/test_email.py
+++ b/contrib/gcc-changelog/test_email.py
@@ -258,7 +258,7 @@ class TestGccChangelog(unittest.TestCase):
 email = self.from_patch_glob('0001-Add-patch_are')
 msg = 'ChangeLog, DATESTAMP, BASE-VER and DEV-PHASE updates should ' \
   'be done separately from normal commits'
-assert email.errors[0].message == msg
+assert email.errors[0].message.startswith(msg)
 
 def test_strict_mode_normal_patch(self):
 email = self.get_git_email('0001-Just-test-it.patch')
-- 
2.31.1



[PATCH][vect] Use main loop's thresholds and vectorization factor to narrow upper_bound of epilogue

2021-05-24 Thread Andre Vieira (lists) via Gcc-patches

Hi,

When vectorizing with --param vect-partial-vector-usage=1 the vectorizer 
uses an unpredicated (all-true predicate for SVE) main loop and a 
predicated tail loop. The way this was implemented seems to mean it 
re-uses the same vector-mode for both loops, which means the tail loop 
isn't an actual loop but only executes one iteration.


This patch uses the knowledge of the conditions to enter an epilogue 
loop to help come up with a potentially more restricive upper bound.


Regression tested on aarch64-linux-gnu and also ran the testsuite using 
'--param vect-partial-vector-usage=1' detecting no ICEs and no execution 
failures.


Would be good to have this tested for PPC too as I believe they are the 
main users of the --param vect-partial-vector-usage=1 option. Can 
someone help me test (and maybe even benchmark?) this on a PPC target?


Kind regards,
Andre

gcc/ChangeLog:

    * tree-vect-loop.c (vect_transform_loop): Use main loop's 
various' thresholds

    to narrow the upper bound on epilogue iterations.

gcc/testsuite/ChangeLog:

    * gcc.target/aarch64/sve/part_vect_single_iter_epilog.c: New test.

diff --git 
a/gcc/testsuite/gcc.target/aarch64/sve/part_vect_single_iter_epilog.c 
b/gcc/testsuite/gcc.target/aarch64/sve/part_vect_single_iter_epilog.c
new file mode 100644
index 
..a03229eb55585f637ebd5288fb4c00f8f921d44c
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/sve/part_vect_single_iter_epilog.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 --param vect-partial-vector-usage=1" } */
+
+void
+foo (short * __restrict__ a, short * __restrict__ b, short * __restrict__ c, 
int n)
+{
+  for (int i = 0; i < n; ++i)
+c[i] = a[i] + b[i];
+}
+
+/* { dg-final { scan-assembler-times {\twhilelo\tp[0-9]+.h, wzr, [xw][0-9]+} 1 
} } */
diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
index 
3e973e774af8f9205be893e01ad9263281116885..81e9c5cc42415a0a92b765bc46640105670c4e6b
 100644
--- a/gcc/tree-vect-loop.c
+++ b/gcc/tree-vect-loop.c
@@ -9723,12 +9723,31 @@ vect_transform_loop (loop_vec_info loop_vinfo, gimple 
*loop_vectorized_call)
   /* In these calculations the "- 1" converts loop iteration counts
  back to latch counts.  */
   if (loop->any_upper_bound)
-loop->nb_iterations_upper_bound
-  = (final_iter_may_be_partial
-? wi::udiv_ceil (loop->nb_iterations_upper_bound + bias_for_lowest,
- lowest_vf) - 1
-: wi::udiv_floor (loop->nb_iterations_upper_bound + bias_for_lowest,
-  lowest_vf) - 1);
+{
+  loop_vec_info main_vinfo = LOOP_VINFO_ORIG_LOOP_INFO (loop_vinfo);
+  loop->nb_iterations_upper_bound
+   = (final_iter_may_be_partial
+  ? wi::udiv_ceil (loop->nb_iterations_upper_bound + bias_for_lowest,
+   lowest_vf) - 1
+  : wi::udiv_floor (loop->nb_iterations_upper_bound + bias_for_lowest,
+lowest_vf) - 1);
+  if (main_vinfo)
+   {
+ unsigned int bound;
+ poly_uint64 main_iters
+   = upper_bound (LOOP_VINFO_VECT_FACTOR (main_vinfo),
+  LOOP_VINFO_COST_MODEL_THRESHOLD (main_vinfo));
+ main_iters
+   = upper_bound (main_iters,
+  LOOP_VINFO_VERSIONING_THRESHOLD (main_vinfo));
+ if (can_div_away_from_zero_p (main_iters,
+   LOOP_VINFO_VECT_FACTOR (loop_vinfo),
+   ))
+   loop->nb_iterations_upper_bound
+ = wi::umin ((widest_int) (bound - 1),
+ loop->nb_iterations_upper_bound);
+  }
+  }
   if (loop->any_likely_upper_bound)
 loop->nb_iterations_likely_upper_bound
   = (final_iter_may_be_partial


[C PATCH] qualifiers of pointers to arrays in C2X [PR 98397]

2021-05-24 Thread Uecker, Martin

Hi Joseph,

I found some time to update this patch. The only real change
of the patch is the qualifier in the conditional expression for
pointer to arrays in C2X. All the rest are the warnings,
which were wrong in the last version.

I hope I got this correct this time in combination with
-pedantic-errors and -Wc11-c2x-compat. 

Martin


2021-05-16  Martin Uecker  

gcc/c/
 PR c/98397
 * c-typeck.c (comp_target_types): Change pedwarn to pedwarn_c11
 for pointers to arrays with qualifiers.
 (build_conditional_expr): For C23 don't lose qualifiers for pointers
 to arrays when the other pointer is a void pointer. Update warnings.
 (convert_for_assignment): Update warnings for C2X when converting from
 void* with qualifiers to a pointer to array with the same qualifiers.

gcc/testsuite/
 PR c/98397
 * gcc.dg/c11-qual-1.c: New test.
 * gcc.dg/c2x-qual-1.c: New test.
 * gcc.dg/c2x-qual-2.c: New test.
 * gcc.dg/c2x-qual-3.c: New test.
 * gcc.dg/c2x-qual-4.c: New test.
 * gcc.dg/c2x-qual-5.c: New test.
 * gcc.dg/c2x-qual-6.c: New test.
 * gcc.dg/pointer-array-quals-1.c: Remove unnecessary flag.
 * gcc.dg/pointer-array-quals-2.c: Remove unnecessary flag.


diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index fc64ef96fb8..5b13656c090 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -1328,8 +1328,8 @@ comp_target_types (location_t location, tree ttl, tree 
ttr)
   val = comptypes_check_enum_int (mvl, mvr, _and_int_p);
 
   if (val == 1 && val_ped != 1)
-pedwarn (location, OPT_Wpedantic, "pointers to arrays with different 
qualifiers "
-  "are incompatible in ISO C");
+pedwarn_c11 (location, OPT_Wpedantic, "invalid use of pointers to arrays 
with different qualifiers "
+ "in ISO C before C2X");
 
   if (val == 2)
 pedwarn (location, OPT_Wpedantic, "types are not quite compatible");
@@ -5396,39 +5396,40 @@ build_conditional_expr (location_t colon_loc, tree 
ifexp, bool ifexp_bcp,
"used in conditional expression");
  return error_mark_node;
}
-  else if (VOID_TYPE_P (TREE_TYPE (type1))
-  && !TYPE_ATOMIC (TREE_TYPE (type1)))
-   {
- if ((TREE_CODE (TREE_TYPE (type2)) == ARRAY_TYPE)
- && (TYPE_QUALS (strip_array_types (TREE_TYPE (type2)))
- & ~TYPE_QUALS (TREE_TYPE (type1
-   warning_at (colon_loc, OPT_Wdiscarded_array_qualifiers,
-   "pointer to array loses qualifier "
-   "in conditional expression");
-
- if (TREE_CODE (TREE_TYPE (type2)) == FUNCTION_TYPE)
+  else if ((VOID_TYPE_P (TREE_TYPE (type1))
+   && !TYPE_ATOMIC (TREE_TYPE (type1)))
+  || (VOID_TYPE_P (TREE_TYPE (type2))
+  && !TYPE_ATOMIC (TREE_TYPE (type2
+   {
+ tree t1 = TREE_TYPE (type1);
+ tree t2 = TREE_TYPE (type2);
+ if (!VOID_TYPE_P (t1))
+  {
+/* roles are swapped */
+t1 = t2;
+t2 = TREE_TYPE (type1);
+  }
+ tree t2_stripped = strip_array_types (t2);
+ if ((TREE_CODE (t2) == ARRAY_TYPE)
+ && (TYPE_QUALS (t2_stripped) & ~TYPE_QUALS (t1)))
+   {
+ if (!flag_isoc2x)
+   warning_at (colon_loc, OPT_Wdiscarded_array_qualifiers,
+   "pointer to array loses qualifier "
+   "in conditional expression");
+ else if (warn_c11_c2x_compat > 0)
+   warning_at (colon_loc, OPT_Wc11_c2x_compat,
+   "pointer to array loses qualifier "
+   "in conditional expression in ISO C before C2X");
+   }
+ if (TREE_CODE (t2) == FUNCTION_TYPE)
pedwarn (colon_loc, OPT_Wpedantic,
 "ISO C forbids conditional expr between "
 "% and function pointer");
- result_type = build_pointer_type (qualify_type (TREE_TYPE (type1),
- TREE_TYPE (type2)));
-   }
-  else if (VOID_TYPE_P (TREE_TYPE (type2))
-  && !TYPE_ATOMIC (TREE_TYPE (type2)))
-   {
- if ((TREE_CODE (TREE_TYPE (type1)) == ARRAY_TYPE)
- && (TYPE_QUALS (strip_array_types (TREE_TYPE (type1)))
- & ~TYPE_QUALS (TREE_TYPE (type2
-   warning_at (colon_loc, OPT_Wdiscarded_array_qualifiers,
-   "pointer to array loses qualifier "
-   "in conditional expression");
-
- if (TREE_CODE (TREE_TYPE (type1)) == FUNCTION_TYPE)
-   pedwarn (colon_loc, OPT_Wpedantic,
-"ISO C forbids conditional expr between "
-"% and function pointer");
- result_type = build_pointer_type (qualify_type (TREE_TYPE (type2),
-