Re: [PATCH v3] bpf.2: Use standard types and attributes

2021-05-16 Thread Alejandro Colomar (man-pages) via Gcc-patches

On 5/15/21 9:01 PM, Alejandro Colomar wrote:

Some manual pages are already using C99 syntax for integral
types 'uint32_t', but some aren't.  There are some using kernel
syntax '__u32'.  Fix those.

Both the kernel and the standard types are 100% binary compatible,
and the source code differences between them are very small, and
not important in a manual page:

- Some of them are implemented with different underlying types
   (e.g., s64 is always long long, while int64_t may be long long
   or long, depending on the arch).  This causes the following
   differences.

- length modifiers required by printf are different, resulting in
   a warning ('-Wformat=').

- pointer assignment causes a warning:
   ('-Wincompatible-pointer-types'), but there aren't any pointers
   in this page.

But, AFAIK, all of those warnings can be safely ignored, due to
the binary compatibility between the types.

...

Some pages also document attributes, using GNU syntax
'__attribute__((xxx))'.  Update those to use the shorter and more
portable C11 keywords such as 'alignas()' when possible, and C2x
syntax '[[gnu::xxx]]' elsewhere, which hasn't been standardized
yet, but is already implemented in GCC, and available through
either --std=c2x or any of the --std=gnu... options.

The standard isn't very clear on how to use alignas() or
[[]]-style attributes, and the GNU documentation isn't better, so
the following link is a useful experiment about the different
alignment syntaxes:
__attribute__((aligned())), alignas(), and [[gnu::aligned()]]:


Signed-off-by: Alejandro Colomar 
Discussion: 


Nacked-by: Alexei Starovoitov 
Nacked-by: Greg Kroah-Hartman 
Acked-by: Zack Weinberg 
Cc: LKML 
Cc: glibc 
Cc: GCC 
Cc: bpf 
Cc: David Laight 
Cc: Joseph Myers 
Cc: Florian Weimer 
Cc: Daniel Borkmann 
---
  man2/bpf.2 | 49 -
  1 file changed, 24 insertions(+), 25 deletions(-)

diff --git a/man2/bpf.2 b/man2/bpf.2
index 6e1ffa198..04b8fbcef 100644
--- a/man2/bpf.2
+++ b/man2/bpf.2
@@ -186,41 +186,40 @@ commands:
  .PP
  .in +4n
  .EX
