[PATCH 1/3] S/390: Rework shift count handling.

2019-07-07 Thread Robin Dapp
Add s390_valid_shift_count to determine the validity of a
shift-count operand.  This is used to replace increasingly
complex substitutions that should have allowed address-style
shift-count handling, an and mask as well as no-op subregs
on the operand.

--

gcc/ChangeLog:

2019-07-05  Robin Dapp  

* config/s390/constraints.md: Add new jsc constraint.
* config/s390/predicates.md: New predicates.
* config/s390/s390-protos.h (s390_valid_shift_count): New function.
* config/s390/s390.c (s390_valid_shift_count): New function.
(print_shift_count_operand): Use s390_valid_shift_count.
(print_operand): Likewise.
* config/s390/s390.md: Use new predicate.
* config/s390/subst.md: Remove addr_style_op and masked_op substs.
* config/s390/vector.md: Use new predicate.
---
 gcc/config/s390/constraints.md | 12 ++
 gcc/config/s390/predicates.md  | 29 ++
 gcc/config/s390/s390-protos.h  |  1 +
 gcc/config/s390/s390.c | 66 ++-
 gcc/config/s390/s390.md| 43 ++--
 gcc/config/s390/subst.md   | 72 --
 gcc/config/s390/vector.md  | 14 ---
 7 files changed, 138 insertions(+), 99 deletions(-)

diff --git a/gcc/config/s390/constraints.md b/gcc/config/s390/constraints.md
index 4055cbc7c68..45d41ae8bf8 100644
--- a/gcc/config/s390/constraints.md
+++ b/gcc/config/s390/constraints.md
@@ -204,6 +204,18 @@
   (match_test "s390_decompose_addrstyle_without_index (op, NULL, NULL)"  ))
 
 
+;; Shift count operands are not necessarily legitimate addresses
+;; but the predicate shift_count_operand will only allow
+;; proper operands.  If reload/lra need to change e.g. a spilled register
+;; they can still do so via the special handling of address constraints.
+;; To avoid further reloading (caused by a non-matching constraint) we
+;; always return true here as the predicate's checks are already sufficient.
+
+(define_address_constraint "jsc"
+  "Address style operand used as shift count."
+  (match_test "true" ))
+
+
 ;;N -- Multiple letter constraint followed by 4 parameter letters.
 ;; 0..9,x:  number of the part counting from most to least significant
 ;; S,H,Q:   mode of the part
diff --git a/gcc/config/s390/predicates.md b/gcc/config/s390/predicates.md
index 92c602e4add..4d2f8b25d83 100644
--- a/gcc/config/s390/predicates.md
+++ b/gcc/config/s390/predicates.md
@@ -556,3 +556,32 @@
 {
   return memory_operand (op, mode) && !contains_symbol_ref_p (op);
 })
+
+;; Check for a valid shift count operand with an implicit
+;; shift truncation mask of 63.
+
+(define_predicate "shift_count_operand"
+ (and (match_code "reg, subreg, and, plus, const_int")
+  (match_test "CONST_INT_P (op) || GET_MODE (op) == E_QImode"))
+{
+  return s390_valid_shift_count (op, 63);
+}
+)
+
+;; This is used as operand predicate.  As we do not know
+;; the mode of the first operand here and the shift truncation
+;; mask depends on the mode, we cannot check the mask.
+;; This is supposed to happen in the insn condition which
+;; calls s390_valid_shift_count with the proper mode size.
+;; We need two separate predicates for non-vector and vector
+;; shifts since the (less restrictive) insn condition is checked
+;; after the more restrictive operand predicate which will
+;; disallow the operand before we can check the condition.
+
+(define_predicate "shift_count_operand_vec"
+ (and (match_code "reg, subreg, and, plus, const_int")
+  (match_test "CONST_INT_P (op) || GET_MODE (op) == E_QImode"))
+{
+  return s390_valid_shift_count (op, 0);
+}
+)
diff --git a/gcc/config/s390/s390-protos.h b/gcc/config/s390/s390-protos.h
index b162b26b344..ae70b2fee18 100644
--- a/gcc/config/s390/s390-protos.h
+++ b/gcc/config/s390/s390-protos.h
@@ -141,6 +141,7 @@ extern void s390_emit_tpf_eh_return (rtx);
 extern bool s390_legitimate_address_without_index_p (rtx);
 extern bool s390_decompose_addrstyle_without_index (rtx, rtx *,
HOST_WIDE_INT *);
+extern bool s390_valid_shift_count (rtx op, HOST_WIDE_INT required_mask = 63);
 extern int s390_branch_condition_mask (rtx);
 extern int s390_compare_and_branch_condition_mask (rtx);
 extern bool s390_extzv_shift_ok (int, int, unsigned HOST_WIDE_INT);
diff --git a/gcc/config/s390/s390.c b/gcc/config/s390/s390.c
index 5ec26a0592b..324d9d23210 100644
--- a/gcc/config/s390/s390.c
+++ b/gcc/config/s390/s390.c
@@ -3131,6 +3131,49 @@ s390_decompose_addrstyle_without_index (rtx op, rtx 
*base,
return true;
 }
 
+/*  Check that OP is a valid shift count operand.
+It should be of the following structure:
+  (subreg (and (plus (reg imm_op)) 2^k-1) 7)
+where subreg, and and plus are optional.
+
+If IMPLICIT_MASK is > 0 and OP contains and
+  (AND ... immediate)
+it is checked whether IMPLICIT_MASK and the immediate match.
+Otherwise, no checking is performed.
+  */
+bool
+s

[PATCH 3/3] S/390: Define shift_truncation_mask.

2019-07-07 Thread Robin Dapp
Define s390_shift_truncation_mask to allow the optabs optimization

sh = (64 - sh)
 -> sh = -sh

for a rotation operation.

--

gcc/ChangeLog:

2019-07-05  Robin Dapp  

* config/s390/s390.c (s390_shift_truncation_mask): Define.
(TARGET_SHIFT_TRUNCATION_MASK): Define.

gcc/testsuite/ChangeLog:

2019-07-05  Robin Dapp  

* gcc.target/s390/rotate-truncation-mask.c: New test.
---
 gcc/config/s390/s390.c|  8 
 .../gcc.target/s390/rotate-truncation-mask.c  | 11 +++
 2 files changed, 19 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/s390/rotate-truncation-mask.c

diff --git a/gcc/config/s390/s390.c b/gcc/config/s390/s390.c
index 324d9d23210..75b0b5b4790 100644
--- a/gcc/config/s390/s390.c
+++ b/gcc/config/s390/s390.c
@@ -16412,7 +16412,13 @@ s390_sched_dependencies_evaluation (rtx_insn *head, 
rtx_insn *tail)
   add_dependence (r11_restore, r15_restore, REG_DEP_ANTI);
 }
 
+/* Implement TARGET_SHIFT_TRUNCATION_MASK for integer shifts.  */
 
+static unsigned HOST_WIDE_INT
+s390_shift_truncation_mask (machine_mode mode)
+{
+  return mode == DImode || mode == SImode ? 63 : 0;
+}
 
 /* Initialize GCC target structure.  */
 
@@ -16709,6 +16715,8 @@ s390_sched_dependencies_evaluation (rtx_insn *head, 
rtx_insn *tail)
 #define TARGET_SCHED_DEPENDENCIES_EVALUATION_HOOK \
   s390_sched_dependencies_evaluation
 
+#undef TARGET_SHIFT_TRUNCATION_MASK
+#define TARGET_SHIFT_TRUNCATION_MASK s390_shift_truncation_mask
 
 /* Use only short displacement, since long displacement is not available for
the floating point instructions.  */
diff --git a/gcc/testsuite/gcc.target/s390/rotate-truncation-mask.c 
b/gcc/testsuite/gcc.target/s390/rotate-truncation-mask.c
new file mode 100644
index 000..1cdd20913b9
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/rotate-truncation-mask.c
@@ -0,0 +1,11 @@
+/* Check that we do not use (64 - sh) for rotating.  */
+
+/* { dg-options "-O1 -m64" } */
+
+/* { dg-final { scan-assembler "lcr\t%r.+,%r.+" } } */
+/* { dg-final { scan-assembler-not "lhi\t%r.+,64" } } */
+/* { dg-final { scan-assembler-not "sr\t%r.+,%r.+" } } */
+unsigned long rotr (unsigned long in, unsigned long sh)
+{
+   return (in >> sh) | (in << (64 - sh));
+}
-- 
2.17.0



[PATCH 2/3] S/390: Shift count tests.

2019-07-07 Thread Robin Dapp
Tests to check for the changed shift-count handling.

--

gcc/testsuite/ChangeLog:

2019-07-05  Robin Dapp  