-union bpf_attr {
+union [[gnu::aligned(8)]] bpf_attr {
  struct {/* Used by BPF_MAP_CREATE */
-__u32 map_type;
-__u32 key_size;/* size of key in bytes */
-__u32 value_size;  /* size of value in bytes */
-__u32 max_entries; /* maximum number of entries
-  in a map */
+uint32_tmap_type;
+uint32_tkey_size;/* size of key in bytes */
+uint32_tvalue_size;  /* size of value in bytes */
+uint32_tmax_entries; /* maximum number of entries
+in a map */
  };
  
-struct {/* Used by BPF_MAP_*_ELEM and BPF_MAP_GET_NEXT_KEY

-   commands */
-__u32 map_fd;
-__aligned_u64 key;
+struct {/* Used by BPF_MAP_*_ELEM and BPF_MAP_GET_NEXT_KEY commands */
+uint32_tmap_fd;
+uint64_t alignas(8) key;
  union {
-__aligned_u64 value;
-__aligned_u64 next_key;
+uint64_t alignas(8) value;
+uint64_t alignas(8) next_key;
  };
-__u64 flags;
+uint64_tflags;
  };
  
  struct {/* Used by BPF_PROG_LOAD */

-__u32 prog_type;
-__u32 insn_cnt;
-__aligned_u64 insns;  /* \(aqconst struct bpf_insn *\(aq */
-__aligned_u64 license;/* \(aqconst char *\(aq */
-__u32 log_level;  /* verbosity level of verifier */
-__u32 log_size;   /* size of user buffer */
-__aligned_u64 log_buf;/* user supplied \(aqchar *\(aq
- buffer */
-__u32 kern_version;
-  /* checked when prog_type=kprobe
- (since Linux 4.1) */
+uint32_tprog_type;
+uint32_tinsn_cnt;
+uint64_t alignas(8) insns; /* \(aqconst struct bpf_insn *\(aq */
+uint64_t alignas(8) license;   /* \(aqconst char *\(aq */
+uint32_tlog_level; /* verbosity level of verifier */
+uint32_tlog_size;  /* size of user buffer */
+uint64_t alignas(8) log_buf;   /* user supplied \(aqchar *\(aq
+  buffer */
+uint32_tkern_version;
+   /* checked when prog_type=kprobe
+  (since Linux 4.1) */
  .\" commit 2541517c32be2531e0da59dfd7efc1ce844644f5
  };
-} __attribute__((aligned(8)));
+};
  .EE
  .in
  .\"




--
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http

Re: [PATCH] Add dg-final option-based target selectors

2021-05-16 Thread Thomas Schwinge
Hi Richard!

On 2021-04-19T20:28:31+0100, Richard Sandiford via Gcc-patches 
 wrote:
> This patch adds target selectors of the form:
>
>   { any-opts "opt1" ... "optn" }
>   { no-opts "opt1" ... "optn" }
>
> for skipping or xfailing tests based on compiler options.

Nice!

> It only
> works for dg-final selectors.

Curious, what does it take to make this work generally, not just for
'dg-final'?  (I shall look into that myself, if you don't know off-hand.)

> The patch then uses no-opts to exclude -O0 and (sometimes) -Og from

Basically, I need the same thing for 'dg-message', where a diagnostic
doesn't vs. does appear depending of 'if (optimize)' (thus, simply,
'no-opts "-O0"' vs. 'any-opts "-O0"').

(My other option is to add a simple 'check_effective_target_O0' using
'check_no_compiler_messages' and some '#ifdef __OPTIMIZE__', '#error',
I suppose.)


Grüße
 Thomas


> some guality.exp xfails.  AFAICT (based on gcc-testresults) these
> tests pass for those options for all targets.
>
> Tested on aarch64-linux-gnu and x86_64-linux-gnu.  OK to install?
> If so, OK now, or should it wait for GCC 12?
>
> Richard
>
>
> gcc/
>   * doc/sourcebuild.texi: Document no-opts and any-opts target
>   selectors.
>
> gcc/testsuite/
>   * lib/target-supports-dg.exp (selector_expression): Handle any-opts
>   and no-opts.
>   * gcc.dg/guality/pr41353-1.c: Exclude -O0 from xfail.
>   * gcc.dg/guality/pr59776.c: Likewise.
>   * gcc.dg/guality/pr54970.c: Likewise -O0 and -Og.
> ---
>  gcc/doc/sourcebuild.texi | 90 +++-
>  gcc/testsuite/gcc.dg/guality/pr41353-1.c |  2 +-
>  gcc/testsuite/gcc.dg/guality/pr54970.c   | 16 ++---
>  gcc/testsuite/gcc.dg/guality/pr59776.c   |  4 +-
>  gcc/testsuite/lib/target-supports-dg.exp | 10 ++-
>  5 files changed, 107 insertions(+), 15 deletions(-)
>
> diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
> index b0001247795..d3200a42e44 100644
> --- a/gcc/doc/sourcebuild.texi
> +++ b/gcc/doc/sourcebuild.texi
> @@ -1301,6 +1301,8 @@ A selector is:
>  @item one or more target triplets, possibly including wildcard characters;
>  use @samp{*-*-*} to match any target
>  @item a single effective-target keyword (@pxref{Effective-Target Keywords})
> +@item a list of compiler options that should be included or excluded
> +(as described in more detail below)
>  @item a logical expression
>  @end itemize
>
> @@ -1313,14 +1315,96 @@ test to fail for targets that match @var{selector2}.
>
>  A selector expression appears within curly braces and uses a single
>  logical operator: one of @samp{!}, @samp{&&}, or @samp{||}.  An
> -operand is another selector expression, an effective-target keyword,
> -a single target triplet, or a list of target triplets within quotes or
> -curly braces.  For example:
> +operand is one of the following:
> +
> +@itemize @bullet
> +@item
> +another selector expression, in curly braces
> +
> +@item
> +an effective-target keyword, such as @code{lp64}
> +
> +@item
> +a single target triplet
> +
> +@item
> +a list of target triplets within quotes or curly braces
> +
> +@item
> +one of the following:
> +
> +@table @samp
> +@item @{ any-opts @var{opt1} @dots{} @var{optn} @}
> +Each of @var{opt1} to @var{optn} is a space-separated list of option globs.
> +The selector expression evaluates to true if, for one of these strings,
> +every glob in the string matches an option that was passed to the compiler.
> +For example:
> +
> +@smallexample
> +@{ any-opts "-O3 -flto" "-O[2g]" @}
> +@end smallexample
> +
> +is true if any of the following are true:
> +
> +@itemize @bullet
> +@item
> +@option{-O2} was passed to the compiler
> +
> +@item
> +@option{-Og} was passed to the compiler
> +
> +@item
> +both @option{-O3} and @option{-flto} were passed to the compiler
> +@end itemize
> +
> +This kind of selector can only be used within @code{dg-final} directives.
> +Use @code{dg-skip-if}, @code{dg-xfail-if} or @code{dg-xfail-run-if} to
> +skip whole tests based on options, or to mark them as expected to fail
> +with certain options.
> +
> +@item @{ no-opts @var{opt1} @dots{} @var{optn} @}
> +As for @code{any-opts} above, each of @var{opt1} to @var{optn} is a
> +space-separated list of option globs.  The selector expression
> +evaluates to true if, for all of these strings, there is at least
> +one glob that does not match an option that was passed to the compiler.
> +It is shorthand for:
> +
> +@smallexample
> +@{ ! @{ any-opts @var{opt1} @dots{} @var{optn} @} @}
> +@end smallexample
> +
> +For example:
> +
> +@smallexample
> +@{ no-opts "-O3 -flto" "-O[2g]" @}
> +@end smallexample
> +
> +is true if all of the following are true:
> +
> +@itemize @bullet
> +@item
> +@option{-O2} was not passed to the compiler
> +
> +@item
> +@option{-Og} was not passed to the compiler
> +
> +@item
> +at least one of @option{-O3} or @option{-flto} was not passed to the compiler
> +@end itemize
> +
> +Like @code{any-opts}, this kind of selector c

RFA: Fix match_scratch bug in define_subst

2021-05-16 Thread Joern Rennecke
Bootstrapped on x86_64-pc-linux-gnu.
2020-12-10  Joern Rennecke  

Fix bug in the define_subst handling that made match_scratch unusable for
multi-alternative patterns.

diff --git a/gcc/gensupport.c b/gcc/gensupport.c
index e1ca06dbc1e..4022c661adb 100644
--- a/gcc/gensupport.c
+++ b/gcc/gensupport.c
@@ -1291,6 +1291,9 @@ alter_constraints (rtx pattern, int n_dup, 
constraints_handler_t alter)
 case MATCH_OPERAND:
   XSTR (pattern, 2) = alter (XSTR (pattern, 2), n_dup);
   break;
+case MATCH_SCRATCH:
+  XSTR (pattern, 1) = alter (XSTR (pattern, 1), n_dup);
+  break;
 
 default:
   break;


RFA: Improve message for wrong number of alternatives

2021-05-16 Thread Joern Rennecke
When you have lots of operands and lots of alternatives in a pattern,
it is often not immediately apparent if the problem is in the
indicated alternative or in the one that genoutput uses as a reference
for the 'correct' number of alternatives, and/or if you dropped a
comma or had one too many.  By making genoutput tell you what the
argument counts are, this gets a little bit easier.

Bootstrapped on x86_64-pc-linux-gnu.
2021-01-13  Joern Rennecke  

Make "wrong number of alternatives" message a bit more specific.

diff --git a/gcc/genoutput.c b/gcc/genoutput.c
index 8e911cce2f5..d2836f85bbf 100644
--- a/gcc/genoutput.c
+++ b/gcc/genoutput.c
@@ -813,8 +813,8 @@ validate_insn_alternatives (class data *d)
if (n == 0)
  n = d->operand[start].n_alternatives;
else if (n != d->operand[start].n_alternatives)
- error_at (d->loc, "wrong number of alternatives in operand %d",
-   start);
+ error_at (d->loc, "wrong number of alternatives in operand %d, 
%d, expected %d",
+   start, d->operand[start].n_alternatives, n);
  }
   }
 


[no subject]

2021-05-16 Thread Joern Rennecke
At the moment, for a match_dup in a define_cond_exec, you'd have to
give the number in the
resulting pattern(s) rather than in the substitute pattern.  That's
not only wrong, but can also
be impossible when the pattern should apply to multiple patterns with
different operand numbers.

The attached patch fixes this.

Bootstrapped on x86_64-pc-linux-gnu.
2020-12-12  Joern Rennecke  

Fix match_dup bug of define_cond_exec.
* gensupport.c (alter_predicate_for_insn): Handle MATCH_DUP.

diff --git a/gcc/gensupport.c b/gcc/gensupport.c
index e1ca06dbc1e..92275358078 100644
--- a/gcc/gensupport.c
+++ b/gcc/gensupport.c
@@ -1230,6 +1230,7 @@ alter_predicate_for_insn (rtx pattern, int alt, int 
max_op,
 case MATCH_OPERATOR:
 case MATCH_SCRATCH:
 case MATCH_PARALLEL:
+case MATCH_DUP:
   XINT (pattern, 0) += max_op;
   break;
 


RFA: Fix match_dup numbering bug in define_cond_exec

2021-05-16 Thread Joern Rennecke
(Sorry about re-sending - I accidentally forgot to add a subject in
the last post, which would make it hard to have a meaningful thread.)

At the moment, for a match_dup in a define_cond_exec, you'd have to
give the number in the
resulting pattern(s) rather than in the substitute pattern.  That's
not only wrong, but can also
be impossible when the pattern should apply to multiple patterns with
different operand numbers.

The attached patch fixes this.

Bootstrapped on x86_64-pc-linux-gnu.
2020-12-12  Joern Rennecke  

Fix match_dup bug of define_cond_exec.
* gensupport.c (alter_predicate_for_insn): Handle MATCH_DUP.

diff --git a/gcc/gensupport.c b/gcc/gensupport.c
index e1ca06dbc1e..92275358078 100644
--- a/gcc/gensupport.c
+++ b/gcc/gensupport.c
@@ -1230,6 +1230,7 @@ alter_predicate_for_insn (rtx pattern, int alt, int 
max_op,
 case MATCH_OPERATOR:
 case MATCH_SCRATCH:
 case MATCH_PARALLEL:
+case MATCH_DUP:
   XINT (pattern, 0) += max_op;
   break;
 


RFA: Support cobbers in define_cond_exec

2021-05-16 Thread Joern Rennecke
At the moment, define_cond_exec allows only a single substitution
pattern.  That is
rather limiting if the target needs to clobber a scratch register in
order to compute the
required condition.
The attached patch allows to add clobber patterns after the main
pattern, and also adds
support for MATCH_SCRATCH in alter_predicate_for_insn.

This makes most sense together with the previous patch for MATCH_DUP support,
although the latter can also be used stand-alone, so have posted and
tested these
patches separately.

Bootstrapped on x86_64-pc-linux-gnu.
2020-12-12  Joern Rennecke  

Fix define_cond_exec flaw of not accepting clobbers.
* gensupport.c (alter_predicate_for_insn): Handle MATCH_SCRATCH.
(process_one_cond_exec): Allow extra patterns for clobbers.

diff --git a/gcc/gensupport.c b/gcc/gensupport.c
index e1ca06dbc1e..b472dc115b5 100644
--- a/gcc/gensupport.c
+++ b/gcc/gensupport.c
@@ -1198,8 +1198,11 @@ alter_predicate_for_insn (rtx pattern, int alt, int 
max_op,
   switch (code)
 {
 case MATCH_OPERAND:
+case MATCH_SCRATCH:
   {
-   const char *c = XSTR (pattern, 2);
+   const char **altstr_loc
+ = &XSTR (pattern, code == MATCH_SCRATCH ? 1 : 2);
+   const char *c = *altstr_loc;
 
if (n_alternatives (c) != 1)
  {
@@ -1216,19 +1219,22 @@ alter_predicate_for_insn (rtx pattern, int alt, int 
max_op,
char *new_c = XNEWVEC (char, len);
 
memcpy (new_c, c, c_len);
+   char *wp = new_c + c_len;
+   if (*c == '=')
+ c++, c_len--;
for (i = 1; i < alt; ++i)
  {
-   new_c[i * (c_len + 1) - 1] = ',';
-   memcpy (&new_c[i * (c_len + 1)], c, c_len);
+   *wp++ = ',';
+   memcpy (wp, c, c_len);
+   wp += c_len;
  }
-   new_c[len - 1] = '\0';
-   XSTR (pattern, 2) = new_c;
+   *wp = '\0';
+   *altstr_loc = new_c;
  }
   }
   /* Fall through.  */
 
 case MATCH_OPERATOR:
-case MATCH_SCRATCH:
 case MATCH_PARALLEL:
   XINT (pattern, 0) += max_op;
   break;
@@ -1754,13 +1760,18 @@ process_one_cond_exec (class queue_elem *ce_elem)
   collect_insn_data (insn_elem->data, &alternatives, &max_operand);
   max_operand += 1;
 
-  if (XVECLEN (ce_elem->data, 0) != 1)
+  for (i = XVECLEN (ce_elem->data, 0) - 1; i > 0; i--)
{
- error_at (ce_elem->loc, "too many patterns in predicate");
- return;
+ rtx part = XVECEXP (ce_elem->data, 0, i);
+ if (GET_CODE (part) != CLOBBER)
+   {
+ error_at (ce_elem->loc, "too many patterns in predicate");
+ return;
+   }
}
 
   pred = copy_rtx (XVECEXP (ce_elem->data, 0, 0));
+  int n_clobbers = XVECLEN (ce_elem->data, 0) - 1;
   pred = alter_predicate_for_insn (pred, alternatives, max_operand,
   ce_elem->loc);
   if (pred == NULL)
@@ -1774,8 +1785,15 @@ process_one_cond_exec (class queue_elem *ce_elem)
   pattern = rtx_alloc (COND_EXEC);
   XEXP (pattern, 0) = pred;
   XEXP (pattern, 1) = add_implicit_parallel (XVEC (insn, 1));
-  XVEC (insn, 1) = rtvec_alloc (1);
+  XVEC (insn, 1) = rtvec_alloc (1 + n_clobbers);
   XVECEXP (insn, 1, 0) = pattern;
+  for (int i = n_clobbers; i > 0; i--)
+   {
+ rtx clobber = copy_rtx (XVECEXP (ce_elem->data, 0, i));
+ clobber = alter_predicate_for_insn (clobber, alternatives,
+ max_operand, ce_elem->loc);
+ XVECEXP (insn, 1, i) = clobber;
+   }
 
if (XVEC (ce_elem->data, 3) != NULL)
{


Re: doc/tm.texi.in (Condition Code): Tweak post-cc0 wording.

2021-05-16 Thread Segher Boessenkool
On Sat, May 15, 2021 at 08:44:29PM +0200, Hans-Peter Nilsson via Gcc-patches 
wrote:
> When eyeballing the r12-440 / bd1cd0d0e0fe / "Remove
> CC0" commit, I noticed parts that could be improved.
> 
> Regarding the first change: at first I thought that just
> removing the word "better" was the best choice, as the
> compared part (cc0) was apparently removed, but the
> paragraph after the one in the patch (still) does speak of
> "implicit setting" (i.e. cc0-style), but now as hypothetical
> reasoning.  So, just add that to clarify what is not-better.

It is better to remove that hypothetical, imho.

> Condition codes in GCC are represented as registers,

s/,/./ and remove the rest of this paragraph?

> -which provides better schedulability for
> +which provides better schedulability than implicit clobbering for
>  architectures that do have a condition code register, but on which
>  most instructions do not affect it.  The latter category includes
>  most RISC machines.


>  Condition codes in GCC are represented as registers,

s/,/./ and remove the rest as well?

> -which provides better schedulability for
> +which provides better schedulability than implicit clobbering for
>  architectures that do have a condition code register, but on which
>  most instructions do not affect it.  The latter category includes
>  most RISC machines.


> The second change is just that there's no non-modern
> representation, so the "Modern" qualifier is just confusing.

That is just fine of course :-)


I would commit such changes as obvious btw, so if you do so as well, you
can blame me if anyone asks!


Segher


Re: doc/tm.texi.in (Condition Code): Tweak post-cc0 wording.

2021-05-16 Thread Hans-Peter Nilsson via Gcc-patches
> From: Segher Boessenkool 
> Date: Sun, 16 May 2021 18:18:17 +0200

> On Sat, May 15, 2021 at 08:44:29PM +0200, Hans-Peter Nilsson via Gcc-patches 
> wrote:
> > When eyeballing the r12-440 / bd1cd0d0e0fe / "Remove
> > CC0" commit, I noticed parts that could be improved.
> > 
> > Regarding the first change: at first I thought that just
> > removing the word "better" was the best choice, as the
> > compared part (cc0) was apparently removed, but the
> > paragraph after the one in the patch (still) does speak of
> > "implicit setting" (i.e. cc0-style), but now as hypothetical
> > reasoning.  So, just add that to clarify what is not-better.
> 
> It is better to remove that hypothetical, imho.
> 
> > Condition codes in GCC are represented as registers,
> 
> s/,/./ and remove the rest of this paragraph?

Perhaps.  Let's see what a doc maintainer says.

> I would commit such changes as obvious btw, so if you do so as well, you
> can blame me if anyone asks!

The second one likely, but for the first one there was
"obviously" a few different suggestions.

Thanks, for the review!

brgds, H-P


RFA: reduce lra spill failures by splitting likely-spilled-reg hogging pseudo

2021-05-16 Thread Joern Rennecke
Bootstrapped regtested and on x86_64-pc-linux-gnu.
2021-02-22  Joern Rennecke  

lra fix to reduce fatal spill failures.

* lra-constraints.c (split_reg): No longer static.
* lra-int.h (split_reg): Declare.
* lra-assigns.c (lra_split_hard_reg_for): Add strategy to split a
longer range pseudo to accomodate a short range pseudo in a
likely-spilled reg.

diff --git a/gcc/lra-assigns.c b/gcc/lra-assigns.c
index c6a941fe663..4f765bbd8de 100644
--- a/gcc/lra-assigns.c
+++ b/gcc/lra-assigns.c
@@ -1799,6 +1799,35 @@ lra_split_hard_reg_for (void)
bitmap_clear (&failed_reload_pseudos);
return true;
  }
+   /* For a likely spilled class, a pseudo hogging a hard register
+  and a hard reg use are pretty much interchangable.
+  If the use is for adjacent insns, we can win by splitting
+  a conflicting pseudo that has a larger range.  */
+   if (next_nonnote_insn (first) == last
+   && targetm.class_likely_spilled_p (rclass))
+ {
+   int j;
+   rtx_insn *j_first, *j_last;
+   for (j = lra_constraint_new_regno_start; j < max_regno; j++)
+ if (reg_renumber[j] >= 0
+ && REGNO_REG_CLASS (reg_renumber[j]) == rclass
+ && (hard_regno_nregs (reg_renumber[j],
+   GET_MODE (regno_reg_rtx[j]))
+ >= hard_regno_nregs (reg_renumber[j],
+  GET_MODE (regno_reg_rtx[i])))
+ && find_reload_regno_insns (j, j_first, j_last)
+ && j_first != j_last && j_last != last)
+   {
+ for (insn = NEXT_INSN (j_first); insn != j_last;
+  insn = NEXT_INSN (insn))
+   if (insn == first
+   && split_reg (TRUE, j, first, NULL, last))
+ {
+   bitmap_clear (&failed_reload_pseudos);
+   return true;
+ }
+   }
+ }
bitmap_set_bit (&failed_reload_pseudos, i);
   }
   bitmap_clear (&non_reload_pseudos);
diff --git a/gcc/lra-constraints.c b/gcc/lra-constraints.c
index a766f1fd7e8..a13d02a9028 100644
--- a/gcc/lra-constraints.c
+++ b/gcc/lra-constraints.c
@@ -5774,7 +5774,7 @@ lra_copy_reg_equiv (unsigned int new_regno, unsigned int 
original_regno)
register and s is a new split pseudo.  The save is put before INSN
if BEFORE_P is true. Return true if we succeed in such
transformation.  */
-static bool
+bool
 split_reg (bool before_p, int original_regno, rtx_insn *insn,
   rtx next_usage_insns, rtx_insn *to)
 {
diff --git a/gcc/lra-int.h b/gcc/lra-int.h
index 4dadccc79f4..eece250eafb 100644
--- a/gcc/lra-int.h
+++ b/gcc/lra-int.h
@@ -346,6 +346,9 @@ extern void lra_constraints_finish (void);
 extern bool spill_hard_reg_in_range (int, enum reg_class, rtx_insn *, rtx_insn 
*);
 extern void lra_inheritance (void);
 extern bool lra_undo_inheritance (void);
+extern bool split_reg (bool before_p, int original_regno, rtx_insn *insn,
+  rtx next_usage_insns, rtx_insn *to);
+
 
 /* lra-lives.c: */
 


[PATCH] Don't simplify (A & C) != 0 ? D : 0 for pointer types.

2021-05-16 Thread apinski--- via Gcc-patches
From: Andrew Pinski 

While rewriting part of PHI-OPT to use match-and-simplify,
I ran into a bug where this pattern in match.pd would hit
and would produce invalid gimple; a shift of a pointer type.

This just disables this simplification for pointer types similarly
to what is already done in PHI-OPT for the generic A ? D : 0 case.

OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.

Thanks,
Andrew Pinski

gcc/ChangeLog:
* match.pd ((A & C) != 0 ? D : 0): Limit to non pointer types.

gcc/testsuite/ChangeLog:
* testsuite/gcc.dg/gimplefe-45.c: New testcase.
---
 gcc/match.pd   |  2 +-
 gcc/testsuite/gcc.dg/gimplefe-45.c | 19 +++
 2 files changed, 20 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/gimplefe-45.c

diff --git a/gcc/match.pd b/gcc/match.pd
index cdb87636951..10503b97ab5 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -4830,7 +4830,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  (cond
   (ne (bit_and @0 integer_pow2p@1) integer_zerop)
   INTEGER_CST@2 integer_zerop)
- (if (integer_pow2p (@2))
+ (if (!POINTER_TYPE_P (type) && integer_pow2p (@2))
   (with {
  int shift = (wi::exact_log2 (wi::to_wide (@2))
  - wi::exact_log2 (wi::to_wide (@1)));
diff --git a/gcc/testsuite/gcc.dg/gimplefe-45.c 
b/gcc/testsuite/gcc.dg/gimplefe-45.c
new file mode 100644
index 000..b1d3cbb0205
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/gimplefe-45.c
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fgimple" } */
+
+/* This used to ICE when simplifying (A & C) != 0 ? D : 0
+   for pointer types. */
+
+int *__GIMPLE ()
+p (int n)
+{
+  int *_2;
+  int *_t;
+  int *_t1;
+  _t = (int*)8;
+  _t1 = 0;
+  n = n & 2;
+  _2 = n != 0 ? _t : _t1;
+  return _2;
+}
+
-- 
2.27.0



RFA: Add option -fretry-compilation

2021-05-16 Thread Joern Rennecke
For architectures with likely spilled register classes, neither
register allocator is guaranteed
to succeed when using optimization.  If you have just a few files to
compile, you can try
by hand which compiler options will succeed and still give reasonable
code, but for large projects,
hand-tweaking library / program build rules on a file-by-file basis is
time intensive and does not
scale well across different build environments and compiler versions.

The attached patch adds a new option -fretry-compilation that allows
you to specify a list - or
lists - of options to use for a compilation retry, which is
implemented in the compiler driver.

Bootstrapped on x86_64-pc-linux-gnu.
2021-05-16  Joern Rennecke  

* common.opt: New option -fretry-compilation=.
* gcc.c (execute): Implement -fretry-compilation.
* doc/invoke.texi: Document -fretry-compilation.

diff --git a/gcc/common.opt b/gcc/common.opt
index a75b44ee47e..d4db372572f 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -1446,6 +1446,10 @@ Common Driver Var(flag_report_bug)
 Collect and dump debug information into temporary file if ICE in C/C++
 compiler occurred.
 
+fretry-compilation=
+Common Driver RejectNegative Joined Var(retry_compilation_str)
+If the compiler fails, retry with named options appeded.  Separate multiple 
options with ',', and multiple alternatives with ':' .
+
 fdump-internal-locations
 Common Var(flag_dump_locations) Init(0)
 Dump detailed information on GCC's internal representation of source code 
locations.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 519881509a6..8f94fd1aa42 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -541,6 +541,7 @@ Objective-C and Objective-C++ Dialects}.
 -freorder-blocks-algorithm=@var{algorithm} @gol
 -freorder-blocks-and-partition  -freorder-functions @gol
 -frerun-cse-after-loop  -freschedule-modulo-scheduled-loops @gol
+-fretry-compilation=@var{option-list} @gol
 -frounding-math  -fsave-optimization-record @gol
 -fsched2-use-superblocks  -fsched-pressure @gol
 -fsched-spec-load  -fsched-spec-load-dangerous @gol
@@ -10796,6 +10797,44 @@ Perform a number of minor optimizations that are 
relatively expensive.
 
 Enabled at levels @option{-O2}, @option{-O3}, @option{-Os}.
 
+@item -fretry-compilation=@var{option-list}
+@opindex -fretry-compilation
+If the compilation fails, retry with additional options as specified in
+@var{option-list}.  This is actally implemented in the compiler driver,
+but the purpose is that you can use options that sporadically fail, and
+in that case, fall back to another option combination.  This is useful
+e.g. when you compile a large program or library and don't want to tweak
+the rules for each object file.
+option-list can specify one or options in a comma-separated list that are
+added at the end of the option list in a retry.  Multiple retries can be
+separated with a colon.  For example,
+@smallexample
+@option{-O3} @option{-fstd=c90} 
@option{-fretry-compilation=-mno-lra:-fno-tree-partial-pre,-fno-web:-O0}
+@end smallexample
+
+Will first run the compiler with the options
+@smallexample
+@option{-O3} @option{-fstd=c90}
+@end smallexample
+
+If that fails, it will re-try the compilation with:
+
+@smallexample
+@option{-O3} @option{-fstd=c90} @option{-mno-lra}
+@end smallexample
+
+If that too fails, it will re-try compilation with:
+
+@smallexample
+@option{-O3} @option{-fstd=c90} @option{-fno-tree-partial-pre} 
@option{-fno-web}
+@end smallexample
+
+And finally, if that too fails, it will re-try compilation with:
+
+@smallexample
+@option{-O3} @option{-fstd=c90} @option{-O0}
+@end smallexample
+
 @item -free
 @opindex free
 Attempt to remove redundant extension instructions.  This is especially
diff --git a/gcc/gcc.c b/gcc/gcc.c
index 4c1a659d5e8..7b056ac2840 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -3286,6 +3286,9 @@ execute (void)
n_commands++;
   }
 
+ retry:
+  bool retry_compilation_p = false;
+
   /* If -v, print what we are about to do, and maybe query.  */
 
   if (verbose_flag)
@@ -3506,6 +3509,12 @@ execute (void)
  try_generate_repro (commands[0].argv);
if (WEXITSTATUS (status) > greatest_status)
  greatest_status = WEXITSTATUS (status);
+   if (retry_compilation_str
+   && WEXITSTATUS (status) == ICE_EXIT_CODE
+   && i == 0
+   && (p = strrchr (commands[0].argv[0], DIR_SEPARATOR))
+   && ! strncmp (p + 1, "cc1", 3))
+ retry_compilation_p = true;
ret_code = -1;
  }
 
@@ -3561,6 +3570,40 @@ execute (void)
  }
   }
 
+commands[0].argv = argbuf.address ();
+while (retry_compilation_p)
+  {
+   int nargs, n_extra;
+   const char *p, *q, **new_argv;
+   for (nargs = 0; commands[0].argv[nargs] != NULL; ++nargs)
+ /* Only retry compiler ICEs, not preprocessor ones.  */
+ if (! strcmp (commands[0].argv[nargs], "-E"))
+ 

[PATCH] Add a couple of A?CST1:CST2 match and simplify optimizations

2021-05-16 Thread apinski--- via Gcc-patches
From: Andrew Pinski 

Instead of some of the more manual optimizations inside phi-opt,
it would be good idea to do a lot of the heavy lifting inside match
and simplify instead. In the process, this moves the three simple
A?CST1:CST2 (where CST1 or CST2 is zero) simplifications.

OK? Boostrapped and tested on x86_64-linux-gnu with no regressions.

Thanks,
Andrew Pinski

gcc:
* match.pd (A?CST1:CST2): Add simplifcations for A?0:+-1, A?+-1:0,
A?POW2:0 and A?0:POW2.
---
 gcc/match.pd | 37 +
 1 file changed, 37 insertions(+)

diff --git a/gcc/match.pd b/gcc/match.pd
index 10503b97ab5..844f7dd5f87 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -3711,6 +3711,43 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(if (integer_all_onesp (@1) && integer_zerop (@2))
 @0
 
+/* A few simplifications of "a ? CST1 : CST2". */
+/* NOTE: Only do this on gimple as the if-chain-to-switch
+   optimization depends on the gimple to have if statements in it. */
+#if GIMPLE
+(simplify
+ (cond @0 INTEGER_CST@1 INTEGER_CST@2)
+ (switch
+  (if (integer_zerop (@2))
+   (switch
+/* a ? 1 : 0 -> a if 0 and 1 are integral types. */
+(if (integer_onep (@1))
+ (convert (convert:boolean_type_node @0)))
+/* a ? -1 : 0 -> -a. */
+(if (integer_all_onesp (@1))
+ (negate (convert (convert:boolean_type_node @0
+/* a ? powerof2cst : 0 -> a << (log2(powerof2cst)) */
+(if (!POINTER_TYPE_P (type) && integer_pow2p (@1))
+ (with {
+   tree shift = build_int_cst (integer_type_node, wi::exact_log2 
(wi::to_wide (@1)));
+  }
+  (lshift (convert (convert:boolean_type_node @0)) { shift; })
+  (if (integer_zerop (@1))
+   (switch
+/* a ? 0 : 1 -> !a. */
+(if (integer_onep (@2))
+ (convert (bit_not:boolean_type_node (convert:boolean_type_node @0
+/* a ? -1 : 0 -> -(!a). */
+(if (integer_all_onesp (@2))
+ (negate (convert (bit_not:boolean_type_node (convert:boolean_type_node 
@0)
+/* a ? powerof2cst : 0 -> (!a) << (log2(powerof2cst)) */
+(if (!POINTER_TYPE_P (type) && integer_pow2p (@2))
+ (with {
+   tree shift = build_int_cst (integer_type_node, wi::exact_log2 
(wi::to_wide (@2)));
+  }
+  (lshift (convert (bit_not:boolean_type_node (convert:boolean_type_node 
@0))) { shift; })))
+#endif
+
 /* Simplification moved from fold_cond_expr_with_comparison.  It may also
be extended.  */
 /* This pattern implements two kinds simplification:
-- 
2.27.0



RFA: Don't squash target character arrays into a narrower host string

2021-05-16 Thread Joern Rennecke
braced_list_to_string creates a host string, so it's not suitable when
e.g. the host
has 8 bit chars, but the target has 16 bit chars.

The attached patch checks if  host and target char sizes are different
and in that case
falls back to leaving the array as an array.

Bootstrapped on x86_64-pc-linux-gnu.

FWIW, we also have patches for cpplib / lexer / parser char and string
handling to make 8 -> 16 bit char cross-compiling work, but they can't
be ported forward easily because the parser has changed since gcc9.
2021-04-16  Joern Rennecke  

* c-family/c-common.c (braced_lists_to_strings): Don't call
braced_list_to_string if host and target character sizes don't match.

diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index 7bd799d1825..5e87d8ba4df 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -9169,7 +9169,7 @@ braced_lists_to_strings (tree type, tree ctor, bool 
member)
 return ctor;
 
   if ((TREE_CODE (ttp) == ARRAY_TYPE || TREE_CODE (ttp) == INTEGER_TYPE)
-  && TYPE_STRING_FLAG (ttp))
+  && TYPE_STRING_FLAG (ttp) && TYPE_PRECISION (char_type_node) == CHAR_BIT)
 return braced_list_to_string (type, ctor, member);
 
   code = TREE_CODE (ttp);


Re: RFA: Improve message for wrong number of alternatives

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

On 5/16/21 7:57 AM, Joern Rennecke wrote:

When you have lots of operands and lots of alternatives in a pattern,
it is often not immediately apparent if the problem is in the
indicated alternative or in the one that genoutput uses as a reference
for the 'correct' number of alternatives, and/or if you dropped a
comma or had one too many.  By making genoutput tell you what the
argument counts are, this gets a little bit easier.

Bootstrapped on x86_64-pc-linux-gnu.



I think it's very helpful to provide this sort of detail.  Just as
a matter of readability, the new error message

  "wrong number of alternatives in operand %d, %d, expected %d"

would be improved by avoiding the two consecutive %d's, e.g., by
rephrasing it like so:

  "%d alternatives provided to operand %d where %d are expected"

or similar (see gcc/po/gcc.pot for examples).  I would suggest to
consider adjusting it.

Martin


[PATCH V2] Split loop for NE condition.

2021-05-16 Thread Jiufu Guo via Gcc-patches
When there is the possibility that overflow/wrap may happen on the loop index,
a few optimizations would not happen. For example code:

foo (int *a, int *b, unsigned k, unsigned n)
{
  while (++k != n)
a[k] = b[k]  + 1;
}

For this code, if "k > n", k would wrap.  if "k < n" at begining,
it could be optimized (e.g. vectorization).

We can split the loop into two loops:

  while (++k > n)
a[k] = b[k]  + 1;
  while (l++ < n)
a[k] = b[k]  + 1;

then for the second loop, it could be optimized.

This patch is spltting this kind of small loop to achieve better performance.

Bootstrap and regtest pass on ppc64le.  Is this ok for trunk?

Thanks!

Jiufu Guo.

gcc/ChangeLog:

2021-05-15  Jiufu Guo  

* tree-ssa-loop-split.c (connect_loop_phis): Add new param.
(get_ne_cond_branch): New function.
(split_ne_loop): New function.
(split_loop_on_ne_cond): New function.
(tree_ssa_split_loops): Use split_loop_on_ne_cond.

gcc/testsuite/ChangeLog:

2021-05-15  Jiufu Guo  

* gcc.dg/loop-split1.c: New test.
* g++.dg/vect/pr98064.cc: Suppress warning.
---
 gcc/testsuite/g++.dg/vect/pr98064.cc |   4 +-
 gcc/testsuite/gcc.dg/loop-split1.c   | 108 +++
 gcc/tree-ssa-loop-split.c| 188 ++-
 3 files changed, 296 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/loop-split1.c

diff --git a/gcc/testsuite/g++.dg/vect/pr98064.cc 
b/gcc/testsuite/g++.dg/vect/pr98064.cc
index 74043ce7725..dcb2985d05a 100644
--- a/gcc/testsuite/g++.dg/vect/pr98064.cc
+++ b/gcc/testsuite/g++.dg/vect/pr98064.cc
@@ -1,5 +1,7 @@
 // { dg-do compile }
-// { dg-additional-options "-O3" }
+// { dg-additional-options "-O3 -Wno-stringop-overflow" }
+/* There is warning message when "short g = var_8; g; g++"
+   is optimized/analyzed as string operation,e.g. memset.  */
 
 const long long &min(const long long &__a, long long &__b) {
   if (__b < __a)
diff --git a/gcc/testsuite/gcc.dg/loop-split1.c 
b/gcc/testsuite/gcc.dg/loop-split1.c
new file mode 100644
index 000..30b006b1b14
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/loop-split1.c
@@ -0,0 +1,108 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fsplit-loops -fdump-tree-lsplit-details" } */
+
+void
+foo (int *a, int *b, unsigned l, unsigned n)
+{
+  while (++l != n)
+a[l] = b[l]  + 1;
+}
+void
+foo_1 (int *a, int *b, unsigned n)
+{
+  unsigned l = 0;
+  while (++l != n)
+a[l] = b[l]  + 1;
+}
+
+void
+foo1 (int *a, int *b, unsigned l, unsigned n)
+{
+  while (l++ != n)
+a[l] = b[l]  + 1;
+}
+
+/* No wrap.  */
+void
+foo1_1 (int *a, int *b, unsigned n)
+{
+  unsigned l = 0;
+  while (l++ != n)
+a[l] = b[l]  + 1;
+}
+
+unsigned
+foo2 (char *a, char *b, unsigned l, unsigned n)
+{
+  while (++l != n)
+if (a[l] != b[l])
+  break;
+
+  return l;
+}
+
+unsigned
+foo2_1 (char *a, char *b, unsigned l, unsigned n)
+{
+  l = 0;
+  while (++l != n)
+if (a[l] != b[l])
+  break;
+
+  return l;
+}
+
+unsigned
+foo3 (char *a, char *b, unsigned l, unsigned n)
+{
+  while (l++ != n)
+if (a[l] != b[l])
+  break;
+
+  return l;
+}
+
+/* No wrap.  */
+unsigned
+foo3_1 (char *a, char *b, unsigned l, unsigned n)
+{
+  l = 0;
+  while (l++ != n)
+if (a[l] != b[l])
+  break;
+
+  return l;
+}
+
+void bar();
+void foo4(unsigned n,  unsigned i)
+{
+  do
+{
+  if (i == n)
+return;
+  bar();
+  ++i;
+}
+  while (1);
+}
+
+unsigned
+foo5 (double *a, unsigned n, unsigned i)
+{
+  while (a[i] > 0 && i != n)
+i++;
+
+  return i;
+}
+
+unsigned
+find_skip_diff (char *p, char *q, unsigned n, unsigned i)
+{
+  while (p[i] == q[i] && ++i != n)
+p++,q++;
+
+  return i;
+}
+
+/* { dg-final { scan-tree-dump-times "Loop split" 9 "lsplit" } } */
diff --git a/gcc/tree-ssa-loop-split.c b/gcc/tree-ssa-loop-split.c
index 3a09bbc39e5..5c1742b5ff4 100644
--- a/gcc/tree-ssa-loop-split.c
+++ b/gcc/tree-ssa-loop-split.c
@@ -41,6 +41,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "cfghooks.h"
 #include "gimple-fold.h"
 #include "gimplify-me.h"
+#include "tree-ssa-loop-ivopts.h"
 
 /* This file implements two kinds of loop splitting.
 
@@ -233,7 +234,8 @@ easy_exit_values (class loop *loop)
this.  The loops need to fulfill easy_exit_values().  */
 
 static void
-connect_loop_phis (class loop *loop1, class loop *loop2, edge new_e)
+connect_loop_phis (class loop *loop1, class loop *loop2, edge new_e,
+  bool use_prev = false)
 {
   basic_block rest = loop_preheader_edge (loop2)->src;
   gcc_assert (new_e->dest == rest);
@@ -279,7 +281,8 @@ connect_loop_phis (class loop *loop1, class loop *loop2, 
edge new_e)
 
   gphi * newphi = create_phi_node (new_init, rest);
   add_phi_arg (newphi, init, skip_first, UNKNOWN_LOCATION);
-  add_phi_arg (newphi, next, new_e, UNKNOWN_LOCATION);
+  add_phi_arg (newphi, use_prev ? PHI_RESULT (phi_first) : next, new_e,
+  UNKNOWN_LOCATION);
  

[PATCH] Update mpfr version to 3.1.6

2021-05-16 Thread Richard Biener
This updates the mpfr version to 3.1.6 which is the last bugfix
release from the 3.1.x series and avoids printing the version
is buggy but acceptable from our configury.

Pushed.

2021-05-17  Richard Biener  

contrib/
* download_prerequesites: Update mpfr version to 3.1.6.
* prerequisites.md5: Update.
* prerequisites.sha512: Likewise.
---
 contrib/download_prerequisites | 2 +-
 contrib/prerequisites.md5  | 2 +-
 contrib/prerequisites.sha512   | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/contrib/download_prerequisites b/contrib/download_prerequisites
index 7d0c4b5ea8d..51e715f69e1 100755
--- a/contrib/download_prerequisites
+++ b/contrib/download_prerequisites
@@ -28,7 +28,7 @@ version='(unversioned)'
 # `contrib/prerequisites.md5` with the new checksums.
 
 gmp='gmp-6.1.0.tar.bz2'
-mpfr='mpfr-3.1.4.tar.bz2'
+mpfr='mpfr-3.1.6.tar.bz2'
 mpc='mpc-1.0.3.tar.gz'
 isl='isl-0.18.tar.bz2'
 
diff --git a/contrib/prerequisites.md5 b/contrib/prerequisites.md5
index cc71e0f4de6..272f7a429b6 100644
--- a/contrib/prerequisites.md5
+++ b/contrib/prerequisites.md5
@@ -1,4 +1,4 @@
 86ee6e54ebfc4a90b643a65e402c4048  gmp-6.1.0.tar.bz2
-b8a2f6b0e68bef46e53da2ac439e1cf4  mpfr-3.1.4.tar.bz2
+320c28198def956aeacdb240b46b8969  mpfr-3.1.6.tar.bz2
 d6a1d5f8ddea3abd2cc3e98f58352d26  mpc-1.0.3.tar.gz
 11436d6b205e516635b666090b94ab32  isl-0.18.tar.bz2
diff --git a/contrib/prerequisites.sha512 b/contrib/prerequisites.sha512
index cf6b93b8d6b..71601457cfc 100644
--- a/contrib/prerequisites.sha512
+++ b/contrib/prerequisites.sha512
@@ -1,4 +1,4 @@
 
3c82aeab9c1596d4da8afac2eec38e429e84f3211e1a572cf8fd2b546493c44c039b922a1133eaaa48bd7f3e11dbe795a384e21ed95cbe3ecc58d7ac02246117
  gmp-6.1.0.tar.bz2
-51066066ff2c12ed2198605ecf68846b0c96b548adafa5b80e0c786d0df488411a5e8973358fce7192dc977ad4e68414cf14500e3c39746de62465eb145bb819
  mpfr-3.1.4.tar.bz2
+0c310dd7956be527884f8059c195a5aca1042b089d0927ac6341e6310b1250a7059bc61b4dfb76c6ab8b67e440878ca203f72674529bbcb46770ed9b6885
  mpfr-3.1.6.tar.bz2
 
0028b76df130720c1fad7de937a0d041224806ce5ef76589f19c7b49d956071a683e2f20d154c192a231e69756b19e48208f2889b0c13950ceb7b3cfaf059a43
  mpc-1.0.3.tar.gz
 
85d0b40f4dbf14cb99d17aa07048cdcab2dc3eb527d2fbb1e84c41b2de5f351025370e57448b63b2b8a8cf8a0843a089c3263f9baee1542d5c2e1cb37ed39d94
  isl-0.18.tar.bz2
-- 
2.26.2