* gcc.target/s390/combine-rotate-modulo.c: New test.
* gcc.target/s390/combine-shift-rotate-add-mod.c: New test.
* gcc.target/s390/vector/combine-shift-vec.c: New test.
---
 .../gcc.target/s390/combine-rotate-modulo.c   |  36 ++
 .../s390/combine-shift-rotate-add-mod.c   |  29 +
 .../s390/vector/combine-shift-vec.c   | 107 ++
 3 files changed, 172 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/s390/combine-rotate-modulo.c
 create mode 100644 gcc/testsuite/gcc.target/s390/combine-shift-rotate-add-mod.c
 create mode 100644 gcc/testsuite/gcc.target/s390/vector/combine-shift-vec.c

diff --git a/gcc/testsuite/gcc.target/s390/combine-rotate-modulo.c 
b/gcc/testsuite/gcc.target/s390/combine-rotate-modulo.c
new file mode 100644
index 000..6cbbb552cd1
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/combine-rotate-modulo.c
@@ -0,0 +1,36 @@
+/* Check that we do not emit & 63 via risbg for rotating.  */
+
+/* { dg-options "-O1 -m64" } */
+
+/* { dg-final { scan-assembler-not "risbg" } } */
+/* { dg-final { scan-assembler-not "nilf" } } */
+
+long shiftl (long in, unsigned long sh)
+{
+   sh %= 64;
+   return (in << sh);
+}
+
+unsigned long shiftll (unsigned long in, unsigned long sh)
+{
+   sh %= 64;
+   return (in << sh);
+}
+
+long shiftr (long in, unsigned long sh)
+{
+   sh %= 64;
+   return (in >> sh);
+}
+
+unsigned long shiftrl (unsigned long in, unsigned long sh)
+{
+   sh %= 64;
+   return (in >> sh);
+}
+
+unsigned long rotlmod (unsigned long in, unsigned long sh)
+{
+   sh %= 64;
+   return (in << sh) | (in >> (64 - sh));
+}
diff --git a/gcc/testsuite/gcc.target/s390/combine-shift-rotate-add-mod.c 
b/gcc/testsuite/gcc.target/s390/combine-shift-rotate-add-mod.c
new file mode 100644
index 000..dc63bfa1481
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/combine-shift-rotate-add-mod.c
@@ -0,0 +1,29 @@
+/* Check shift via address-style displacement.  There should not be any
+   and operations that the instructions perform implicitly anyway.*/
+
+/* { dg-options "-O1 -m64" } */
+
+/* { dg-final { scan-assembler-not "risbg\t%r.+,.*63" } } */
+/* { dg-final { scan-assembler "rllg\t%r.+,3.%r.+" } } */
+/* { dg-final { scan-assembler "sllg\t%r.+,2.%r.+" } } */
+
+unsigned long rotlmodp (unsigned long in, unsigned long sh)
+{
+   sh = (sh + 3) % 64;
+   return (in << sh) | (in >> (64 - sh));
+}
+
+unsigned long shiftmodp (unsigned long in, unsigned long sh)
+{
+   sh = (sh + 2) % 64;
+   return (in << sh);
+}
+
+/* We expect a displacement of 1 here since combine simplifies
+   modulo 255 when substituting into a QImode subreg.  */
+/* { dg-final { scan-assembler "sllg\t%r.+,1.%r.+" } } */
+unsigned long shiftp (unsigned long in, unsigned long sh)
+{
+   sh = sh + 4097;
+   return (in << sh);
+}
diff --git a/gcc/testsuite/gcc.target/s390/vector/combine-shift-vec.c 
b/gcc/testsuite/gcc.target/s390/vector/combine-shift-vec.c
new file mode 100644
index 000..1ac9496cf9f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/vector/combine-shift-vec.c
@@ -0,0 +1,107 @@
+/* Check vector shift patterns.  */
+
+/* { dg-options "-march=z13 -O1 -m64" } */
+
+/* { dg-final { scan-assembler "veslb\t%v.+,%v.+,2.%r2" } } */
+/* { dg-final { scan-assembler "veslh\t%v.+,%v.+,3.%r2" } } */
+/* { dg-final { scan-assembler "veslf\t%v.+,%v.+,4.%r2" } } */
+/* { dg-final { scan-assembler "veslg\t%v.+,%v.+,5.%r2" } } */
+/* { dg-final { scan-assembler "vesrab\t%v.+,%v.+,2.%r2" } } */
+/* { dg-final { scan-assembler "vesrah\t%v.+,%v.+,3.%r2" } } */
+/* { dg-final { scan-assembler "vesraf\t%v.+,%v.+,4.%r2" } } */
+/* { dg-final { scan-assembler "vesrag\t%v.+,%v.+,5.%r2" } } */
+/* { dg-final { scan-assembler "vesrlb\t%v.+,%v.+,2.%r2" } } */
+/* { dg-final { scan-assembler "vesrlh\t%v.+,%v.+,3.%r2" } } */
+/* { dg-final { scan-assembler "vesrlf\t%v.+,%v.+,4.%r2" } } */
+/* { dg-final { scan-assembler "vesrlg\t%v.+,%v.+,5.%r2" } } */
+/* { dg-final { scan-assembler-not "ahi" } } */
+/* { dg-final { scan-assembler-not "nilf" } } */
+/* { dg-final { scan-assembler-not "risbg" } } */
+
+typedef __attribute__((vector_size(16))) signed char v16qi;
+
+v16qi vshiftlqi (v16qi in, unsigned int sh)
+{
+  sh = (sh + 2) % 8;
+  return (in << sh);
+}
+
+typedef __attribute__((vector_size(16))) signed short v8hi;
+
+v8hi vshiftlhi (v8hi in, unsigned int sh)
+{
+  sh = (sh + 3) % 16;
+  return (in << sh);
+}
+
+typedef __attribute__((vector_size(16))) signed int v4si;
+
+v4si vshiftlsi (v4si in, unsigned int sh)
+{
+  sh = (sh + 4) % 32;
+  return (in << sh);
+}
+
+typedef __attribute__((vector_size(16))) signed long v2di;
+
+v2di vshiftldi (v2di in, unsigned int sh)
+{
+  sh = (sh + 5) % 64;
+  return (in << sh);
+}
+
+typedef __attribute__((vector_size(16))) unsigned char uv16qi;
+
+uv16qi vshiftrqiu (uv16qi in, unsigned int sh)
+{
+  sh = (sh + 2) % 8;
+

[PATCH 0/3] S/390: Shift count improvements.

2019-07-07 Thread Robin Dapp
Hi,

these patches introduce a new predicate that recognizes
shift-count operands instead of the subst patterns we
used before.  This allows introducing (no-op) subregs in
the patterns which was not possible via subst before
(see https://gcc.gnu.org/ml/gcc-patches/2019-05/msg00853.html).
The second patch adds some tests.

The third patch defines the shift_truncation_mask and adds
a test for it.

Bootstrapped and regtested.

Regards
 Robin

---

Robin Dapp (3):
  S/390: Rework shift count handling.
  S/390: Shift count tests.
  S/390: Define shift_truncation_mask.

 gcc/config/s390/constraints.md |  12 ++
 gcc/config/s390/predicates.md  |  29 +
 gcc/config/s390/s390-protos.h  |   1 +
 gcc/config/s390/s390.c |  59 +-
 gcc/config/s390/s390.md|  43 +++
 gcc/config/s390/subst.md   |  72 
 gcc/config/s390/vector.md  |  14 ++-
 .../gcc.target/s390/combine-rotate-modulo.c|  36 ++
 .../s390/combine-shift-rotate-add-mod.c|  29 +
 .../gcc.target/s390/vector/combine-shift-vec.c | 107 ++
 .../gcc.target/s390/rotate-truncation-mask.c   |  11 ++
 11 files changed, 314 insertions(+), 99 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/s390/combine-rotate-modulo.c
 create mode 100644 gcc/testsuite/gcc.target/s390/combine-shift-rotate-add-mod.c
 create mode 100644 gcc/testsuite/gcc.target/s390/vector/combine-shift-vec.c
 create mode 100644 gcc/testsuite/gcc.target/s390/rotate-truncation-mask.c

-- 
2.17.0



Re: [PATCH, RISC-V] Fix ambiguous mode of some compare insn

2019-07-07 Thread Jim Wilson
On Sat, Jul 6, 2019 at 1:26 AM Katsuhiro Suzuki  wrote:
> This patch fixes ambiguous mode of some compare insns of RISC-V.
> Only sge, slt and sle are using  but other compare insns use
> . It seems first group mode settings are ambiguous.

Richard Sandiford submitted a patch that fixes every port, and has the
same RISC-V specific changes plus a few more.  I approved Richard's
patch.

Jim


Re: [07/11] [riscv] Fix ambiguous .md attribute uses

2019-07-07 Thread Jim Wilson
On Fri, Jul 5, 2019 at 11:19 PM Richard Sandiford
 wrote:
> gcc/
> * config/riscv/pic.md (*local_pic_load_s)
> (*local_pic_load_u): Explicitly specify the mode iterator
> referenced by , giving...
> (*local_pic_load_s, *local_pic_load_u): 
> ...these.
> * config/riscv/riscv.md (*sge_)
> (*slt_, *sle_): Explicitly
> use  for the mode attribute.

OK.

Jim


[patch, libfortran] Adjust block size for libgfortran for unformatted reads

2019-07-07 Thread Thomas Koenig

Hello world,

the attached patch sets the I/O block size for unformatted files to
2**17 and makes this, and the block size for formatted files,
adjustable via environment variables.

The main reason is that -fconvert=big-endian was quite slow on
some HPC systems. A bigger buffer should eliminate that.  Also,
People who use unformatted files are likely to write large amounts
of data, so this seems like a good fit.  Finally, some benchmarking
showed that 131072 seemed like a good value to use. Thanks to Jerry
for support.

I didn't change the value for formatted files because, frankly, we are
using a lot of CPU for converting numbers there, so any gain
negligible (unless somebody comes up with a benchmark which says
otherwise).

As this is a change in behavior / new feature, I don't think that
backporting is indicated, but if somebody feels otherwise, please
speak up.

Regression-tested. OK for trunk?

Regards

Thomas

2019-07-07  Thomas König  

PR libfortran/91030
* gfortran.texi (GFORTRAN_BUFFER_SIZE_FORMATTED): Document
(GFORTRAN_BUFFER_SIZE_FORMATTED): Likewise.

2019-07-07  Thomas König  

PR libfortran/91030
* io/unix.c (BUFFER_SIZE): Delete.
(BUFFER_SIZE_FORMATTED_DEFAULT): New variable.
(BUFFER_SIZE_UNFORMATTED_DEFAULT): New variable.
(unix_stream): Add buffer_size.
(buf_read): Use s->buffer_size instead of BUFFER_SIZE.
(buf_write): Likewise.
(buf_init): Add argument unformatted.  Handle block sizes
for unformatted vs. formatted, using defaults if provided.
(fd_to_stream): Add argument unformatted in call to buf_init.
* libgfortran.h (options_t): Add buffer_size_formatted and
buffer_size_unformatted.
* runtime/environ.c (variable_table): Add
GFORTRAN_BUFFER_SIZE_UNFORMATTED and GFORTRAN_BUFFER_SIZE_FORMATTED.

Index: gcc/fortran/gfortran.texi
===
--- gcc/fortran/gfortran.texi	(Revision 273183)
+++ gcc/fortran/gfortran.texi	(Arbeitskopie)
@@ -611,6 +611,8 @@ Malformed environment variables are silently ignor
 * GFORTRAN_LIST_SEPARATOR::  Separator for list output
 * GFORTRAN_CONVERT_UNIT::  Set endianness for unformatted I/O
 * GFORTRAN_ERROR_BACKTRACE:: Show backtrace on run-time errors
+* GFORTRAN_BUFFER_SIZE_FORMATTED:: Buffer size for formatted files.
+* GFORTRAN_BUFFER_SIZE_UNFORMATTED:: Buffer size for unformatted files.
 @end menu
 
 @node TMPDIR
@@ -782,6 +784,20 @@ the backtracing, set the variable to @samp{n}, @sa
 Default is to print a backtrace unless the @option{-fno-backtrace}
 compile option was used.
 
+@node GFORTRAN_BUFFER_SIZE_FORMATTED
+@section @env{GFORTRAN_BUFFER_SIZE_FORMATTED}---Set buffer size for formatted I/O
+
+The @env{GFORTRAN_BUFFER_SIZE_FORMATTED} environment variable
+specifies buffer size in bytes to be used for formatted output.
+The default value is 8192.
+
+@node GFORTRAN_BUFFER_SIZE_UNFORMATTED
+@section @env{GFORTRAN_BUFFER_SIZE_UNFORMATTED}---Set buffer size for unformatted I/O
+
+The @env{GFORTRAN_BUFFER_SIZE_UNFORMATTED} environment variable
+specifies buffer size in bytes to be used for unformatted output.
+The default value is 131072.
+
 @c =
 @c PART II: LANGUAGE REFERENCE
 @c =
Index: libgfortran/io/unix.c
===
--- libgfortran/io/unix.c	(Revision 273183)
+++ libgfortran/io/unix.c	(Arbeitskopie)
@@ -193,7 +193,8 @@ fallback_access (const char *path, int mode)
 
 /* Unix and internal stream I/O module */
 
-static const int BUFFER_SIZE = 8192;
+static const int BUFFER_SIZE_FORMATTED_DEFAULT = 8192;
+static const int BUFFER_SIZE_UNFORMATTED_DEFAULT = 128*1024;
 
 typedef struct
 {
@@ -205,6 +206,7 @@ typedef struct
   gfc_offset file_length;	/* Length of the file. */
 
   char *buffer; /* Pointer to the buffer.  */
+  ssize_t buffer_size;   /* Length of the buffer.  */
   int fd;   /* The POSIX file descriptor.  */
 
   int active;			/* Length of valid bytes in the buffer */
@@ -592,9 +594,9 @@ buf_read (unix_stream *s, void *buf, ssize_t nbyte
   && raw_seek (s, new_logical, SEEK_SET) < 0)
 return -1;
   s->buffer_offset = s->physical_offset = new_logical;
-  if (to_read <= BUFFER_SIZE/2)
+  if (to_read <= s->buffer_size/2)
 {
-  did_read = raw_read (s, s->buffer, BUFFER_SIZE);
+  did_read = raw_read (s, s->buffer, s->buffer_size);
 	  if (likely (did_read >= 0))
 	{
 	  s->physical_offset += did_read;
@@ -632,11 +634,11 @@ buf_write (unix_stream *s, const void *buf, ssize_
 s->buffer_offset = s->logical_offset;
 
   /* Does the data fit into the buffer?  As a special case, if the
- buffer is empty and the request is bigger than BUFFER_SIZE/2,
+ 

Re: Prevent tree-ssa-dce.c from deleting stores at -Og

2019-07-07 Thread Jeff Law
On 7/7/19 3:45 AM, Richard Sandiford wrote:
> DCE tries to delete dead stores to local data and also tries to insert
> debug binds for simple cases:
> 
>   /* If this is a store into a variable that is being optimized away,
>  add a debug bind stmt if possible.  */
>   if (MAY_HAVE_DEBUG_BIND_STMTS
>   && gimple_assign_single_p (stmt)
>   && is_gimple_val (gimple_assign_rhs1 (stmt)))
> {
>   tree lhs = gimple_assign_lhs (stmt);
>   if ((VAR_P (lhs) || TREE_CODE (lhs) == PARM_DECL)
> && !DECL_IGNORED_P (lhs)
> && is_gimple_reg_type (TREE_TYPE (lhs))
> && !is_global_var (lhs)
> && !DECL_HAS_VALUE_EXPR_P (lhs))
>   {
> tree rhs = gimple_assign_rhs1 (stmt);
> gdebug *note
>   = gimple_build_debug_bind (lhs, unshare_expr (rhs), stmt);
> gsi_insert_after (i, note, GSI_SAME_STMT);
>   }
> }
> 
> But this doesn't help for things like "print *ptr" when ptr points
> to the local variable (tests Og-dce-1.c and Og-dce-2.c).  It also tends
> to make the *live* -- and thus useful -- values optimised out, because
> we can't yet switch back to tracking the memory location as it evolves
> over time (test Og-dce-3.c).
> 
> So for -Og I think it'd be better not to delete any stmts with
> vdefs for now.  This also means that we can avoid the potentially
> expensive vop walks (which already have a cut-off, but still).
> 
> The patch also fixes the Og failures in gcc.dg/guality/pr54970.c
> (PR 86638).
> 
> Tested on aarch64-linux-gnu and x86_64-linux-gnu.  OK to install?
> 
> Richard
> 
> 
> 2019-07-07  Richard Sandiford  
> 
> gcc/
>   PR debug/86638
>   * tree-ssa-dce.c (keep_all_vdefs_p): New function.
>   (mark_stmt_if_obviously_necessary): Mark all stmts with vdefs as
>   necessary if keep_all_vdefs_p is true.
>   (mark_aliased_reaching_defs_necessary): Add a gcc_checking_assert
>   that keep_all_vdefs_p is false.
>   (mark_all_reaching_defs_necessary): Likewise.
>   (propagate_necessity): Skip the vuse scan if keep_all_vdefs_p is true.
> 
> gcc/testsuite/
>   * c-c++-common/guality/Og-dce-1.c: New test.
>   * c-c++-common/guality/Og-dce-2.c: Likewise.
>   * c-c++-common/guality/Og-dce-3.c: Likewise.
OK
jeff


Re: Prevent -Og from deleting stores to write-only variables

2019-07-07 Thread Jakub Jelinek
On Sun, Jul 07, 2019 at 10:41:43AM +0100, Richard Sandiford wrote:
> gcc/testsuite/
>   * c-c++-common/guality/Og-static-wo-1.c: New test.
>   * g++.dg/guality/guality.exp: Separate the c-c++-common tests into
>   "Og" and "general" tests.  Run the latter at -O0 and -Og only.

Do we really want further filename prefixes based tests?
I find it extremely ugly in /vect/ and would appreciate not to add further
ones.
The tests can just use dg-skip-if, can't they?
/* { dg-skip-if "" { *-*-* }  { "*" } { "-O0" "-Og" } } */
would do it.

> --- gcc/testsuite/g++.dg/guality/guality.exp  2019-07-01 10:15:31.0 
> +0100
> +++ gcc/testsuite/g++.dg/guality/guality.exp  2019-07-07 10:29:19.999365874 
> +0100
> @@ -65,8 +65,22 @@ if {[check_guality "
>  return 0;
>}
>  "]} {
> -  gcc-dg-runtest [lsort [glob $srcdir/$subdir/*.C]] "" ""
> -  gcc-dg-runtest [lsort [glob $srcdir/c-c++-common/guality/*.c]] "" ""
> +set general [list]
> +set Og [list]
> +foreach file [lsort [glob $srcdir/c-c++-common/guality/*.c]] {
> + switch -glob -- [file tail $file] {
> + Og-* { lappend Og $file }
> + * { lappend general $file }
> + }
> +}
> +
> +gcc-dg-runtest [lsort [glob $srcdir/$subdir/*.C]] "" ""
> +gcc-dg-runtest $general "" ""
> +set-torture-options \
> + [list "-O0" "-Og"] \
> + [list {}] \
> + [list "-Og -flto"]
> +gcc-dg-runtest $Og "" ""
>  }
>  
>  if [info exists guality_gdb_name] {
> Index: gcc/testsuite/gcc.dg/guality/guality.exp
> ===
> --- gcc/testsuite/gcc.dg/guality/guality.exp  2019-07-01 10:15:31.0 
> +0100
> +++ gcc/testsuite/gcc.dg/guality/guality.exp  2019-07-07 10:29:19.999365874 
> +0100
> @@ -80,8 +80,22 @@ if {[check_guality "
>  return 0;
>}
>  "]} {
> -  gcc-dg-runtest [lsort [glob $srcdir/$subdir/*.c]] "" ""
> -  gcc-dg-runtest [lsort [glob $srcdir/c-c++-common/guality/*.c]] "" 
> "-Wc++-compat"
> +set general [list]
> +set Og [list]
> +foreach file [lsort [glob $srcdir/c-c++-common/guality/*.c]] {
> + switch -glob -- [file tail $file] {
> + Og-* { lappend Og $file }
> + * { lappend general $file }
> + }
> +}
> +
> +gcc-dg-runtest [lsort [glob $srcdir/$subdir/*.c]] "" ""
> +gcc-dg-runtest $general "" "-Wc++-compat"
> +set-torture-options \
> + [list "-O0" "-Og"] \
> + [list {}] \
> + [list "-Og -flto"]
> +gcc-dg-runtest $Og "" "-Wc++-compat"
>  }
>  
>  if [info exists guality_gdb_name] {

Jakub


Re: Don't run DSE at -Og

2019-07-07 Thread Jeff Law
On 7/7/19 3:43 AM, Richard Sandiford wrote:
> This patch stops gimple and rtl DSE from running by default at -Og.
> The idea is both to improve compile time and to stop us from deleting
> stores that we can't track in debug info.
> 
> We could rein this back in future for stores to local variables
> with is_gimple_reg_type, but at the moment we don't have any
> infrastructure for switching between binds to specific values
> and binds to evolving memory locations.  Even then, location
> tracking only works for direct references to the variables, and doesn't
> for example help with printing dereferenced pointers (see the next patch
> in the series for an example).
> 
> I'm also not sure that DSE is important enough for -Og to justify the
> compile time cost -- especially in the case of RTL DSE, which is pretty
> expensive.
> 
> Tested on aarch64-linux-gnu and x86_64-linux-gnu.  OK to install?
> 
> Richard
> 
> 
> 2019-07-07  Richard Sandiford  
> 
> gcc/
>   * common.opt (Og): Change the initial value of flag_dse to 0.
>   * opts.c (default_options_table): Move OPT_ftree_dse from
>   OPT_LEVELS_1_PLUS to OPT_LEVELS_1_PLUS_NOT_DEBUG.  Also add
>   OPT_fdse to OPT_LEVELS_1_PLUS_NOT_DEBUG.  Put the OPT_ftree_pta
>   entry before the OPT_ftree_sra entry.
>   * doc/invoke.texi (Og): Add -fdse and -ftree-dse to the list
>   of flags disabled by Og.
> 
> gcc/testsuite/
>   * c-c++-common/guality/Og-global-dse-1.c: New test.
OK.  I doubt DSE is at all important if someone has asked for Og.

BTW, if you're going to be poking at improving Og or debuginfo in
general, you might want to loop Alex into your plans.  He did a detailed
evaluation of how the various options impact debugging, -Og issues, etc.
 He's no longer with Red Hat, but can be reached at Adacore.

jeff


Re: Prevent -Og from deleting stores to write-only variables

2019-07-07 Thread Jeff Law
On 7/7/19 3:41 AM, Richard Sandiford wrote:
> This patch prevents -Og from deleting stores to write-only variables,
> so that the values are still available when debugging.  This seems
> more convenient than forcing users to use __attribute__((used))
> (probably conditionally, if it's not something they want in release
> builds).
> 
> Tested on aarch64-linux-gnu and x86_64-linux-gnu.  OK to install?
> 
> Richard
> 
> 
> 2019-07-07  Richard Sandiford  
> 
> gcc/
>   * tree-cfg.c (execute_fixup_cfg): Don't delete stores to write-only
>   variables for -Og.
> 
> gcc/testsuite/
>   * c-c++-common/guality/Og-static-wo-1.c: New test.
>   * g++.dg/guality/guality.exp: Separate the c-c++-common tests into
>   "Og" and "general" tests.  Run the latter at -O0 and -Og only.
>   * gcc.dg/guality/guality.exp: Likewise.
OK
jeff


Re: Add a build config for bootstrapping at -Og

2019-07-07 Thread Jeff Law
On 7/7/19 3:40 AM, Richard Sandiford wrote:
> Although BOOT_CFLAGS can be used to bootstrap with -Og, having a
> dedicated build config is sometimes more convenient.
> 
> Tested on aarch64-linux-gnu and x86_64-linux-gnu.  OK to install?
> 
> Richard
> 
> 
> 2019-07-07  Richard Sandiford  
> 
> config/
>   * bootstrap-Og.mk: New file.
> 
> gcc/
>   * doc/install.texi (bootstrap-Og): Document.
OK
jeff


Re: Make guality.h handle Yama restricted ptrace mode

2019-07-07 Thread Jeff Law
On 7/7/19 3:39 AM, Richard Sandiford wrote:
> guality.exp is silently skipped on Linux systems with
> kernel.yama.ptrace_scope=1 because gdb fails to attach to the
> sanity check test.  This patch uses PR_SET_PTRACER (where available)
> to avoid this.
> 
> prctl was apparently added in Linux 2.1.57, so I don't think we
> need any tests other than __linux for the #include.
> 
> Tested on aarch64-linux-gnu and x86_64-linux-gnu.  OK to install?
> 
> Richard
> 
> 
> 2019-07-07  Richard Sandiford  
> 
> gcc/testsuite/
>   * gcc.dg/guality/guality.h: Include  on Linux targets.
>   (main): Use PR_SET_PTRACER where available.
OK
jeff


[committed] [PR tree-optimization/91090] Fix logic error in jump threading

2019-07-07 Thread Jeff Law

This code was copied and reindented from tree-vrp.c.  It looks like in
that process the second conditional moved inside the true arm of the
first conditional, which was wrong.

It won't cause incorrect code, just missed optimizations.  I also
verified that the code is still live -- it triggers during a bootstrap
when building the Fortran front-end for example.  Given that I just
fixed it on the trunk.  I don't think there's much value in fixing on
the release branches.

Bootstrapped and regression tested on x86_64-linux-gnu.

Installed on the trunk.

jeff
commit f60e7cee5700a9f9515ab4e2a922c325149c49e1
Author: law 
Date:   Sun Jul 7 18:42:45 2019 +

PR tree-optimization/91090
* tree-ssa-dom.c (simplify_stmt_for_jump_threading): Fix logic error
in handling of ranges to simplify switch statements.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@273184 
138bc75d-0d04-0410-961f-82ee72b054a4

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 0ef7eb6b93b..9f83f75b0bf 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2019-07-07  Jeff Law  
+
+   PR tree-optimization/91090
+   * tree-ssa-dom.c (simplify_stmt_for_jump_threading): Fix logic error
+   in handling of ranges to simplify switch statements.
+
 2019-07-07  Iain Sandoe  
 
* config/darwin.c (darwin_override_options): Make a final check on PIC
diff --git a/gcc/tree-ssa-dom.c b/gcc/tree-ssa-dom.c
index b0d56fcf3e3..17c852d5299 100644
--- a/gcc/tree-ssa-dom.c
+++ b/gcc/tree-ssa-dom.c
@@ -913,21 +913,26 @@ simplify_stmt_for_jump_threading (gimple *stmt,
 
  find_case_label_range (switch_stmt, vr->min (), vr->max (), &i, &j);
 
+ /* Is there only one such label?  */
  if (i == j)
{
  tree label = gimple_switch_label (switch_stmt, i);
  tree singleton;
 
+ /* The i'th label will only be taken if the value range of the
+operand is entirely within the bounds of this label.  */
  if (CASE_HIGH (label) != NULL_TREE
  ? (tree_int_cst_compare (CASE_LOW (label), vr->min ()) <= 0
 && tree_int_cst_compare (CASE_HIGH (label), vr->max ()) >= 
0)
  : (vr->singleton_p (&singleton)
 && tree_int_cst_equal (CASE_LOW (label), singleton)))
return label;
-
- if (i > j)
-   return gimple_switch_label (switch_stmt, 0);
}
+
+ /* If there are no such labels, then the default label
+will be taken.  */
+ if (i > j)
+   return gimple_switch_label (switch_stmt, 0);
}
 
   if (vr->kind () == VR_ANTI_RANGE)


[PATCH] subreg: Add -fsplit-wide-types-early (PR88233)

2019-07-07 Thread Segher Boessenkool
Currently the second lower-subreg pass is run right before RA.  This
is much too late to be very useful.  At least for targets that do not
have RTL patterns for operations on multi-register modes it is a lot
better to split patterns earlier, before combine and all related
passes.

This adds an option -fsplit-wide-types-early that does that, and
enables it by default for rs6000.


2019-07-07  Segher Boessenkool  

PR rtl-optimization/88233
* common.opt (fsplit-wide-types-early): New option.
* common/config/rs6000/rs6000-common.c
(rs6000_option_optimization_table): Add OPT_fsplit_wide_types_early for
OPT_LEVELS_ALL.
* doc/invoke.texi (Optimization Options): Add -fsplit-wide-types-early.
* lower-subreg.c (pass_lower_subreg2::gate): Add test for
flag_split_wide_types_early.
(pass_data_lower_subreg3): New.
(pass_lower_subreg3): New.
(make_pass_lower_subreg3): New.
* passes.def (pass_lower_subreg2): Move after the loop passes.
(pass_lower_subreg3): New, inserted where pass_lower_subreg2 was.
* tree-pass.h (make_pass_lower_subreg2): Move up, to its new place in
the pass pipeline; its previous place is taken by ...
(make_pass_lower_subreg3): ... this.

---
 gcc/common.opt   |  4 +++
 gcc/common/config/rs6000/rs6000-common.c |  2 ++
 gcc/doc/invoke.texi  |  8 +-
 gcc/lower-subreg.c   | 46 +++-
 gcc/passes.def   |  3 ++-
 gcc/tree-pass.h  |  3 ++-
 6 files changed, 62 insertions(+), 4 deletions(-)

diff --git a/gcc/common.opt b/gcc/common.opt
index 41514df..b998b25 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -2430,6 +2430,10 @@ fsplit-wide-types
 Common Report Var(flag_split_wide_types) Optimization
 Split wide types into independent registers.
 
+fsplit-wide-types-early
+Common Report Var(flag_split_wide_types_early) Optimization
+Split wide types into independent registers earlier.
+
 fssa-backprop
 Common Report Var(flag_ssa_backprop) Init(1) Optimization
 Enable backward propagation of use properties at the SSA level.
diff --git a/gcc/common/config/rs6000/rs6000-common.c 
b/gcc/common/config/rs6000/rs6000-common.c
index 9857b54..4b0c205 100644
--- a/gcc/common/config/rs6000/rs6000-common.c
+++ b/gcc/common/config/rs6000/rs6000-common.c
@@ -31,6 +31,8 @@
 /* Implement TARGET_OPTION_OPTIMIZATION_TABLE.  */
 static const struct default_options rs6000_option_optimization_table[] =
   {
+/* Split multi-word types early.  */
+{ OPT_LEVELS_ALL, OPT_fsplit_wide_types_early, NULL, 1 },
 /* Enable -fsched-pressure for first pass instruction scheduling.  */
 { OPT_LEVELS_1_PLUS, OPT_fsched_pressure, NULL, 1 },
 { OPT_LEVELS_NONE, 0, NULL, 0 }
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 73d16b5..6349d4c 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -467,7 +467,7 @@ Objective-C and Objective-C++ Dialects}.
 -fsignaling-nans @gol
 -fsingle-precision-constant  -fsplit-ivs-in-unroller  -fsplit-loops@gol
 -fsplit-paths @gol
--fsplit-wide-types  -fssa-backprop  -fssa-phiopt @gol
+-fsplit-wide-types  -fsplit-wide-types-early  -fssa-backprop  -fssa-phiopt @gol
 -fstdarg-opt  -fstore-merging  -fstrict-aliasing @gol
 -fthread-jumps  -ftracer  -ftree-bit-ccp @gol
 -ftree-builtin-call-dce  -ftree-ccp  -ftree-ch @gol
@@ -8731,6 +8731,12 @@ but may make debugging more difficult.
 Enabled at levels @option{-O}, @option{-O2}, @option{-O3},
 @option{-Os}.
 
+@item -fsplit-wide-types-early
+@opindex fsplit-wide-types-early
+Fully split wide types early, instead of very late.
+
+This is the default on some targets.
+
 @item -fcse-follow-jumps
 @opindex fcse-follow-jumps
 In common subexpression elimination (CSE), scan through jump instructions
diff --git a/gcc/lower-subreg.c b/gcc/lower-subreg.c
index 4f68a73..e1418e5 100644
--- a/gcc/lower-subreg.c
+++ b/gcc/lower-subreg.c
@@ -1801,7 +1801,8 @@ public:
   {}
 
   /* opt_pass methods: */
-  virtual bool gate (function *) { return flag_split_wide_types != 0; }
+  virtual bool gate (function *) { return flag_split_wide_types
+ && flag_split_wide_types_early; }
   virtual unsigned int execute (function *)
 {
   decompose_multiword_subregs (true);
@@ -1817,3 +1818,46 @@ make_pass_lower_subreg2 (gcc::context *ctxt)
 {
   return new pass_lower_subreg2 (ctxt);
 }
+
+/* Implement third lower subreg pass.  */
+
+namespace {
+
+const pass_data pass_data_lower_subreg3 =
+{
+  RTL_PASS, /* type */
+  "subreg3", /* name */
+  OPTGROUP_NONE, /* optinfo_flags */
+  TV_LOWER_SUBREG, /* tv_id */
+  0, /* properties_required */
+  0, /* properties_provided */
+  0, /* properties_destroyed */
+  0, /* todo_flags_start */
+  TODO_df_finish, /* todo_flags_finish */
+};
+
+class pass_lower_subreg3 : public rtl_opt_pass
+{
+public:
+  pass_l

[Darwin] Make a final check on PIC options.

2019-07-07 Thread Iain Sandoe
In some cases the cascaded settings for pic/pie/PIC/PIE can cause a confusing
scenario for Darwin where "fPIC fno-PIE”  produces a wrong code generation 
setting.

So we make a final check on PIC options; for Darwin these are not dependent on
the PIE ones, although PIE does require PIC to support it.  Specifically, for 
Darwin,
"fPIC fno-PIE" should result in the same as "-fno-PIE -fPIC”.

tested on x86-64-darwin16,
applied to mainline
Iain

2019-07-07  Iain Sandoe  

* config/darwin.c (darwin_override_options): Make a final check on PIC
options.

diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c
index 02bcf01..5ac0925 100644
--- a/gcc/config/darwin.c
+++ b/gcc/config/darwin.c
@@ -3241,6 +3241,8 @@ darwin_override_options (void)
   && write_symbols == DWARF2_DEBUG)
 flag_var_tracking_uninit = flag_var_tracking;
 
+  /* Final check on PIC options; for Darwin these are not dependent on the PIE
+ ones, although PIE does require PIC to support it.  */
   if (MACHO_DYNAMIC_NO_PIC_P)
 {
   if (flag_pic)
@@ -3249,9 +3251,11 @@ darwin_override_options (void)
 " %<-fpie%> or %<-fPIE%>");
   flag_pic = 0;
 }
-  else if (flag_pic == 1)
+  else if (flag_pic == 1
+  || (flag_pic == 0 && !(flag_mkernel || flag_apple_kext)))
 {
-  /* Darwin's -fpic is -fPIC.  */
+  /* Darwin's -fpic is -fPIC.
+We only support "static" code in the kernel and kernel exts.  */
   flag_pic = 2;
 }
 



[Darwin] Don't jam symbol stubs on for kernel code.

2019-07-07 Thread Iain Sandoe
For PPC Darwin, we need the JBSR long jump code to be enabled when generating
kernel code.  Now we have that handled in rs6000.c, we can drop the conflated
setting in the common code.  The gcc-4.2.1 compilers don’t generate symbol stubs
for any X86 case.

tested on x86_64-darwin16,
applied to mainline.
Iain

2019-07-07  Iain Sandoe  

* config/darwin.c (darwin_override_options): Don't jam symbol stubs
on for kernel code.


diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c
index ef6e389..02bcf01 100644
--- a/gcc/config/darwin.c
+++ b/gcc/config/darwin.c
@@ -3232,8 +3232,6 @@ darwin_override_options (void)
   /* so no tables either.. */
   flag_unwind_tables = 0;
   flag_asynchronous_unwind_tables = 0;
-  /* We still need to emit branch islands for kernel context.  */
-  darwin_picsymbol_stubs = true;
 }
 
   if (flag_var_tracking_uninit == 0



[PATCH] rs6000: Delete Ffre

2019-07-07 Thread Segher Boessenkool
It is unused.  Committing.


2019-07-07  Segher Boessenkool  

* config/rs6000/rs6000.md (Ffre): Delete.

---
 gcc/config/rs6000/rs6000.md | 1 -
 1 file changed, 1 deletion(-)

diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
index 9e81df9..3cc42cb6 100644
--- a/gcc/config/rs6000/rs6000.md
+++ b/gcc/config/rs6000/rs6000.md
@@ -545,7 +545,6 @@ (define_mode_attr Fv[(SF "wa") (DF "wa") 
(DI "wa")])
 (define_mode_attr Fisa [(SF "p8v")  (DF "*") (DI "*")])
 
 ; FRE/FRES support
-(define_mode_attr Ffre [(SF "fres") (DF "fre")])
 (define_mode_attr FFRE [(SF "FRES") (DF "FRE")])
 
 ; Conditional returns.
-- 
1.8.3.1



Re: [Patch, fortran] PR91077 - [8/9/10 Regression] Wrong indexing when using a pointer

2019-07-07 Thread Paul Richard Thomas
Thanks, Steve.

Fixed with revisions 273176, 7 & 8.

Paul

On Sat, 6 Jul 2019 at 18:05, Steve Kargl
 wrote:
>
> On Sat, Jul 06, 2019 at 02:29:06PM +0100, Paul Richard Thomas wrote:
> > As anticipated, 8-branch required a different patch but the difference
> > was much smaller than anticipated.
> >
> > Bootstrapped and regetested on FC29/x86_64 - OK for 8-branch?
> >
>
> OK for both patches.
>
> --
> Steve



-- 
"If you can't explain it simply, you don't understand it well enough"
- Albert Einstein


[RFC][PR89245] Check REG_CALL_DECL note during the tail-merging

2019-07-07 Thread Dragan Mladjenovic
From: "Dragan Mladjenovic" 

This patch prevents merging of CALL instructions that that have different
REG_CALL_DECL notes attached to them.

On most architectures this is not an important distinction. Usually instruction 
patterns
for calls to different functions reference different SYMBOL_REF-s, so they 
won't match.
On MIPS PIC calls get split into an got_load/*call_internal pair where the 
latter represents
indirect register call w/o SYMBOL_REF attached (until machine_reorg pass). The 
bugzilla issue
had such two internal_call-s merged despite the fact that they had different 
register usage
information assigned by ipa-ra.

The check could be improved by checking if ipa-ra has actually assigned two 
different
register sets for two functions involved, but I chose to only do a quick 
rtx_equal check.

gcc/ChangeLog:

2019-07-07  Dragan Mladjenovic  

* cfgcleanup.c (old_insns_match_p): Check for equal REG_CALL_DECL notes
on call instructions.

gcc/testsuite/ChangeLog:

2019-07-07  Dragan Mladjenovic  

* gcc.target/mips/cfgcleanup-jalr.c: New test.
---
 gcc/cfgcleanup.c|  9 +
 gcc/testsuite/gcc.target/mips/cfgcleanup-jalr.c | 17 +
 2 files changed, 26 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/mips/cfgcleanup-jalr.c

diff --git a/gcc/cfgcleanup.c b/gcc/cfgcleanup.c
index 992912c..9903249 100644
--- a/gcc/cfgcleanup.c
+++ b/gcc/cfgcleanup.c
@@ -1224,6 +1224,15 @@ old_insns_match_p (int mode ATTRIBUTE_UNUSED, rtx_insn 
*i1, rtx_insn *i2)
}
}
}
+
+  n1 = find_reg_note (i1, REG_CALL_DECL, 0);
+  n2 = find_reg_note (i2, REG_CALL_DECL, 0);
+
+  if (!n1 && n2)
+return dir_none;
+
+  if (n1 && (!n2 || !rtx_equal_p (XEXP (n1, 0), XEXP (n2, 0
+return dir_none;
 }
 
   /* If both i1 and i2 are frame related, verify all the CFA notes
diff --git a/gcc/testsuite/gcc.target/mips/cfgcleanup-jalr.c 
b/gcc/testsuite/gcc.target/mips/cfgcleanup-jalr.c
new file mode 100644
index 000..a4c0c47
--- /dev/null
+++ b/gcc/testsuite/gcc.target/mips/cfgcleanup-jalr.c
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-options "-mabicalls -fpic" } */
+
+extern void foo (void*);
+
+extern void bar (void*);
+
+void test (void* p)
+{
+   if (!p)
+   foo(p);
+   else
+   bar(p);
+}
+
+/* { dg-final { scan-assembler "\\\.reloc\t1f,R_MIPS_JALR,foo" } } */
+/* { dg-final { scan-assembler "\\\.reloc\t1f,R_MIPS_JALR,bar" } } */
-- 
1.9.1



Prevent tree-ssa-dce.c from deleting stores at -Og

2019-07-07 Thread Richard Sandiford
DCE tries to delete dead stores to local data and also tries to insert
debug binds for simple cases:

  /* If this is a store into a variable that is being optimized away,
 add a debug bind stmt if possible.  */
  if (MAY_HAVE_DEBUG_BIND_STMTS
  && gimple_assign_single_p (stmt)
  && is_gimple_val (gimple_assign_rhs1 (stmt)))
{
  tree lhs = gimple_assign_lhs (stmt);
  if ((VAR_P (lhs) || TREE_CODE (lhs) == PARM_DECL)
  && !DECL_IGNORED_P (lhs)
  && is_gimple_reg_type (TREE_TYPE (lhs))
  && !is_global_var (lhs)
  && !DECL_HAS_VALUE_EXPR_P (lhs))
{
  tree rhs = gimple_assign_rhs1 (stmt);
  gdebug *note
= gimple_build_debug_bind (lhs, unshare_expr (rhs), stmt);
  gsi_insert_after (i, note, GSI_SAME_STMT);
}
}

But this doesn't help for things like "print *ptr" when ptr points
to the local variable (tests Og-dce-1.c and Og-dce-2.c).  It also tends
to make the *live* -- and thus useful -- values optimised out, because
we can't yet switch back to tracking the memory location as it evolves
over time (test Og-dce-3.c).

So for -Og I think it'd be better not to delete any stmts with
vdefs for now.  This also means that we can avoid the potentially
expensive vop walks (which already have a cut-off, but still).

The patch also fixes the Og failures in gcc.dg/guality/pr54970.c
(PR 86638).

Tested on aarch64-linux-gnu and x86_64-linux-gnu.  OK to install?

Richard


2019-07-07  Richard Sandiford  

gcc/
PR debug/86638
* tree-ssa-dce.c (keep_all_vdefs_p): New function.
(mark_stmt_if_obviously_necessary): Mark all stmts with vdefs as
necessary if keep_all_vdefs_p is true.
(mark_aliased_reaching_defs_necessary): Add a gcc_checking_assert
that keep_all_vdefs_p is false.
(mark_all_reaching_defs_necessary): Likewise.
(propagate_necessity): Skip the vuse scan if keep_all_vdefs_p is true.

gcc/testsuite/
* c-c++-common/guality/Og-dce-1.c: New test.
* c-c++-common/guality/Og-dce-2.c: Likewise.
* c-c++-common/guality/Og-dce-3.c: Likewise.

Index: gcc/tree-ssa-dce.c
===
--- gcc/tree-ssa-dce.c  2019-06-29 17:20:49.0 +0100
+++ gcc/tree-ssa-dce.c  2019-07-07 10:34:47.616717593 +0100
@@ -115,6 +115,14 @@ #define STMT_NECESSARY GF_PLF_1
 static int *bb_postorder;
 
 
+/* True if we should treat any stmt with a vdef as necessary.  */
+
+static inline bool
+keep_all_vdefs_p ()
+{
+  return optimize_debug;
+}
+
 /* If STMT is not already marked necessary, mark it, and add it to the
worklist if ADD_TO_WORKLIST is true.  */
 
@@ -311,6 +319,12 @@ mark_stmt_if_obviously_necessary (gimple
   return;
 }
 
+  if (gimple_vdef (stmt) && keep_all_vdefs_p ())
+{
+  mark_stmt_necessary (stmt, true);
+  return;
+}
+
   return;
 }
 
@@ -526,6 +540,9 @@ mark_aliased_reaching_defs_necessary_1 (
 static void
 mark_aliased_reaching_defs_necessary (gimple *stmt, tree ref)
 {
+  /* Should have been caught before calling this function.  */
+  gcc_checking_assert (!keep_all_vdefs_p ());
+
   unsigned int chain;
   ao_ref refd;
   gcc_assert (!chain_ovfl);
@@ -599,6 +616,8 @@ mark_all_reaching_defs_necessary_1 (ao_r
 static void
 mark_all_reaching_defs_necessary (gimple *stmt)
 {
+  /* Should have been caught before calling this function.  */
+  gcc_checking_assert (!keep_all_vdefs_p ());
   walk_aliased_vdefs (NULL, gimple_vuse (stmt),
  mark_all_reaching_defs_necessary_1, NULL, &visited);
 }
@@ -798,6 +817,10 @@ propagate_necessity (bool aggressive)
  if (!use)
continue;
 
+ /* No need to search for vdefs if we intrinsicly keep them all.  */
+ if (keep_all_vdefs_p ())
+   continue;
+
  /* If we dropped to simple mode make all immediately
 reachable definitions necessary.  */
  if (chain_ovfl)
Index: gcc/testsuite/c-c++-common/guality/Og-dce-1.c
===
--- /dev/null   2019-06-14 15:59:19.298479944 +0100
+++ gcc/testsuite/c-c++-common/guality/Og-dce-1.c   2019-07-07 
10:34:47.612717625 +0100
@@ -0,0 +1,14 @@
+/* { dg-do run } */
+/* { dg-options "-g" } */
+
+int *__attribute__((noipa)) consume (int *ptr) { return ptr; }
+
+int
+main (void)
+{
+  int x;
+  int *volatile ptr = consume (&x);
+  x = 0;
+  x = 1;   /* { dg-final { gdb-test . "*ptr" "0" } } */
+  return 0;/* { dg-final { gdb-test . "*ptr" "1" } } */
+}
Index: gcc/testsuite/c-c++-common/guality/Og-dce-2.c
===
--- /dev/null   2019-06-14 15:59:19.298479944 +0100
+++ gcc/testsuite/c-c++-common/guality/Og-dce-2.c   2019-07-07 
10:34:47.612717625 +0100
@@ -0,0 +1,19 @@
+/* { dg-do run } */
+/* { dg-options "-g" } */
+
+struct s { int a, b, c, d; };
+
+struct s gs1 = { 1, 2, 3, 4 };

Don't run DSE at -Og

2019-07-07 Thread Richard Sandiford
This patch stops gimple and rtl DSE from running by default at -Og.
The idea is both to improve compile time and to stop us from deleting
stores that we can't track in debug info.

We could rein this back in future for stores to local variables
with is_gimple_reg_type, but at the moment we don't have any
infrastructure for switching between binds to specific values
and binds to evolving memory locations.  Even then, location
tracking only works for direct references to the variables, and doesn't
for example help with printing dereferenced pointers (see the next patch
in the series for an example).

I'm also not sure that DSE is important enough for -Og to justify the
compile time cost -- especially in the case of RTL DSE, which is pretty
expensive.

Tested on aarch64-linux-gnu and x86_64-linux-gnu.  OK to install?

Richard


2019-07-07  Richard Sandiford  

gcc/
* common.opt (Og): Change the initial value of flag_dse to 0.
* opts.c (default_options_table): Move OPT_ftree_dse from
OPT_LEVELS_1_PLUS to OPT_LEVELS_1_PLUS_NOT_DEBUG.  Also add
OPT_fdse to OPT_LEVELS_1_PLUS_NOT_DEBUG.  Put the OPT_ftree_pta
entry before the OPT_ftree_sra entry.
* doc/invoke.texi (Og): Add -fdse and -ftree-dse to the list
of flags disabled by Og.

gcc/testsuite/
* c-c++-common/guality/Og-global-dse-1.c: New test.

Index: gcc/common.opt
===
--- gcc/common.opt  2019-07-03 20:50:45.902320943 +0100
+++ gcc/common.opt  2019-07-07 10:29:23.683336097 +0100
@@ -1955,7 +1955,7 @@ Common Var(flag_dce) Init(1) Optimizatio
 Use the RTL dead code elimination pass.
 
 fdse
-Common Var(flag_dse) Init(1) Optimization
+Common Var(flag_dse) Init(0) Optimization
 Use the RTL dead store elimination pass.
 
 freschedule-modulo-scheduled-loops
Index: gcc/opts.c
===
--- gcc/opts.c  2019-06-29 17:20:49.0 +0100
+++ gcc/opts.c  2019-07-07 10:29:23.691336032 +0100
@@ -466,7 +466,6 @@ static const struct default_options defa
 { OPT_LEVELS_1_PLUS, OPT_ftree_copy_prop, NULL, 1 },
 { OPT_LEVELS_1_PLUS, OPT_ftree_dce, NULL, 1 },
 { OPT_LEVELS_1_PLUS, OPT_ftree_dominator_opts, NULL, 1 },
-{ OPT_LEVELS_1_PLUS, OPT_ftree_dse, NULL, 1 },
 { OPT_LEVELS_1_PLUS, OPT_ftree_fre, NULL, 1 },
 { OPT_LEVELS_1_PLUS, OPT_ftree_sink, NULL, 1 },
 { OPT_LEVELS_1_PLUS, OPT_ftree_slsr, NULL, 1 },
@@ -477,14 +476,16 @@ static const struct default_options defa
 #if DELAY_SLOTS
 { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fdelayed_branch, NULL, 1 },
 #endif
+{ OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fdse, NULL, 1 },
 { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fif_conversion, NULL, 1 },
 { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fif_conversion2, NULL, 1 },
 { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_finline_functions_called_once, NULL, 1 
},
 { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fmove_loop_invariants, NULL, 1 },
 { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fssa_phiopt, NULL, 1 },
 { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_ftree_bit_ccp, NULL, 1 },
-{ OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_ftree_sra, NULL, 1 },
+{ OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_ftree_dse, NULL, 1 },
 { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_ftree_pta, NULL, 1 },
+{ OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_ftree_sra, NULL, 1 },
 
 /* -O2 and -Os optimizations.  */
 { OPT_LEVELS_2_PLUS, OPT_fcaller_saves, NULL, 1 },
Index: gcc/doc/invoke.texi
===
--- gcc/doc/invoke.texi 2019-07-03 20:50:42.346350375 +0100
+++ gcc/doc/invoke.texi 2019-07-07 10:29:23.687336062 +0100
@@ -8421,10 +8421,10 @@ no effect.  Otherwise @option{-Og} enabl
 optimization flags except for those that may interfere with debugging:
 
 @gccoptlist{-fbranch-count-reg  -fdelayed-branch @gol
--fif-conversion  -fif-conversion2  @gol
+-fdse  -fif-conversion  -fif-conversion2  @gol
 -finline-functions-called-once @gol
 -fmove-loop-invariants  -fssa-phiopt @gol
--ftree-bit-ccp  -ftree-pta  -ftree-sra}
+-ftree-bit-ccp  -ftree-dse  -ftree-pta  -ftree-sra}
 
 @end table
 
Index: gcc/testsuite/c-c++-common/guality/Og-global-dse-1.c
===
--- /dev/null   2019-06-14 15:59:19.298479944 +0100
+++ gcc/testsuite/c-c++-common/guality/Og-global-dse-1.c2019-07-07 
10:29:23.691336032 +0100
@@ -0,0 +1,17 @@
+/* { dg-do run } */
+/* { dg-options "-g" } */
+
+struct s { int i, j; };
+struct s gs1, gs2 = { 3, 4 };
+
+void __attribute__((noipa)) consume (void) {};
+
+int
+main (void)
+{
+  gs1.i = 1;
+  gs1.j = 2;   /* { dg-final { gdb-test . "gs1.i" "1" } } */
+  gs1 = gs2;   /* { dg-final { gdb-test . "gs1.j" "2" } } */
+  consume ();  /* { dg-final { gdb-test . "gs1.i" "3" } } */
+  return 0;/* { dg-final { gdb-test . "gs1.j" "4" } } */
+}


Prevent -Og from deleting stores to write-only variables

2019-07-07 Thread Richard Sandiford
This patch prevents -Og from deleting stores to write-only variables,
so that the values are still available when debugging.  This seems
more convenient than forcing users to use __attribute__((used))
(probably conditionally, if it's not something they want in release
builds).

Tested on aarch64-linux-gnu and x86_64-linux-gnu.  OK to install?

Richard


2019-07-07  Richard Sandiford  

gcc/
* tree-cfg.c (execute_fixup_cfg): Don't delete stores to write-only
variables for -Og.

gcc/testsuite/
* c-c++-common/guality/Og-static-wo-1.c: New test.
* g++.dg/guality/guality.exp: Separate the c-c++-common tests into
"Og" and "general" tests.  Run the latter at -O0 and -Og only.
* gcc.dg/guality/guality.exp: Likewise.

Index: gcc/tree-cfg.c
===
--- gcc/tree-cfg.c  2019-07-06 09:25:08.717486045 +0100
+++ gcc/tree-cfg.c  2019-07-07 10:29:19.999365874 +0100
@@ -9571,7 +9571,8 @@ execute_fixup_cfg (void)
 Keep access when store has side effect, i.e. in case when source
 is volatile.  */
  if (gimple_store_p (stmt)
- && !gimple_has_side_effects (stmt))
+ && !gimple_has_side_effects (stmt)
+ && !optimize_debug)
{
  tree lhs = get_base_address (gimple_get_lhs (stmt));
 
Index: gcc/testsuite/c-c++-common/guality/Og-static-wo-1.c
===
--- /dev/null   2019-06-14 15:59:19.298479944 +0100
+++ gcc/testsuite/c-c++-common/guality/Og-static-wo-1.c 2019-07-07 
10:29:19.999365874 +0100
@@ -0,0 +1,15 @@
+/* { dg-do run } */
+/* { dg-options "-g" } */
+
+#include "../../gcc.dg/nop.h"
+
+static int x = 0;
+
+int
+main (void)
+{
+  asm volatile (NOP);  /* { dg-final { gdb-test . "x" "0" } } */
+  x = 1;
+  asm volatile (NOP);  /* { dg-final { gdb-test . "x" "1" } } */
+  return 0;
+}
Index: gcc/testsuite/g++.dg/guality/guality.exp
===
--- gcc/testsuite/g++.dg/guality/guality.exp2019-07-01 10:15:31.0 
+0100
+++ gcc/testsuite/g++.dg/guality/guality.exp2019-07-07 10:29:19.999365874 
+0100
@@ -65,8 +65,22 @@ if {[check_guality "
 return 0;
   }
 "]} {
-  gcc-dg-runtest [lsort [glob $srcdir/$subdir/*.C]] "" ""
-  gcc-dg-runtest [lsort [glob $srcdir/c-c++-common/guality/*.c]] "" ""
+set general [list]
+set Og [list]
+foreach file [lsort [glob $srcdir/c-c++-common/guality/*.c]] {
+   switch -glob -- [file tail $file] {
+   Og-* { lappend Og $file }
+   * { lappend general $file }
+   }
+}
+
+gcc-dg-runtest [lsort [glob $srcdir/$subdir/*.C]] "" ""
+gcc-dg-runtest $general "" ""
+set-torture-options \
+   [list "-O0" "-Og"] \
+   [list {}] \
+   [list "-Og -flto"]
+gcc-dg-runtest $Og "" ""
 }
 
 if [info exists guality_gdb_name] {
Index: gcc/testsuite/gcc.dg/guality/guality.exp
===
--- gcc/testsuite/gcc.dg/guality/guality.exp2019-07-01 10:15:31.0 
+0100
+++ gcc/testsuite/gcc.dg/guality/guality.exp2019-07-07 10:29:19.999365874 
+0100
@@ -80,8 +80,22 @@ if {[check_guality "
 return 0;
   }
 "]} {
-  gcc-dg-runtest [lsort [glob $srcdir/$subdir/*.c]] "" ""
-  gcc-dg-runtest [lsort [glob $srcdir/c-c++-common/guality/*.c]] "" 
"-Wc++-compat"
+set general [list]
+set Og [list]
+foreach file [lsort [glob $srcdir/c-c++-common/guality/*.c]] {
+   switch -glob -- [file tail $file] {
+   Og-* { lappend Og $file }
+   * { lappend general $file }
+   }
+}
+
+gcc-dg-runtest [lsort [glob $srcdir/$subdir/*.c]] "" ""
+gcc-dg-runtest $general "" "-Wc++-compat"
+set-torture-options \
+   [list "-O0" "-Og"] \
+   [list {}] \
+   [list "-Og -flto"]
+gcc-dg-runtest $Og "" "-Wc++-compat"
 }
 
 if [info exists guality_gdb_name] {


Add a build config for bootstrapping at -Og

2019-07-07 Thread Richard Sandiford
Although BOOT_CFLAGS can be used to bootstrap with -Og, having a
dedicated build config is sometimes more convenient.

Tested on aarch64-linux-gnu and x86_64-linux-gnu.  OK to install?

Richard


2019-07-07  Richard Sandiford  

config/
* bootstrap-Og.mk: New file.

gcc/
* doc/install.texi (bootstrap-Og): Document.

Index: config/bootstrap-Og.mk
===
--- /dev/null   2019-06-14 15:59:19.298479944 +0100
+++ config/bootstrap-Og.mk  2019-07-07 10:20:42.935544725 +0100
@@ -0,0 +1,1 @@
+BOOT_CFLAGS := -Og $(filter-out -O%, $(BOOT_CFLAGS))
Index: gcc/doc/install.texi
===
--- gcc/doc/install.texi2019-07-03 20:50:42.350350342 +0100
+++ gcc/doc/install.texi2019-07-07 10:20:42.935544725 +0100
@@ -2535,6 +2535,7 @@ Removes any @option{-O}-started option f
 @samp{BOOT_CFLAGS='-g -O1'}.
 
 @item @samp{bootstrap-O3}
+@itemx @samp{bootstrap-Og}
 Analogous to @code{bootstrap-O1}.
 
 @item @samp{bootstrap-lto}


Make guality.h handle Yama restricted ptrace mode

2019-07-07 Thread Richard Sandiford
guality.exp is silently skipped on Linux systems with
kernel.yama.ptrace_scope=1 because gdb fails to attach to the
sanity check test.  This patch uses PR_SET_PTRACER (where available)
to avoid this.

prctl was apparently added in Linux 2.1.57, so I don't think we
need any tests other than __linux for the #include.

Tested on aarch64-linux-gnu and x86_64-linux-gnu.  OK to install?

Richard


2019-07-07  Richard Sandiford  

gcc/testsuite/
* gcc.dg/guality/guality.h: Include  on Linux targets.
(main): Use PR_SET_PTRACER where available.

Index: gcc/testsuite/gcc.dg/guality/guality.h
===
--- gcc/testsuite/gcc.dg/guality/guality.h  2019-03-08 18:15:03.052868249 
+
+++ gcc/testsuite/gcc.dg/guality/guality.h  2019-07-07 10:18:20.240698144 
+0100
@@ -23,6 +23,9 @@ the Free Software Foundation; either ver
 #include 
 #include 
 #include 
+#ifdef __linux
+#include 
+#endif
 
 /* This is a first cut at checking that debug information matches
run-time.  The idea is to annotate programs with GUALCHK* macros
@@ -214,6 +217,10 @@ main (int argc, char *argv[])
   int i;
   char *argv0 = argv[0];
 
+#if defined(PR_SET_PTRACER_ANY)
+  prctl (PR_SET_PTRACER, PR_SET_PTRACER_ANY, 0, 0, 0);
+#endif
+
   guality_gdb_command = getenv ("GUALITY_GDB");
   if (!guality_gdb_command)
 {