[PATCH] Simplify ((A & N) ==/!= CST1) &/| ((A & M) ==/!= CST2)

2020-01-03 Thread Andrew Pinski
Hi,
  This adds the following two simplifcations to match.pd:

((A & N) == CST1) & ((A & M) == CST2)
if (N) == (N), then
   (A&(N|M)) == (CST1|CST2)
else
  false
And
((A & N) != CST1) | ((A & M) != CST2)

if (N) == (N), then
   (A&(N|M)) != (CST1|CST2)
else
  true

NOTE it adds a check to make sure N&~CST1 and M&~CST2 are zero; that
is non outside bits are set in CST1/CST2; just to make sure we don't
have an ordering issue when doing the simplification.

I added a testcase for majority of cases I could think of, so there
are a total of 29 testcases include.

NOTE It does not solve the original testcase in the bug report though,
because we need to handle (A_pow2p) !=/== 0 as ((A &
integer_pow2p) ==/!= integer_pow2p) which is not done in this patch.
I will implement that in a follow up patch.  NOTE this is a step
forward to be able to remove the fold_truth_andor_1 and
optimize_bit_field_compare from fold-const.c.

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

Thanks,
Andrew Pinski

ChangeLog:
* match.pd (((A & N) ==/!= CST1) &/| ((A & M) ==/!= CST2)): New pattern.

testsuite/ChangeLog:
* gcc.c-torture/execute/cmpandor-1.c: New testcase
* gcc.c-torture/execute/cmpandor-1.h: New file.
* gcc.dg/tree-ssa/eqand-1.c: New testcase.
* gcc.dg/tree-ssa/eqand-2.c: New testcase.
* gcc.dg/tree-ssa/eqand-3.c: New testcase.
* gcc.dg/tree-ssa/eqand-4.c: New testcase.
* gcc.dg/tree-ssa/eqand-5.c: New testcase.
* gcc.dg/tree-ssa/eqand-6.c: New testcase.
* gcc.dg/tree-ssa/eqand-7.c: New testcase.
* gcc.dg/tree-ssa/eqor-1.c: New testcase.
* gcc.dg/tree-ssa/eqor-2.c: New testcase.
* gcc.dg/tree-ssa/eqor-3.c: New testcase.
* gcc.dg/tree-ssa/eqor-4.c: New testcase.
* gcc.dg/tree-ssa/eqor-5.c: New testcase.
* gcc.dg/tree-ssa/eqor-6.c: New testcase.
* gcc.dg/tree-ssa/eqor-7.c: New testcase.
* gcc.dg/tree-ssa/neand-1.c: New testcase.
* gcc.dg/tree-ssa/neand-2.c: New testcase.
* gcc.dg/tree-ssa/neand-3.c: New testcase.
* gcc.dg/tree-ssa/neand-4.c: New testcase.
* gcc.dg/tree-ssa/neand-5.c: New testcase.
* gcc.dg/tree-ssa/neand-6.c: New testcase.
* gcc.dg/tree-ssa/neand-7.c: New testcase.
* gcc.dg/tree-ssa/neor-1.c: New testcase.
* gcc.dg/tree-ssa/neor-2.c: New testcase.
* gcc.dg/tree-ssa/neor-3.c: New testcase.
* gcc.dg/tree-ssa/neor-4.c: New testcase.
* gcc.dg/tree-ssa/neor-5.c: New testcase.
* gcc.dg/tree-ssa/neor-6.c: New testcase.
* gcc.dg/tree-ssa/neor-7.c: New testcase.
Index: match.pd
===
--- match.pd(revision 279865)
+++ match.pd(working copy)
@@ -807,6 +807,35 @@ (define_operator_list COND_TERNARY
&& TYPE_PRECISION (TREE_TYPE (@0)) == TYPE_PRECISION (TREE_TYPE (@1)))
 (cmp (bit_and @0 (convert @1)) @2
 
+/* Transform ((A & N) ==/!= CST1) &/| ((A & M) ==/!= CST2)
+   if (CST1&~N) == 0 && (CST2&~M) == 0 then
+   if  (N) != (N) then
+   false/true
+   else
+   (A&(N|M)) ==/!= (CST1|CST2) */
+(for bitop (bit_and bit_ior)
+ cmp   (eq  ne)
+ (simplify
+  (bitop
+   (cmp (bit_and @0 INTEGER_CST@mask1) INTEGER_CST@CST1)
+   (cmp (bit_and @0 INTEGER_CST@mask2) INTEGER_CST@CST2))
+  (with
+   {
+ tree type1 = TREE_TYPE (@0);
+ wide_int mask1 = wi::to_wide (@mask1);
+ wide_int mask2 = wi::to_wide (@mask2);
+ wide_int newmask = mask1 | mask2;
+ wide_int m = mask1 & mask2;
+ wide_int cst1 = wi::to_wide (@CST1);
+ wide_int cst2 = wi::to_wide (@CST2);
+   }
+   (if (wi::bit_and_not (cst1, mask1) == 0
+&& wi::bit_and_not (cst2, mask2) == 0)
+(if (wi::eq_p (m & cst1, m & cst2))
+ (cmp (bit_and @0 { wide_int_to_tree (type1, newmask); } )
+  { wide_int_to_tree (type1, cst1 | cst2); } )
+ { constant_boolean_node (cmp == NE_EXPR, type); })
+
 /* Fold (A & ~B) - (A & B) into (A ^ B) - B.  */
 (simplify
  (minus (bit_and:cs @0 (bit_not @1)) (bit_and:cs @0 @1))
Index: testsuite/gcc.c-torture/execute/cmpandor-1.c
===
--- testsuite/gcc.c-torture/execute/cmpandor-1.c(nonexistent)
+++ testsuite/gcc.c-torture/execute/cmpandor-1.c(working copy)
@@ -0,0 +1,91 @@
+
+#define NOIPA __attribute__((__noipa__))
+
+
+#define functiondefine(name, cmp, bitop, v1, v1cmp, v2, v2cmp) \
+int name(int a) NOIPA; \
+int name(int a)\
+{  \
+  int b = (a & (v1)) cmp (v1cmp);  \
+  int c = (a & (v2)) cmp (v2cmp);  \
+  return b bitop c;\
+}
+
+
+#define func functiondefine
+#include "cmpandor-1.h"
+#undef func
+
+struct inputsuse
+{
+  const char *name;
+  int (*function)(int);
+  int input;
+  int result;  
+};
+
+#define strivify(input) #input
+
+#define func(name, cmp, bitop, v1, v1cmp, v2, v2cmp) \
+{ \
+   "" #name "_" strivify(input), \
+   , \
+   input, \
+   ((input) 

[PATCH 3/3] Check array contiguity for OpenACC/Fortran

2020-01-03 Thread Julian Brown
Hi,

This patch tightens up error checking for array references used in
OpenACC clauses such that they must now be contiguous. I believe this
matches up to the spec (as of 2.6). I've tried to make it so an error
only triggers if the compiler is sure that a given array expression must
be non-contiguous at compile time, although this errs on the side
of potentially allowing the user to shoot themselves in the foot at
runtime: at least one existing test in the testsuite appears to expect
that behaviour.

This hopefully addresses Tobias's concern in:

  https://gcc.gnu.org/ml/gcc-patches/2019-12/msg01439.html

In particular, with the error checking, we no longer get an ICE for the
example given in that message. The new check also catches a test case
that appears to have been relying on undefined behaviour.

Tested with offloading to NVPTX. OK for trunk?

Thanks,

Julian

ChangeLog

2020-01-04  Julian Brown  

PR fortran/93025

gcc/fortran/
* openmp.c (resolve_omp_clauses): Check array references for contiguity.

gcc/testsuite/
* gfortran.dg/goacc/mapping-tests-2.f90: New test.
* gfortran.dg/goacc/subarrays.f95: Expect rejection of non-contiguous
array.
---
 gcc/fortran/openmp.c  | 29 +
 .../gfortran.dg/goacc/mapping-tests-2.f90 | 32 +++
 gcc/testsuite/gfortran.dg/goacc/subarrays.f95 |  2 +-
 3 files changed, 55 insertions(+), 8 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/goacc/mapping-tests-2.f90

diff --git a/gcc/fortran/openmp.c b/gcc/fortran/openmp.c
index 78351b190f7..71308c0235c 100644
--- a/gcc/fortran/openmp.c
+++ b/gcc/fortran/openmp.c
@@ -4533,13 +4533,28 @@ resolve_omp_clauses (gfc_code *code, gfc_omp_clauses 
*omp_clauses,
/* Look through component refs to find last array
   reference.  */
if (openacc && resolved)
- while (array_ref
-&& (array_ref->type == REF_COMPONENT
-|| (array_ref->type == REF_ARRAY
-&& array_ref->next
-&& (array_ref->next->type
-== REF_COMPONENT
-   array_ref = array_ref->next;
+ {
+   /* The "!$acc cache" directive allows rectangular
+  subarrays to be specified, with some restrictions
+  on the form of bounds (not implemented).
+  Only raise an error here if we're really sure the
+  array isn't contiguous.  An expression such as
+  arr(-n:n,-n:n) could be contiguous even if it looks
+  like it may not be.  */
+   if (list != OMP_LIST_CACHE
+   && !gfc_is_simply_contiguous (n->expr, false, true)
+   && gfc_is_not_contiguous (n->expr))
+ gfc_error ("Array is not contiguous at %L",
+>where);
+
+   while (array_ref
+  && (array_ref->type == REF_COMPONENT
+  || (array_ref->type == REF_ARRAY
+  && array_ref->next
+  && (array_ref->next->type
+  == REF_COMPONENT
+ array_ref = array_ref->next;
+ }
  }
if (array_ref
|| (n->expr
diff --git a/gcc/testsuite/gfortran.dg/goacc/mapping-tests-2.f90 
b/gcc/testsuite/gfortran.dg/goacc/mapping-tests-2.f90
new file mode 100644
index 000..1372f6af53e
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/goacc/mapping-tests-2.f90
@@ -0,0 +1,32 @@
+subroutine foo
+  type t
+integer :: i, j
+  end type t
+
+  type t2
+type(t) :: cc(3)
+  end type t2
+
+  type(t) x, y(3)
+  type(t2) :: z(3)
+
+  ! OK - map whole aggregated variable
+!$acc enter data copyin(x)
+  ! map(to:x [len: 8])
+
+  ! OK - map two components of the aggregated variable
+!$acc enter data copyin(x%j, x%i)
+
+  ! Bad - we cannot mix full-object and component accesses
+!$acc enter data copyin(x, x%i)
+! { dg-error "Symbol .x. has mixed component and non-component accesses" "" { 
target "*-*-*" } 21 }
+
+  ! Bad - we cannot do a strided access of 'x'
+  ! No C/C++ equivalent
+!$acc enter data copyin(y(:)%i)
+! { dg-error "Array is not contiguous" "" { target "*-*-*" } 26 }
+
+  ! Bad - again, a strided access
+!$acc enter data copyin(z(1)%cc(:)%i)
+! { dg-error "Array is not contiguous" "" { target "*-*-*" } 30 }
+end
diff --git a/gcc/testsuite/gfortran.dg/goacc/subarrays.f95 
b/gcc/testsuite/gfortran.dg/goacc/subarrays.f95
index f6adde459f4..fa0378550e9 100644
--- 

[PATCH 1/3] Add OpenACC test for sub-references being pointer or allocatable variables

2020-01-03 Thread Julian Brown
Hi,

This test (by Tobias Burnus, mildly edited) adds a test to check whether
the final component of a derived-type access has pointer or allocatable
type for manual deep copy attach/detach operations. This is just checking
existing behaviour.

This arose from discussion of the manual deep copy patch here:

  https://gcc.gnu.org/ml/gcc-patches/2019-12/msg01439.html

OK?

Thanks,

Julian

ChangeLog

2020-01-04  Tobias Burnus  

gcc/testsuite/
* gfortran.dg/goacc/strided-alloc-ptr.f90: New test.
---
 .../gfortran.dg/goacc/strided-alloc-ptr.f90   | 34 +++
 1 file changed, 34 insertions(+)
 create mode 100644 gcc/testsuite/gfortran.dg/goacc/strided-alloc-ptr.f90

diff --git a/gcc/testsuite/gfortran.dg/goacc/strided-alloc-ptr.f90 
b/gcc/testsuite/gfortran.dg/goacc/strided-alloc-ptr.f90
new file mode 100644
index 000..755fd1c164b
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/goacc/strided-alloc-ptr.f90
@@ -0,0 +1,34 @@
+implicit none
+type t
+  integer, allocatable :: i, j(:)
+  integer, pointer :: k, ll(:)
+end type t
+type(t) :: x(2)
+
+!$acc enter data copyin(x)
+
+!$acc enter data copyin(x(:)%i)
+! { dg-error "Component to the right of a part reference with nonzero rank 
must not have the ALLOCATABLE attribute" "" { target "*-*-*" } 10 }
+! { dg-error ".x. in MAP clause at .1. is not a proper array section"  "" { 
target "*-*-*" } 10 }
+
+!$acc enter data copyin(x(:)%j(3))
+! { dg-error "Component to the right of a part reference with nonzero rank 
must not have the ALLOCATABLE attribute" "" { target "*-*-*" } 14 }
+! { dg-error ".x. in MAP clause at .1. is not a proper array section"  "" { 
target "*-*-*" } 14 }
+
+!$acc enter data copyin(x(:)%j)
+! { dg-error "Component to the right of a part reference with nonzero rank 
must not have the ALLOCATABLE attribute" "" { target "*-*-*" } 18 }
+! { dg-error ".x. in MAP clause at .1. is not a proper array section"  "" { 
target "*-*-*" } 18 }
+
+
+!$acc enter data copyin(x(:)%k)
+! { dg-error "Component to the right of a part reference with nonzero rank 
must not have the POINTER attribute" "" { target "*-*-*" } 23 }
+! { dg-error ".x. in MAP clause at .1. is not a proper array section"  "" { 
target "*-*-*" } 23 }
+
+!$acc enter data copyin(x(:)%ll(3))
+! { dg-error "Component to the right of a part reference with nonzero rank 
must not have the POINTER attribute" "" { target "*-*-*" } 27 }
+! { dg-error ".x. in MAP clause at .1. is not a proper array section"  "" { 
target "*-*-*" } 27 }
+
+!$acc enter data copyin(x(:)%ll)
+! { dg-error "Component to the right of a part reference with nonzero rank 
must not have the POINTER attribute" "" { target "*-*-*" } 31 }
+! { dg-error ".x. in MAP clause at .1. is not a proper array section"  "" { 
target "*-*-*" } 31 }
+end
-- 
2.23.0



[PATCH 2/3] Don't allow mixed component and non-component accesses for OpenACC/Fortran

2020-01-03 Thread Julian Brown
Hi,

This patch arose from discussion of the manual deep copy patch here:

  https://gcc.gnu.org/ml/gcc-patches/2019-12/msg01439.html

In C/C++, it's not permitted to mix full struct-type accesses and
"attach/detach" accesses to the same struct's members within a single
directive.  This patch adds the same restriction to the Fortran front-end,
and adjusts some existing tests to match.  A test is also added for
detection of duplicate derived-type member accesses within a directive.

Tested with offloading to NVPTX. OK for mainline?

Thanks,

Julian

ChangeLog

2020-01-04  Julian Brown  

gcc/fortran/
* gfortran.h (gfc_symbol): Add comp_mark bitfield.
* openmp.c (resolve_omp_clauses): Disallow mixed component and
full-derived-type accesses to the same variable within a single
directive.

libgomp/
* testsuite/libgomp.oacc-fortran/deep-copy-2.f90: Remove test from here.
* testsuite/libgomp.oacc-fortran/deep-copy-3.f90: Don't use mixed
component/non-component variable refs in a single directive.
* testsuite/libgomp.oacc-fortran/classtypes-1.f95: Likewise.

gcc/testsuite/
* gfortran.dg/goacc/deep-copy-2.f90: Add test here. Make a compilation
test, and expect rejection of mixed component/non-component accesses.
* gfortran.dg/goacc/mapping-tests-1.f90: New test.
---
 gcc/fortran/gfortran.h|  6 ++--
 gcc/fortran/openmp.c  | 31 ++-
 .../gfortran.dg/goacc}/deep-copy-2.f90|  8 +++--
 .../gfortran.dg/goacc/mapping-tests-1.f90 | 15 +
 .../libgomp.oacc-fortran/classtypes-1.f95 |  6 ++--
 .../libgomp.oacc-fortran/deep-copy-3.f90  |  4 ++-
 6 files changed, 49 insertions(+), 21 deletions(-)
 rename {libgomp/testsuite/libgomp.oacc-fortran => 
gcc/testsuite/gfortran.dg/goacc}/deep-copy-2.f90 (63%)
 create mode 100644 gcc/testsuite/gfortran.dg/goacc/mapping-tests-1.f90

diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index df07eeed8e3..1de5f0d171e 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -1592,9 +1592,11 @@ typedef struct gfc_symbol
  current statement have the mark member nonzero.  Of these symbols,
  symbols with old_symbol equal to NULL are symbols created within
  the current statement.  Otherwise, old_symbol points to a copy of
- the old symbol. gfc_new is used in symbol.c to flag new symbols.  */
+ the old symbol. gfc_new is used in symbol.c to flag new symbols.
+ comp_mark is used to indicate variables which have component accesses
+ in OpenACC directive clauses.  */
   struct gfc_symbol *old_symbol;
-  unsigned mark:1, gfc_new:1;
+  unsigned mark:1, comp_mark:1, gfc_new:1;
 
   /* The tlink field is used in the front end to carry the module
  declaration of separate module procedures so that the characteristics
diff --git a/gcc/fortran/openmp.c b/gcc/fortran/openmp.c
index c105657a91b..78351b190f7 100644
--- a/gcc/fortran/openmp.c
+++ b/gcc/fortran/openmp.c
@@ -4245,6 +4245,7 @@ resolve_omp_clauses (gfc_code *code, gfc_omp_clauses 
*omp_clauses,
 for (n = omp_clauses->lists[list]; n; n = n->next)
   {
n->sym->mark = 0;
+   n->sym->comp_mark = 0;
if (n->sym->attr.flavor == FL_VARIABLE
|| n->sym->attr.proc_pointer
|| (!code && (!n->sym->attr.dummy || n->sym->ns != ns)))
@@ -4310,23 +4311,25 @@ resolve_omp_clauses (gfc_code *code, gfc_omp_clauses 
*omp_clauses,
&& (list != OMP_LIST_REDUCTION || !openacc))
   for (n = omp_clauses->lists[list]; n; n = n->next)
{
- bool array_only_p = true;
- /* Disallow duplicate bare variable references and multiple
-subarrays of the same array here, but allow multiple components of
-the same (e.g. derived-type) variable.  For the latter, duplicate
-components are detected elsewhere.  */
+ bool component_ref_p = false;
+
+ /* Allow multiple components of the same (e.g. derived-type)
+variable here.  Duplicate components are detected elsewhere.  */
  if (openacc && n->expr && n->expr->expr_type == EXPR_VARIABLE)
for (gfc_ref *ref = n->expr->ref; ref; ref = ref->next)
- if (ref->type != REF_ARRAY)
-   {
- array_only_p = false;
- break;
-   }
- if (array_only_p)
+ if (ref->type == REF_COMPONENT)
+   component_ref_p = true;
+ if (openacc && ((!component_ref_p && n->sym->comp_mark)
+ || (component_ref_p && n->sym->mark)))
+   gfc_error ("Symbol %qs has mixed component and non-component "
+  "accesses at %L", n->sym->name, >where);
+ else if (n->sym->mark)
+   gfc_error ("Symbol %qs present on multiple clauses at %L",
+  n->sym->name, >where);
+ else

[PATCH] Improve __builtin_add_overflow on x86 for double-word types (PR target/93141)

2020-01-03 Thread Jakub Jelinek
Hi!

As the following testcase shows, we generate quite bad code for
double-word __builtin_add_overflow on x86, we have add[dt]i3_doubleword
pattern and emit add[ql]; adc[ql];, but then we could just use setc/seto
or adc etc., but we instead perform a double-word comparison to set compute
the carry from the addition (or overflow).
The following patch on the testcase results in the attached changes for -m64
(and -m32).  Also, when the middle-end notices the optabs, it pattern
recognizes hand-written code, like e.g. in the #c0 testcase in the PR where
it does sum += prod; overflow += sum < prod; which the GIMPLE opts can
turn into overflow += __builtin_add_overflow (sum, prod, );.

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

Haven't done yet subv4 and usubv4 for the double-word modes, but
it ought to work similarly, just it will be more work.

2020-01-04  Jakub Jelinek  

PR target/93141
* config/i386/i386.md (SWIDWI): New mode iterator.
(DWI, dwi): Add TImode variants.
(addv4): Use SWIDWI iterator instead of SWI.  Use
 instead of .  Use
CONST_SCALAR_INT_P instead of CONST_INT_P.
(*addv4_1): Rename to ...
(addv4_1): ... this.
(QWI): New mode attribute.
(*addv4_doubleword, *addv4_doubleword_1): New
define_insn_and_split patterns.
(*addv4_overflow_1, *addv4_overflow_2): New define_insn
patterns.
(uaddv4): Use SWIDWI iterator instead of SWI.  Use
 instead of .
(*addcarry_1): New define_insn.
(*add3_doubleword_cc_overflow_1): New define_insn_and_split.

* gcc.target/i386/pr93141-1.c: New test.
* gcc.dg/pr67089-6.c: Expect 16 ADD_OVERFLOW calls even on ia32.

--- gcc/config/i386/i386.md.jj  2020-01-03 11:10:43.839511446 +0100
+++ gcc/config/i386/i386.md 2020-01-03 20:55:39.152577178 +0100
@@ -1036,6 +1036,9 @@ (define_mode_iterator SWIM248 [(HI "TARG
 (define_mode_iterator DWI [(DI "!TARGET_64BIT")
   (TI "TARGET_64BIT")])
 
+;; SWI and DWI together.
+(define_mode_iterator SWIDWI [QI HI SI DI (TI "TARGET_64BIT")])
+
 ;; GET_MODE_SIZE for selected modes.  As GET_MODE_SIZE is not
 ;; compile time constant, it is faster to use  than
 ;; GET_MODE_SIZE (mode).  For XFmode which depends on
@@ -1051,8 +1054,8 @@ (define_mode_attr MODE_SIZE [(QI "1") (H
 (V4SF "16") (V8SF "32") (V16SF "64")])
 
 ;; Double word integer modes as mode attribute.
-(define_mode_attr DWI [(QI "HI") (HI "SI") (SI "DI") (DI "TI")])
-(define_mode_attr dwi [(QI "hi") (HI "si") (SI "di") (DI "ti")])
+(define_mode_attr DWI [(QI "HI") (HI "SI") (SI "DI") (DI "TI") (TI "OI")])
+(define_mode_attr dwi [(QI "hi") (HI "si") (SI "di") (DI "ti") (TI "oi")])
 
 ;; LEA mode corresponding to an integer mode
 (define_mode_attr LEAMODE [(QI "SI") (HI "SI") (SI "SI") (DI "DI")])
@@ -6054,16 +6057,17 @@ (define_insn "*addqi_ext_2"
 ;; Add with jump on overflow.
 (define_expand "addv4"
   [(parallel [(set (reg:CCO FLAGS_REG)
-  (eq:CCO (plus:
- (sign_extend:
-(match_operand:SWI 1 "nonimmediate_operand"))
- (match_dup 4))
-  (sign_extend:
- (plus:SWI (match_dup 1)
-   (match_operand:SWI 2
-  "")
- (set (match_operand:SWI 0 "register_operand")
-  (plus:SWI (match_dup 1) (match_dup 2)))])
+  (eq:CCO
+(plus:
+  (sign_extend:
+(match_operand:SWIDWI 1 "nonimmediate_operand"))
+  (match_dup 4))
+(sign_extend:
+  (plus:SWIDWI (match_dup 1)
+(match_operand:SWIDWI 2
+  "")
+ (set (match_operand:SWIDWI 0 "register_operand")
+  (plus:SWIDWI (match_dup 1) (match_dup 2)))])
(set (pc) (if_then_else
   (eq (reg:CCO FLAGS_REG) (const_int 0))
   (label_ref (match_operand 3))
@@ -6071,7 +6075,7 @@ (define_expand "addv4"
   ""
 {
   ix86_fixup_binary_operands_no_copy (PLUS, mode, operands);
-  if (CONST_INT_P (operands[2]))
+  if (CONST_SCALAR_INT_P (operands[2]))
 operands[4] = operands[2];
   else
 operands[4] = gen_rtx_SIGN_EXTEND (mode, operands[2]);
@@ -6093,7 +6097,7 @@ (define_insn "*addv4"
   [(set_attr "type" "alu")
(set_attr "mode" "")])
 
-(define_insn "*addv4_1"
+(define_insn "addv4_1"
   [(set (reg:CCO FLAGS_REG)
(eq:CCO (plus:
   (sign_extend:
@@ -6118,15 +6122,178 @@ (define_insn "*addv4_1"
  (const_string "4")]
  (const_string "")))])
 
+;; Quad word integer modes as mode attribute.
+(define_mode_attr QWI [(SI "TI") (DI "OI")])
+
+(define_insn_and_split 

[C++ PATCH] Fix up cp-gimplify.c ICE (PR c++/93046)

2020-01-03 Thread Jakub Jelinek
Hi!

On the following testcase since the split_nonconstant_init move
on the COND_EXPR with omitted middle-end operand we end up with
the operator bool called on a TARGET_EXPR in the first operand and
the same TARGET_EXPR appearing in INIT_EXPR in the second operand.
cp_gimplify_init_expr ICEs, because this is during gimplification
and when TARGET_EXPR is gimplified for the first time, the
TARGET_EXPR_SLOT VAR_DECL is initialized and TARGET_EXPR_INITIAL
is cleared and when we gimplify it for the second and following time,
we just use the TARGET_EXPR_SLOT.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

2010-01-04  Jakub Jelinek  

PR c++/93046
* cp-gimplify.c (cp_gimplify_init_expr): Don't look through
TARGET_EXPR if it has been gimplified already.

* g++.dg/ext/cond4.C: New test.

--- gcc/cp/cp-gimplify.c.jj 2020-01-01 12:22:33.838478071 +0100
+++ gcc/cp/cp-gimplify.c2020-01-03 13:28:49.714314467 +0100
@@ -523,7 +523,7 @@ cp_gimplify_init_expr (tree *expr_p, gim
  think that such code never uses the TARGET_EXPR as an initializer.  If
  I'm wrong, we'll abort because the temp won't have any RTL.  In that
  case, I guess we'll need to replace references somehow.  */
-  if (TREE_CODE (from) == TARGET_EXPR)
+  if (TREE_CODE (from) == TARGET_EXPR && TARGET_EXPR_INITIAL (from))
 from = TARGET_EXPR_INITIAL (from);
 
   /* If we might need to clean up a partially constructed object, break down
--- gcc/testsuite/g++.dg/ext/cond4.C.jj 2020-01-03 13:48:09.630801029 +0100
+++ gcc/testsuite/g++.dg/ext/cond4.C2020-01-03 13:47:10.408696206 +0100
@@ -0,0 +1,14 @@
+// PR c++/93046
+// { dg-do compile }
+// { dg-options "" }
+
+struct S {
+  S (int);
+  operator bool ();
+};
+
+S
+foo ()
+{
+  return S (1) ? : S (2);
+}

Jakub



[C++ PATCH] Avoid bogus errors due to -Wredundant-tags (PR c++/93138)

2020-01-03 Thread Jakub Jelinek
Hi!

For -Wredundant-tags or -Wmismatched-tags, cp_parser_maybe_warn_enum_key
and cp_parser_check_class_key perform an extra name lookup to check if the
enum/struct/class/union keyword is redundant, but as the testcase shows,
if it is not redundant, but there is e.g. a hidden member with the same
name, it results in bogus error about accessing the member, although that
should be diagnosed only if the non-redundant keyword is not present.

So, I think we need to ensure the lookup doesn't perform nor queue any
access checks.  Furthermore, I don't see the point in performing the lookup
for enums if the warning is disabled (by default), for struct/class/union
we already don't perform it if both warnings are disabled.

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

2020-01-04  Jakub Jelinek  

PR c++/93138
* parser.c (cp_parser_check_class_key): Disable access checks for the
simple name lookup.
(cp_parser_maybe_warn_enum_key): Likewise.  Return early if
!warn_redundant_tags.

* g++.dg/warn/Wredundant-tags-2.C: New test.

--- gcc/cp/parser.c.jj  2020-01-01 12:22:34.078474448 +0100
+++ gcc/cp/parser.c 2020-01-03 10:56:53.899072533 +0100
@@ -30663,11 +30663,15 @@ static void
 cp_parser_maybe_warn_enum_key (cp_parser *parser, location_t key_loc,
   tree type, rid scoped_key)
 {
+  if (!warn_redundant_tags)
+return;
+
   tree type_decl = TYPE_MAIN_DECL (type);
   tree name = DECL_NAME (type_decl);
-  /* Look up the NAME to see if it unambiguously refers to the TYPE
- and set KEY_REDUNDANT if so.  */
+  /* Look up the NAME to see if it unambiguously refers to the TYPE.  */
+  push_deferring_access_checks (dk_no_check);
   tree decl = cp_parser_lookup_name_simple (parser, name, input_location);
+  pop_deferring_access_checks ();
 
   /* The enum-key is redundant for uses of the TYPE that are not
  declarations and for which name lookup returns just the type
@@ -30837,7 +30841,9 @@ cp_parser_check_class_key (cp_parser *pa
   tree name = DECL_NAME (type_decl);
   /* Look up the NAME to see if it unambiguously refers to the TYPE
  and set KEY_REDUNDANT if so.  */
+  push_deferring_access_checks (dk_no_check);
   tree decl = cp_parser_lookup_name_simple (parser, name, input_location);
+  pop_deferring_access_checks ();
 
   /* The class-key is redundant for uses of the CLASS_TYPE that are
  neither definitions of it nor declarations, and for which name
--- gcc/testsuite/g++.dg/warn/Wredundant-tags-2.C.jj2020-01-03 
10:56:10.408730751 +0100
+++ gcc/testsuite/g++.dg/warn/Wredundant-tags-2.C   2020-01-03 
10:56:00.525880326 +0100
@@ -0,0 +1,18 @@
+// PR c++/93138
+// { dg-do compile }
+// { dg-options "-Wredundant-tags" }
+
+struct Foo
+{
+  enum Kind { a };
+private:
+  Kind Kind;
+};
+enum Foo::Kind foo (); // { dg-bogus "is private within this 
context|redundant" }
+struct Bar
+{
+  struct Kind { int a; };
+private:
+  Kind Kind;
+};
+struct Bar::Kind bar ();   // { dg-bogus "is private within this 
context|redundant" }

Jakub



[C++ PATCH] PR c++/93033 - incorrect tree node sharing with array init.

2020-01-03 Thread Jason Merrill
The split_nonconstant_init piece is the only one necessary to fix the
testcase, but it occurred to me that we might as well not split when
-fno-exceptions.

Tested x86_64-pc-linux-gnu, applying to trunk.

* typeck2.c (split_nonconstant_init): Unshare non-decl.
* cp-gimplify.c (cp_gimplify_init_expr): Only split if -fexceptions.
---
 gcc/cp/cp-gimplify.c |  1 +
 gcc/cp/typeck2.c |  4 +++-
 gcc/testsuite/g++.dg/cpp0x/initlist-array9.C | 20 
 3 files changed, 24 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/initlist-array9.C

diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c
index 3eca3591e01..eb552767f61 100644
--- a/gcc/cp/cp-gimplify.c
+++ b/gcc/cp/cp-gimplify.c
@@ -529,6 +529,7 @@ cp_gimplify_init_expr (tree *expr_p, gimple_seq *pre_p)
   /* If we might need to clean up a partially constructed object, break down
  the CONSTRUCTOR with split_nonconstant_init.  */
   if (TREE_CODE (from) == CONSTRUCTOR
+  && flag_exceptions
   && TREE_SIDE_EFFECTS (from)
   && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (to)))
 {
diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index f36a5649ae6..955669727c3 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -34,6 +34,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "intl.h"
 #include "gcc-rich-location.h"
 #include "target.h"
+#include "gimplify.h"
 
 static tree
 process_init_constructor (tree type, tree init, int nested, int flags,
@@ -791,7 +792,8 @@ split_nonconstant_init (tree dest, tree init)
}
   else if (init)
{
- tree ie = build2 (INIT_EXPR, void_type_node, dest, init);
+ tree ie = build2 (INIT_EXPR, void_type_node,
+   unshare_expr (dest), init);
  code = add_stmt_to_compound (ie, code);
}
 }
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-array9.C 
b/gcc/testsuite/g++.dg/cpp0x/initlist-array9.C
new file mode 100644
index 000..4a5d74f6166
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist-array9.C
@@ -0,0 +1,20 @@
+// PR c++/93033
+// { dg-do compile { target c++11 } }
+
+struct A {
+  A ();
+  ~A ();
+};
+
+A f();
+
+struct B {
+  A a;
+  bool b;
+};
+
+void
+foo ()
+{
+  B i[] { f() };
+}

base-commit: a497906525b087eb03c5b162736b73f8de57c389
-- 
2.18.1



[C++ PATCH] Reject class template placeholder as non-type template parm type in C++17.

2020-01-03 Thread Jason Merrill
Jakub noticed that we were improperly allowing this in C++17 mode.

Tested x86_64-pc-linux-gnu, applying to trunk.

* pt.c (invalid_nontype_parm_type_p): Reject class placeholder in
C++17.
---
 gcc/cp/pt.c| 11 ++-
 gcc/testsuite/g++.dg/cpp1z/class-deduction64.C |  2 +-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 5b12aa6996a..bc23e9e0354 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -25811,7 +25811,16 @@ invalid_nontype_parm_type_p (tree type, tsubst_flags_t 
complain)
   else if (TYPE_PTRMEM_P (type))
 return false;
   else if (TREE_CODE (type) == TEMPLATE_TYPE_PARM)
-return false;
+{
+  if (CLASS_PLACEHOLDER_TEMPLATE (type) && cxx_dialect < cxx2a)
+   {
+ if (complain & tf_error)
+   error ("non-type template parameters of deduced class type only "
+  "available with %<-std=c++2a%> or %<-std=gnu++2a%>");
+ return true;
+   }
+  return false;
+}
   else if (TREE_CODE (type) == TYPENAME_TYPE)
 return false;
   else if (TREE_CODE (type) == DECLTYPE_TYPE)
diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction64.C 
b/gcc/testsuite/g++.dg/cpp1z/class-deduction64.C
index 3a06e6fb522..a21ea129f46 100644
--- a/gcc/testsuite/g++.dg/cpp1z/class-deduction64.C
+++ b/gcc/testsuite/g++.dg/cpp1z/class-deduction64.C
@@ -3,7 +3,7 @@
 
 template  struct S;
 
-template  struct W {
+template  struct W {  // { dg-error "class type" "" { target 
c++17_only } }
   template  static int foo();
   bool b = foo();
 };

base-commit: 95d4b531e7e3750bdde17079e209909deee6b219
-- 
2.18.1



[PATCH] analyzer: fix global-sm-state issue affecting sm-signal

2020-01-03 Thread David Malcolm
sm-signal.cc was failing to warn about the use of an fprintf call in a
signal handler when the signal handler function was non-static.

The root cause was a failure to copy global sm-state within
sm_state_map::clone_with_remapping as called by
program_state::can_merge_with_p, which led to the exploded node for
the entrypoint to the handler in the "normal" state being erroneously
reused for the "in_signal_handler" state, thus losing the global state,
and thus failing to warn.

This patch fixes the above, so that non-equal global sm-state values
prevent merger of program_state, thus requiring separate exploded nodes
for the "normal" and "in signal handler" states, and thus triggering
the warning for the reproducer.

Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Pushed to dmalcolm/analyzer on the GCC git mirror.

gcc/analyzer/ChangeLog:
* program-state.cc (sm_state_map::clone_with_remapping): Copy
m_global_state.
(selftest::test_program_state_merging_2): New selftest.
(selftest::analyzer_program_state_cc_tests): Call it.

gcc/testsuite/ChangeLog:
* gcc.dg/analyzer/signal-6.c: New test.
---
 gcc/analyzer/program-state.cc| 35 
 gcc/testsuite/gcc.dg/analyzer/signal-6.c | 20 ++
 2 files changed, 55 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/analyzer/signal-6.c

diff --git a/gcc/analyzer/program-state.cc b/gcc/analyzer/program-state.cc
index 3ed78b40928b..a5afb1c1bc07 100644
--- a/gcc/analyzer/program-state.cc
+++ b/gcc/analyzer/program-state.cc
@@ -59,6 +59,7 @@ sm_state_map *
 sm_state_map::clone_with_remapping (const one_way_svalue_id_map _map) const
 {
   sm_state_map *result = new sm_state_map ();
+  result->m_global_state = m_global_state;
   for (typename map_t::iterator iter = m_map.begin ();
iter != m_map.end ();
++iter)
@@ -1323,6 +1324,39 @@ test_program_state_merging ()
   ASSERT_EQ (s0, merged);
 }
 
+/* Verify that program_states with different global-state in an sm-state
+   can't be merged.  */
+
+static void
+test_program_state_merging_2 ()
+{
+  auto_delete_vec  checkers;
+  checkers.safe_push (make_signal_state_machine (NULL));
+  extrinsic_state ext_state (checkers);
+
+  program_state s0 (ext_state);
+  {
+sm_state_map *smap0 = s0.m_checker_states[0];
+const state_machine::state_t TEST_STATE_0 = 0;
+smap0->set_global_state (TEST_STATE_0);
+ASSERT_EQ (smap0->get_global_state (), TEST_STATE_0);
+  }
+
+  program_state s1 (ext_state);
+  {
+sm_state_map *smap1 = s1.m_checker_states[0];
+const state_machine::state_t TEST_STATE_1 = 1;
+smap1->set_global_state (TEST_STATE_1);
+ASSERT_EQ (smap1->get_global_state (), TEST_STATE_1);
+  }
+
+  ASSERT_NE (s0, s1);
+
+  /* They ought to not be mergeable.  */
+  program_state merged (ext_state);
+  ASSERT_FALSE (s0.can_merge_with_p (s1, ext_state, ));
+}
+
 /* Run all of the selftests within this file.  */
 
 void
@@ -1330,6 +1364,7 @@ analyzer_program_state_cc_tests ()
 {
   test_sm_state_map ();
   test_program_state_merging ();
+  test_program_state_merging_2 ();
 }
 
 } // namespace selftest
diff --git a/gcc/testsuite/gcc.dg/analyzer/signal-6.c 
b/gcc/testsuite/gcc.dg/analyzer/signal-6.c
new file mode 100644
index ..f51845167f5c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/analyzer/signal-6.c
@@ -0,0 +1,20 @@
+#include 
+#include 
+
+extern void body_of_program(void);
+
+/* Example of a non-static signal handler.  */
+
+void handler(int signum)
+{
+  fprintf(stderr, "LOG: %i", signum); /* { dg-warning "call to 'fprintf' from 
within signal handler" } */
+}
+
+int main(int argc, const char *argv)
+{
+  signal(SIGINT, handler); /* { dg-message "registering 'handler' as signal 
handler" } */
+
+  body_of_program();
+
+  return 0;
+}
-- 
2.21.0



[testsuite, X86, committed] Require effective target masm_intel for two tests.

2020-01-03 Thread Iain Sandoe
Hi and Happy New Year,

The vx512??-pr92686-vpcmp-intelasm-1.c  tests currently fail on targets that do 
not
support intel asm syntax.  Fixed by adding the effective target requires.

tested on x86_64-darwin16,
applied to mainline as obvious,
thanks
Iain

gcc/testsuite/ChangeLog:

2020-01-03  Iain Sandoe  

* gcc.target/i386/avx512bw-pr92686-vpcmp-intelasm-1.c: Require
effective target masm_intel.
* gcc.target/i386/avx512vl-pr92686-vpcmp-intelasm-1.c: Likewise.

diff --git a/gcc/testsuite/gcc.target/i386/avx512bw-pr92686-vpcmp-intelasm-1.c 
b/gcc/testsuite/gcc.target/i386/avx512bw-pr92686-vpcmp-intelasm-1.c
index 23c785ce9d..f1a62bdf32 100644
--- a/gcc/testsuite/gcc.target/i386/avx512bw-pr92686-vpcmp-intelasm-1.c
+++ b/gcc/testsuite/gcc.target/i386/avx512bw-pr92686-vpcmp-intelasm-1.c
@@ -1,5 +1,6 @@
 /* PR target/92686 */
 /* { dg-do assemble } */
+/* { dg-require-effective-target masm_intel } */
 /* { dg-options "-O2 -mavx512bw -mno-avx512dq -mno-avx512vl -mno-xop 
-masm=intel" } */
 /* { dg-require-effective-target avx512bw } */
 
diff --git a/gcc/testsuite/gcc.target/i386/avx512vl-pr92686-vpcmp-intelasm-1.c 
b/gcc/testsuite/gcc.target/i386/avx512vl-pr92686-vpcmp-intelasm-1.c
index c9a1b69003..907386db08 100644
--- a/gcc/testsuite/gcc.target/i386/avx512vl-pr92686-vpcmp-intelasm-1.c
+++ b/gcc/testsuite/gcc.target/i386/avx512vl-pr92686-vpcmp-intelasm-1.c
@@ -1,5 +1,6 @@
 /* PR target/88547 */
 /* { dg-do assemble } */
+/* { dg-require-effective-target masm_intel } */
 /* { dg-options "-O2 -mavx512bw -mavx512vl -mno-avx512dq -mno-xop -masm=intel" 
} */
 /* { dg-require-effective-target avx512bw } */
 /* { dg-require-effective-target avx512vl } */



[PATCH] libstdc++/92124 for associative containers

2020-01-03 Thread François Dumont

This is the patch to extend PR 92124 to the associative containers.

As it is pretty simple I thought it could maybe go in now.

I also think that the existing 92124 tests are not really testing what 
they should with the move assignment operators noexcept qualified, no ?


    PR libstdc++/92124
    * include/bits/stl_tree.h
    (_Rb_tree<>::_M_move_assign(_Rb_tree&, false_type)): Replace
    std::move_if_noexcept by std::move.
    * testsuite/23_containers/deque/92124.cc
    (X::operator==(X&&)): Qualify noexcept(false).
    * testsuite/23_containers/forward_list/92124.cc: Likewise.
    * testsuite/23_containers/list/92124.cc: Likewise.
    * testsuite/23_containers/vector/92124.cc: Likewise.
    * testsuite/23_containers/map/92124.cc: New.
    * testsuite/23_containers/set/92124.cc: New.

Tested under linux x86_64.

François

diff --git a/libstdc++-v3/include/bits/stl_tree.h b/libstdc++-v3/include/bits/stl_tree.h
index 12ba3181dd9..9339011e872 100644
--- a/libstdc++-v3/include/bits/stl_tree.h
+++ b/libstdc++-v3/include/bits/stl_tree.h
@@ -1695,7 +1695,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	[&__roan](const value_type& __cval)
 	{
 	  auto& __val = const_cast(__cval);
-	  return __roan(std::move_if_noexcept(__val));
+	  return __roan(std::move(__val));
 	};
 	  _M_root() = _M_copy(__x, __lbd);
 	  __x.clear();
diff --git a/libstdc++-v3/testsuite/23_containers/deque/92124.cc b/libstdc++-v3/testsuite/23_containers/deque/92124.cc
index 0bdfcb70dcf..ea16d415a49 100644
--- a/libstdc++-v3/testsuite/23_containers/deque/92124.cc
+++ b/libstdc++-v3/testsuite/23_containers/deque/92124.cc
@@ -30,7 +30,7 @@ struct X {
 // Tracking calls to assignment functions
 X& operator=(const X&) { throw 1; }
 
-X& operator=(X&&) noexcept(true) { return *this; }
+X& operator=(X&&) noexcept(false) { return *this; }
 };
 
 void
diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/92124.cc b/libstdc++-v3/testsuite/23_containers/forward_list/92124.cc
index 3e1b7ab3421..4d037f3a08f 100644
--- a/libstdc++-v3/testsuite/23_containers/forward_list/92124.cc
+++ b/libstdc++-v3/testsuite/23_containers/forward_list/92124.cc
@@ -30,7 +30,7 @@ struct X {
 // Tracking calls to assignment functions
 X& operator=(const X&) { throw 1; }
 
-X& operator=(X&&) noexcept(true) { return *this; }
+X& operator=(X&&) noexcept(false) { return *this; }
 };
 
 void
diff --git a/libstdc++-v3/testsuite/23_containers/list/92124.cc b/libstdc++-v3/testsuite/23_containers/list/92124.cc
index f9f2ed2e76f..49b74cab7e5 100644
--- a/libstdc++-v3/testsuite/23_containers/list/92124.cc
+++ b/libstdc++-v3/testsuite/23_containers/list/92124.cc
@@ -30,7 +30,7 @@ struct X {
 // Tracking calls to assignment functions
 X& operator=(const X&) { throw 1; }
 
-X& operator=(X&&) noexcept(true) { return *this; }
+X& operator=(X&&) noexcept(false) { return *this; }
 };
 
 void
diff --git a/libstdc++-v3/testsuite/23_containers/map/92124.cc b/libstdc++-v3/testsuite/23_containers/map/92124.cc
new file mode 100644
index 000..177c9d7abe9
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/map/92124.cc
@@ -0,0 +1,58 @@
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// .
+
+// { dg-do run { target c++11 } }
+
+#include 
+#include 
+
+struct X
+{
+  X() = default;
+  X(const X&)
+  { if (Throw) throw 1; }
+
+  // Move constructor might throw
+  X(X&&) noexcept(false) {}
+
+  // Tracking calls to assignment functions
+  X& operator=(const X&) { throw 1; }
+
+  X& operator=(X&&) noexcept(false) { return *this; }
+
+  static bool Throw;
+};
+
+bool X::Throw = false;
+
+void
+test01()
+{
+  using A = __gnu_test::propagating_allocator, false>;
+  A a1(1), a2(2);
+  std::map, A>
+m1({ { 1, X() } }, a1),
+m2({ { 2, X() } }, a2);
+  X::Throw = true;
+  m1 = std::move(m2);
+}
+
+int
+main()
+{
+  test01();
+}
diff --git a/libstdc++-v3/testsuite/23_containers/set/92124.cc b/libstdc++-v3/testsuite/23_containers/set/92124.cc
new file mode 100644
index 000..95a2e9ce518
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/set/92124.cc
@@ -0,0 +1,73 @@
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// 

Re: [Patch, Fortran] PR91640 – Fix call to contiguous dummy

2020-01-03 Thread Thomas König

Hi Tobias,

As a variant, I now use the latter (via the else branch). Either variant 
produces the same original tree. One can argue which variant is clearer; 
I think both are fine – pick one.


I think the second one (the one you just attached) looks better.

So, OK for trunk.  Thanks for the patch!

Regards

Thomas


Re: [Patch, Fortran] PR91640 – Fix call to contiguous dummy

2020-01-03 Thread Tobias Burnus

Hi Thomas,

On 1/3/20 7:18 PM, Thomas König wrote:


Build on x86-64-gnu-linux.
OK for the trunk – and for GCC 9? [It's a 9/10 regression]

Is is now okay?

If you add this, it would be good to add a test (for example counting
while statements in the *.original dump) that the copyback does not
happen.


I have now added something, which hopefully correctly captures this. I 
added 'xxx' to have some example how a copy out could look like. (That 
way, I also test whether a copy out happens.)


That creating a well-working pattern is difficult as get_var() also uses 
atmp. – However, looking at the dump, I found that the copy out will 
call get_var again! That's now PR 93148.



Generally, if we are passing an expression, the call to
gfc_conv_subref_array_arg is not needed - we will generate an array
temporary for the expression anyway, and this will always be contiguous.


True – but one needs to call some function. Whether 
gfc_conv_subref_array_arg with INTENT_IN or gfc_conv_array_parameter 
does not matter.


As a variant, I now use the latter (via the else branch). Either variant 
produces the same original tree. One can argue which variant is clearer; 
I think both are fine – pick one.


Tobias

	PR fortran/91640
	* trans-expr.c (gfc_conv_procedure_call): Avoid copy-out for nonvariable
	arguments to contiguous dummy args.  Avoid re-checking whether fsym is
	NULL.

	PR fortran/91640
	* gfortran.dg/contiguous_10.f90: New.

 gcc/fortran/trans-expr.c| 18 
 gcc/testsuite/gfortran.dg/contiguous_10.f90 | 69 +
 2 files changed, 78 insertions(+), 9 deletions(-)

diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index f2fe538a511..e1c0fb271de 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -6177,37 +6177,37 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
 fsym ? fsym->attr.intent : INTENT_INOUT,
 fsym && fsym->attr.pointer);
 
 	  else if (gfc_is_class_array_ref (e, NULL)
-			 && fsym && fsym->ts.type == BT_DERIVED)
+		   && fsym && fsym->ts.type == BT_DERIVED)
 		/* The actual argument is a component reference to an
 		   array of derived types.  In this case, the argument
 		   is converted to a temporary, which is passed and then
 		   written back after the procedure call.
 		   OOP-TODO: Insert code so that if the dynamic type is
 		   the same as the declared type, copy-in/copy-out does
 		   not occur.  */
 		gfc_conv_subref_array_arg (, e, nodesc_arg,
-fsym ? fsym->attr.intent : INTENT_INOUT,
-fsym && fsym->attr.pointer);
+	   fsym->attr.intent,
+	   fsym->attr.pointer);
 
 	  else if (gfc_is_class_array_function (e)
-			 && fsym && fsym->ts.type == BT_DERIVED)
+		   && fsym && fsym->ts.type == BT_DERIVED)
 		/* See previous comment.  For function actual argument,
 		   the write out is not needed so the intent is set as
 		   intent in.  */
 		{
 		  e->must_finalize = 1;
 		  gfc_conv_subref_array_arg (, e, nodesc_arg,
-	 INTENT_IN,
-	 fsym && fsym->attr.pointer);
+	 INTENT_IN, fsym->attr.pointer);
 		}
 	  else if (fsym && fsym->attr.contiguous
-		   && !gfc_is_simply_contiguous (e, false, true))
+		   && !gfc_is_simply_contiguous (e, false, true)
+		   && gfc_expr_is_variable (e))
 		{
 		  gfc_conv_subref_array_arg (, e, nodesc_arg,
-fsym ? fsym->attr.intent : INTENT_INOUT,
-fsym && fsym->attr.pointer);
+	 fsym->attr.intent,
+	 fsym->attr.pointer);
 		}
 	  else
 		gfc_conv_array_parameter (, e, nodesc_arg, fsym,
 	  sym->name, NULL);
diff --git a/gcc/testsuite/gfortran.dg/contiguous_10.f90 b/gcc/testsuite/gfortran.dg/contiguous_10.f90
new file mode 100644
index 000..82b8ed54f5b
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/contiguous_10.f90
@@ -0,0 +1,69 @@
+! { dg-do run }
+! { dg-additional-options "-fdump-tree-original" }
+!
+! PR fortran/91640
+!
+! Based on G. Steinmetz's test case
+!
+program p
+   implicit none (type, external)
+   real, target :: z(3) = 1.0
+   real :: res(3)
+   real, pointer :: xxx(:)
+
+   res = 42.0
+   call sub (-z, res)
+   if (any (abs (res - (-1.0)) > epsilon(res))) stop 1
+   if (any (abs (z - 1.0) > epsilon(z))) stop 2
+
+   res = 43.0
+   call sub (z*2.0, res)
+   if (any (abs (res - 2.0) > epsilon(res))) stop 3
+   if (any (abs (z - 1.0) > epsilon(z))) stop 4
+
+   res = 44.0
+   call sub(get_var(), res)
+   if (any (abs (res - 1.0) > epsilon(res))) stop 5
+   if (any (abs (z - 1.0) > epsilon(z))) stop 6
+
+   call double(get_var())
+   if (any (abs (z - 2.0) > epsilon(z))) stop 7
+
+   call double(get_var_cont())
+   if (any (abs (z - 4.0) > epsilon(z))) stop 8
+
+   ! For cross check for copy-out:
+   xxx => z
+   if (any (abs (z - 4.0) > epsilon(z))) stop 10
+   if (any (abs (xxx - 4.0) > epsilon(z))) stop 11
+   call double (xxx)
+   if (any (abs (z - 8.0) > epsilon(z))) stop 12
+   if (any (abs (xxx - 8.0) > epsilon(z))) stop 13
+

[PATCH 2/2] analyzer: cleanups to checker_path

2020-01-03 Thread David Malcolm
This patch adds DISABLE_COPY_AND_ASSIGN to checker_path, and makes its
fields private.

Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Pushed to dmalcolm/analyzer on the GCC git mirror.

gcc/analyzer/ChangeLog:
* checker-path.h (checker_path::get_checker_event): New function.
(checker_path): Add DISABLE_COPY_AND_ASSIGN; make fields private.
* diagnostic-manager.cc
(diagnostic_manager::prune_for_sm_diagnostic): Replace direct
access to checker_path::m_events with accessor functions.  Fix
overlong line.
(diagnostic_manager::prune_interproc_events): Replace direct
access to checker_path::m_events with accessor functions.
(diagnostic_manager::finish_pruning): Likewise.
---
 gcc/analyzer/checker-path.h|  8 +++
 gcc/analyzer/diagnostic-manager.cc | 37 --
 2 files changed, 28 insertions(+), 17 deletions(-)

diff --git a/gcc/analyzer/checker-path.h b/gcc/analyzer/checker-path.h
index 9faaeb72ddc5..35d9700e0385 100644
--- a/gcc/analyzer/checker-path.h
+++ b/gcc/analyzer/checker-path.h
@@ -455,6 +455,11 @@ public:
 return *m_events[idx];
   }
 
+  checker_event *get_checker_event (int idx)
+  {
+return m_events[idx];
+  }
+
   void dump (pretty_printer *pp) const;
   void debug () const;
 
@@ -505,6 +510,9 @@ public:
 return false;
   }
 
+private:
+  DISABLE_COPY_AND_ASSIGN(checker_path);
+
   /* The events that have occurred along this path.  */
   auto_delete_vec m_events;
 
diff --git a/gcc/analyzer/diagnostic-manager.cc 
b/gcc/analyzer/diagnostic-manager.cc
index 5e4e44ecae73..c7d5f1c514fc 100644
--- a/gcc/analyzer/diagnostic-manager.cc
+++ b/gcc/analyzer/diagnostic-manager.cc
@@ -935,10 +935,10 @@ diagnostic_manager::prune_for_sm_diagnostic (checker_path 
*path,
 tree var,
 state_machine::state_t state) const
 {
-  int idx = path->m_events.length () - 1;
-  while (idx >= 0 && idx < (signed)path->m_events.length ())
+  int idx = path->num_events () - 1;
+  while (idx >= 0 && idx < (signed)path->num_events ())
 {
-  checker_event *base_event = path->m_events[idx];
+  checker_event *base_event = path->get_checker_event (idx);
   if (get_logger ())
{
  if (sm)
@@ -1070,7 +1070,8 @@ diagnostic_manager::prune_for_sm_diagnostic (checker_path 
*path,
log ("filtering event %i: CFG edge", idx);
path->delete_event (idx);
/* Also delete the corresponding EK_END_CFG_EDGE.  */
-   gcc_assert (path->m_events[idx]->m_kind == EK_END_CFG_EDGE);
+   gcc_assert (path->get_checker_event (idx)->m_kind
+   == EK_END_CFG_EDGE);
path->delete_event (idx);
  }
  }
@@ -1167,18 +1168,19 @@ diagnostic_manager::prune_interproc_events 
(checker_path *path) const
   do
 {
   changed = false;
-  int idx = path->m_events.length () - 1;
+  int idx = path->num_events () - 1;
   while (idx >= 0)
{
  /* Prune [..., call, function-entry, return, ...] triples.  */
- if (idx + 2 < (signed)path->m_events.length ()
- && path->m_events[idx]->is_call_p ()
- && path->m_events[idx + 1]->is_function_entry_p ()
- && path->m_events[idx + 2]->is_return_p ())
+ if (idx + 2 < (signed)path->num_events ()
+ && path->get_checker_event (idx)->is_call_p ()
+ && path->get_checker_event (idx + 1)->is_function_entry_p ()
+ && path->get_checker_event (idx + 2)->is_return_p ())
{
  if (get_logger ())
{
- label_text desc (path->m_events[idx]->get_desc (false));
+ label_text desc
+   (path->get_checker_event (idx)->get_desc (false));
  log ("filtering events %i-%i:"
   " irrelevant call/entry/return: %s",
   idx, idx + 2, desc.m_buffer);
@@ -1194,13 +1196,14 @@ diagnostic_manager::prune_interproc_events 
(checker_path *path) const
 
  /* Prune [..., call, return, ...] pairs
 (for -fanalyzer-verbosity=0).  */
- if (idx + 1 < (signed)path->m_events.length ()
- && path->m_events[idx]->is_call_p ()
- && path->m_events[idx + 1]->is_return_p ())
+ if (idx + 1 < (signed)path->num_events ()
+ && path->get_checker_event (idx)->is_call_p ()
+ && path->get_checker_event (idx + 1)->is_return_p ())
{
  if (get_logger ())
{
- label_text desc (path->m_events[idx]->get_desc (false));
+ label_text desc
+   (path->get_checker_event (idx)->get_desc (false));
  log ("filtering events %i-%i:"
   " irrelevant call/return: %s",
  

[PATCH 1/2] analyzer: delete checker_event::clone

2020-01-03 Thread David Malcolm
checker_event has a clone vfunc implemented by all the concrete
subclasses, but this is never used (a holdover from a very early
implementation).  This patch deletes it.

Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Pushed to dmalcolm/analyzer on the GCC git mirror.

gcc/analyzer/ChangeLog:
* checker-path.h (checker_event::clone): Delete vfunc decl.
(debug_event::clone): Delete vfunc impl.
(custom_event::clone): Delete vfunc impl.
(statement_event::clone): Delete vfunc impl.
(function_entry_event::clone): Delete vfunc impl.
(state_change_event::clone): Delete vfunc impl.
(start_cfg_edge_event::clone): Delete vfunc impl.
(end_cfg_edge_event::clone): Delete vfunc impl.
(call_event::clone): Delete vfunc impl.
(return_event::clone): Delete vfunc impl.
(setjmp_event::clone): Delete vfunc impl.
(rewind_from_longjmp_event::clone): Delete vfunc impl.
(rewind_to_setjmp_event::clone): Delete vfunc impl.
(warning_event::clone): Delete vfunc impl.
---
 gcc/analyzer/checker-path.h | 72 -
 1 file changed, 72 deletions(-)

diff --git a/gcc/analyzer/checker-path.h b/gcc/analyzer/checker-path.h
index bdad5abc413d..9faaeb72ddc5 100644
--- a/gcc/analyzer/checker-path.h
+++ b/gcc/analyzer/checker-path.h
@@ -91,8 +91,6 @@ public:
 
   /* Additional functionality.  */
 
-  virtual checker_event *clone () const = 0;
-
   virtual void prepare_for_emission (checker_path *,
 pending_diagnostic *pd,
 diagnostic_event_id_t emission_id);
@@ -131,11 +129,6 @@ public:
 
   label_text get_desc (bool) const FINAL OVERRIDE;
 
-  checker_event *clone () const FINAL OVERRIDE
-  {
-return new debug_event (m_loc, m_fndecl, m_depth, m_desc);
-  }
-
 private:
   char *m_desc;
 };
@@ -159,11 +152,6 @@ public:
 
   label_text get_desc (bool) const FINAL OVERRIDE;
 
-  checker_event *clone () const FINAL OVERRIDE
-  {
-return new custom_event (m_loc, m_fndecl, m_depth, m_desc);
-  }
-
 private:
   char *m_desc;
 };
@@ -179,11 +167,6 @@ public:
 
   label_text get_desc (bool) const FINAL OVERRIDE;
 
-  checker_event *clone () const FINAL OVERRIDE
-  {
-return new statement_event (m_stmt, m_fndecl, m_depth, m_dst_state);
-  }
-
   const gimple * const m_stmt;
   const program_state m_dst_state;
 };
@@ -200,11 +183,6 @@ public:
 
   label_text get_desc (bool can_colorize) const FINAL OVERRIDE;
 
-  checker_event *clone () const FINAL OVERRIDE
-  {
-return new function_entry_event (m_loc, m_fndecl, m_depth);
-  }
-
   bool is_function_entry_p () const FINAL OVERRIDE { return true; }
 };
 
@@ -224,13 +202,6 @@ public:
 
   label_text get_desc (bool can_colorize) const FINAL OVERRIDE;
 
-  checker_event *clone () const FINAL OVERRIDE
-  {
-return new state_change_event (m_node, m_stmt, m_depth,
-  m_sm, m_var, m_from, m_to, m_origin,
-  m_dst_state);
-  }
-
   region_id get_lvalue (tree expr) const
   {
 return m_dst_state.m_region_model->get_lvalue (expr, NULL);
@@ -305,11 +276,6 @@ public:
 
   label_text get_desc (bool can_colorize) const FINAL OVERRIDE;
 
-  checker_event *clone () const FINAL OVERRIDE
-  {
-return new start_cfg_edge_event (m_eedge, m_loc, m_fndecl, m_depth);
-  }
-
  private:
   label_text maybe_describe_condition (bool can_colorize) const;
 
@@ -336,11 +302,6 @@ public:
   {
 return label_text::borrow ("...to here");
   }
-
-  checker_event *clone () const FINAL OVERRIDE
-  {
-return new end_cfg_edge_event (m_eedge, m_loc, m_fndecl, m_depth);
-  }
 };
 
 /* A concrete event subclass for an interprocedural call.  */
@@ -353,11 +314,6 @@ public:
 
   label_text get_desc (bool can_colorize) const FINAL OVERRIDE;
 
-  checker_event *clone () const FINAL OVERRIDE
-  {
-return new call_event (m_eedge, m_loc, m_fndecl, m_depth);
-  }
-
   bool is_call_p () const FINAL OVERRIDE;
 };
 
@@ -371,11 +327,6 @@ public:
 
   label_text get_desc (bool can_colorize) const FINAL OVERRIDE;
 
-  checker_event *clone () const FINAL OVERRIDE
-  {
-return new return_event (m_eedge, m_loc, m_fndecl, m_depth);
-  }
-
   bool is_return_p () const FINAL OVERRIDE;
 };
 
@@ -391,11 +342,6 @@ public:
   {
   }
 
-  setjmp_event *clone () const FINAL OVERRIDE
-  {
-return new setjmp_event (m_loc, m_enode, m_fndecl, m_depth);
-  }
-
   label_text get_desc (bool can_colorize) const FINAL OVERRIDE;
 
   void prepare_for_emission (checker_path *path,
@@ -439,12 +385,6 @@ public:
   }
 
   label_text get_desc (bool can_colorize) const FINAL OVERRIDE;
-
-  rewind_from_longjmp_event *clone () const FINAL OVERRIDE
-  {
-return new rewind_from_longjmp_event (get_eedge (),
- m_loc, m_fndecl, m_depth);
-  }
 };
 
 /* A concrete event subclass for rewinding from a longjmp to a setjmp,

Fortran patches to be reviewed (was: [Patch, Fortran] PR91640 – Fix call to contiguous dummy)

2020-01-03 Thread Thomas Koenig

Hi Tobias,

PS: I lost a bit the overview. Is there any patch pending review or 
otherwise pending?


From my side, there is the patch for PR 65428,

https://gcc.gnu.org/ml/gcc-patches/2020-01/msg00040.html

Apart from that, I don't see any outstanding patches.

Regards

Thomas


Re: [Patch, Fortran] PR91640 – Fix call to contiguous dummy

2020-01-03 Thread Thomas König

Hi Tobias,

If one passes something which is not a variable as an argument, there is 
no point to do the copy-out – the copy-in is sufficient. Note that a the 
result of a pointer-returning function is regarded as variable.


As cleanup, I also fixed the indentation (twice) and the pointless 'fsym 
?' check inside a condition body where the condition already checks this.


Build on x86-64-gnu-linux.
OK for the trunk – and for GCC 9? [It's a 9/10 regression]


The change to avoid the copy-out via INTENT(IN) makes sense.
If you add this, it would be good to add a test (for example counting
while statements in the *.original dump) that the copyback does not
happen.

Generally, if we are passing an expression, the call to
gfc_conv_subref_array_arg is not needed - we will generate an array
temporary for the expression anyway, and this will always be contiguous.

Regards

Thomas


Connect and Network with Regulators and Canna Operators

2020-01-03 Thread CannaWest Summit
CannaWest   
     
 
http://links.infocastevents.mkt8115.com/ctt?kn=13=NDE0MTM4MzgS1=NjkyMTk1NzM3MTk0S0=2=MTY4MDI1MTIxMQS2=1=0
  

The CannaWest Summit is a unique and highly regarded event where senior 
cannabis regulators will meet with experienced operators to network and discuss 
how to solve the multitude of issues facing the regulated cannabis industry. 
Hear strategies on topics like public health concerns around vaping, increasing 
cannabis mark-up and cultivation tax rate changes, as well as increasing 
competition from the illegal market.

For all established operators, this is a remarkable opportunity to hear and 
learn dynamic solutions to the industry's most critical issues. New and 
emerging regulations, in a volatile and dynamic market, will be a hot topic 
discussed by the who’s who of industry insiders at the CannaWest Summit.

Don’t Miss This Great Opportunity.
Reserve Your Seat Today! 
Register Now

Featured Speakers
Lori Ajax, Chief, CA BUREAU OF CANNABIS CONTROL
Carrie Bishop, Chief Digital Services Officer, CITY AND COUNTY OF SAN FRANCISCO
Amanda Borup, Policy Analyst, Recreational Marijuana Program, OREGON LIQUOR 
CONTROL COMMISSION
Christina Coursey, Licensing Coordinator, Cannabis Program, CITY OF PORTLAND
Bonnie Czander, REHS, Director, Environmental Specialist, DETROIT HEALTH 
DEPARTMENT
Greg Minor, Assistant to the City Administrator Nuisance Abatement/Special 
Activity Permits Division, CITY OF OAKLAND
Cat Packer, Executive Director, Department of Cannabis Regulation, CITY OF LOS 
ANGELES
Richard Parrott, Director, CalCannabis Cultivation Licensing,
CALIFORNIA DEPARTMENT OF FOOD AND AGRICULTURE
Jackie Rocco, Director of Public Works, CITY OF WEST HOLLYWOOD


---
 
Interested in being a sponsor?   
Email lawren...@infocastevents.com or call (818) 888-4445 ext. 31   
 

Copyright © 2019 Information Forecast, Inc., All rights reserved.
  
Infocast, 20931 Burbank Boulevard, Woodland Hills, CA 91367, United States
  
Contact Us mailto:i...@infocastevents.com?subject= 
Visit Website 
http://links.infocastevents.mkt8115.com/ctt?kn=3=NDE0MTM4MzgS1=NjkyMTk1NzM3MTk0S0=2=MTY4MDI1MTIxMQS2=1=0
 
Unsubscribe from all emails 
http://www.pages03.net/informationforecastinc/UnsubAll/UnsubAllForm?spMailingID=41413838=NjkyMTk1NzM3MTk0S0=MTY4MDI1MTIxMQS2=MTY4MDI1MTIxMQS2
 



[Patch, Fortran] PR91640 – Fix call to contiguous dummy

2020-01-03 Thread Tobias Burnus
If one passes something which is not a variable as an argument, there is 
no point to do the copy-out – the copy-in is sufficient. Note that a the 
result of a pointer-returning function is regarded as variable.


As cleanup, I also fixed the indentation (twice) and the pointless 'fsym 
?' check inside a condition body where the condition already checks this.


Build on x86-64-gnu-linux.
OK for the trunk – and for GCC 9? [It's a 9/10 regression]

Cheers,

Tobias

PS: I lost a bit the overview. Is there any patch pending review or 
otherwise pending? I know that PR92178 is pending (mostly okay, but some 
follow-up work needed/useful). Anything else?


	PR fortran/91640
	* trans-expr.c (gfc_conv_procedure_call): Avoid copy-out for nonvariable
	arguments to contiguous dummy args.  Avoid re-checking whether fsym is
	NULL.

	PR fortran/91640
	* gfortran.dg/contiguous_10.f90: New.

 gcc/fortran/trans-expr.c| 19 +--
 gcc/testsuite/gfortran.dg/contiguous_10.f90 | 49 +
 2 files changed, 59 insertions(+), 9 deletions(-)

diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index f2fe538a511..471540453dc 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -6177,37 +6177,38 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
 fsym ? fsym->attr.intent : INTENT_INOUT,
 fsym && fsym->attr.pointer);
 
 	  else if (gfc_is_class_array_ref (e, NULL)
-			 && fsym && fsym->ts.type == BT_DERIVED)
+		   && fsym && fsym->ts.type == BT_DERIVED)
 		/* The actual argument is a component reference to an
 		   array of derived types.  In this case, the argument
 		   is converted to a temporary, which is passed and then
 		   written back after the procedure call.
 		   OOP-TODO: Insert code so that if the dynamic type is
 		   the same as the declared type, copy-in/copy-out does
 		   not occur.  */
 		gfc_conv_subref_array_arg (, e, nodesc_arg,
-fsym ? fsym->attr.intent : INTENT_INOUT,
-fsym && fsym->attr.pointer);
+	   fsym->attr.intent,
+	   fsym->attr.pointer);
 
 	  else if (gfc_is_class_array_function (e)
-			 && fsym && fsym->ts.type == BT_DERIVED)
+		   && fsym && fsym->ts.type == BT_DERIVED)
 		/* See previous comment.  For function actual argument,
 		   the write out is not needed so the intent is set as
 		   intent in.  */
 		{
 		  e->must_finalize = 1;
 		  gfc_conv_subref_array_arg (, e, nodesc_arg,
-	 INTENT_IN,
-	 fsym && fsym->attr.pointer);
+	 INTENT_IN, fsym->attr.pointer);
 		}
 	  else if (fsym && fsym->attr.contiguous
 		   && !gfc_is_simply_contiguous (e, false, true))
 		{
-		  gfc_conv_subref_array_arg (, e, nodesc_arg,
-fsym ? fsym->attr.intent : INTENT_INOUT,
-fsym && fsym->attr.pointer);
+		  sym_intent intent = fsym->attr.intent;
+		  if (!gfc_expr_is_variable (e))
+		intent = INTENT_IN;
+		  gfc_conv_subref_array_arg (, e, nodesc_arg, intent,
+	 fsym->attr.pointer);
 		}
 	  else
 		gfc_conv_array_parameter (, e, nodesc_arg, fsym,
 	  sym->name, NULL);
diff --git a/gcc/testsuite/gfortran.dg/contiguous_10.f90 b/gcc/testsuite/gfortran.dg/contiguous_10.f90
new file mode 100644
index 000..46a497d6967
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/contiguous_10.f90
@@ -0,0 +1,49 @@
+! { dg-do run }
+!
+! PR fortran/91640
+!
+! Based on G. Steinmetz's test case
+!
+program p
+   implicit none (type, external)
+   real, target :: z(3) = 1.0
+   real :: res(3)
+
+   res = 42.0
+   call sub (-z, res)
+   if (any (abs (res - (-1.0)) > epsilon(res))) stop 1
+   if (any (abs (z - 1.0) > epsilon(z))) stop 2
+
+   res = 43.0
+   call sub (z*2.0, res)
+   if (any (abs (res - 2.0) > epsilon(res))) stop 3
+   if (any (abs (z - 1.0) > epsilon(z))) stop 4
+
+   res = 44.0
+   call sub(get_var(), res)
+   if (any (abs (res - 1.0) > epsilon(res))) stop 5
+   if (any (abs (z - 1.0) > epsilon(z))) stop 6
+
+   call double(get_var())
+   if (any (abs (z - 2.0) > epsilon(z))) stop 7
+
+   call double(get_var_cont())
+   if (any (abs (z - 4.0) > epsilon(z))) stop 8
+contains
+   subroutine sub (x, res)
+  real, contiguous :: x(:), res(:)
+  res = x
+   end
+   subroutine double (x)
+  real, contiguous :: x(:)
+  x = x * 2.0
+   end
+   function get_var()
+ real, pointer :: get_var(:)
+ get_var => z
+   end
+   function get_var_cont()
+ real, pointer, contiguous :: get_var_cont(:)
+ get_var_cont => z
+   end
+end


Re: [PATCH] Mark param_max_combine_insns with Optimization keyword.

2020-01-03 Thread Segher Boessenkool
Hi!

On Thu, Jan 02, 2020 at 12:07:27PM +0100, Martin Liška wrote:
> The param is changed here:
> 
>   /* Restrict the amount of work combine does at -Og while retaining
>  most of its useful transforms.  */
>   if (opts->x_optimize_debug)
> SET_OPTION_IF_UNSET (opts, opts_set, param_max_combine_insns, 2);
> 
> and so that it should be per-function. The only usage is in combine RTL
> pass, which is per-function optimization.
> 
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
> 
> Ready to be installed?

Sure.  Okay for trunk.  Thanks!

> 2020-01-02  Martin Liska  
> 
>   PR tree-optimization/92860
>   * params.opt: Mart param_max_combine_insns with Optimization
>   keyword.

s/mart/mark/

(Btw, does this help -Og at all?  If so, shouldn't it be -O1 as well?)


Segher


[PATCH] Fix a bug that propagation in recursive function uses wrong aggregate lattice (PR ipa/93084)

2020-01-03 Thread Feng Xue OS
When checking a self-recursively generated value for aggregate jump
function, wrong aggregate lattice was used, which will cause infinite
constant propagation. This patch is composed to fix this issue. 

2020-01-03  Feng Xue  

PR ipa/93084
* ipa-cp.c (self_recursively_generated_p): Find matched aggregate
lattice for a value to check.
(propagate_vals_across_arith_jfunc): Add an assertion to ensure
finite propagation in self-recursive scc.

Feng

0001-Fix-pr93084.patch
Description: 0001-Fix-pr93084.patch


Re: Define HAVE_ for math long double functions declared in vxworks headers

2020-01-03 Thread Jonathan Wakely

On 25/12/19 03:40 -0300, Alexandre Oliva wrote:


When cross-building for vxworks, test for declarations of long double
functions in math.h.  We don't normally test for these functions when
cross compiling, because link tests don't work, or ever really, but
not defining them as available causes replacements to be defined in
ways that may cause duplicate definition linker errors if the units
defining both the replacement and the actual implementation are
brought in because of other symbols.

Tested on trunk by checking configure results of libstdc++-v3 for an
affected target, and also building natively on x86_64-linux-gnu.  Also
tested for various cross configurations far more thoroughly on trees not
matching trunk so closely.  I'm checking this in.


libstdc++-v3/
* crossconfig.m4 (GLIBCXX_CROSSCONFIG) [*-vxworks*]: Define
long double functions as available if declared by math.h.
(GLIBCXX_CHECK_MATH_DECL, GLIBCXX_CHECK_MATH_DECLS): New.
* configure: Rebuild.
---
libstdc++-v3/configure  | 1104 +++
libstdc++-v3/crossconfig.m4 |   62 ++
2 files changed, 1166 insertions(+)

diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure
[omitted]
diff --git a/libstdc++-v3/crossconfig.m4 b/libstdc++-v3/crossconfig.m4
index 5e24889..2a0cb04 100644
--- a/libstdc++-v3/crossconfig.m4
+++ b/libstdc++-v3/crossconfig.m4
@@ -291,9 +291,71 @@ case "${host}" in
AC_DEFINE(HAVE_SQRTF)
AC_DEFINE(HAVE_TANF)
AC_DEFINE(HAVE_TANHF)
+
+dnl # Different versions and execution modes implement different
+dnl # subsets of these functions.  Instead of hard-coding, test for C
+dnl # declarations in headers.  The C primitives could be defined as
+dnl # macros, in which case the tests might fail, and we might have to
+dnl # switch to more elaborate tests.
+GLIBCXX_CHECK_MATH_DECLS([
+  acosl asinl atan2l atanl ceill cosl coshl expl fabsl floorl fmodl
+  frexpl ldexpl log10l logl modfl powl sinl sinhl sqrtl tanl tanhl])
+dnl # sincosl is the only one missing here, compared with the *l
+dnl # functions in the list guarded by
+dnl # long_double_math_on_this_cpu in configure.ac, right after
+dnl # the expansion of the present macro.
;;
  *)
AC_MSG_ERROR([No support for this host/target combination.])
   ;;
esac
])
+
+
+dnl
+dnl Check to see if the (math function) argument passed is
+dnl declared when using the c compiler
+dnl
+dnl Define HAVE_CARGF etc if "cargf" is declared
+dnl
+dnl argument 1 is name of function to check
+dnl
+dnl ASSUMES argument is a math function
+dnl
+dnl GLIBCXX_CHECK_MATH_DECL
+AC_DEFUN([GLIBCXX_CHECK_MATH_DECL], [
+  AC_CACHE_CHECK([for $1 declaration],
+[glibcxx_cv_func_$1_use], [
+  AC_LANG_SAVE
+  AC_LANG_C
+  AC_TRY_COMPILE([
+#include 
+#ifdef HAVE_IEEEFP_H
+# include 
+#endif
+], [
+  void (*f)(void) = (void (*)(void))$1;


I wondered whether using ($1) here instead of just $1 would give any
benefit. It would mean that function-like macros are ignored.

Maybe it would be better to just do #undef $1 before the test, so that
all macros are ignored. That would match the actual usage, as 
does a #undef for each function.



Re: [PATCH] [RFC] ipa: duplicate ipa_size_summary for cloned nodes

2020-01-03 Thread Martin Jambor
Hi,

On Thu, Dec 19 2019, Jan Hubicka wrote:
>> On 2019/12/18 23:48, Jan Hubicka wrote:
>> >> The size_info of ipa_size_summary are created by r277424.  It should be
>> >> duplicated for cloned nodes, otherwise self_size and 
>> >> estimated_self_stack_size
>> >> would be 0, causing param large-function-insns and large-function-growth 
>> >> working
>> >> inaccurate when ipa-inline.
>> >>
>> >> gcc/ChangeLog:
>> >>
>> >>   2019-12-18  Luo Xiong Hu  
>> >>
>> >>   * ipa-fnsummary.c (ipa_fn_summary_t::duplicate): Copy
>> >>   ipa_size_summary for cloned nodes.
>> >> ---
>> >>   gcc/ipa-fnsummary.c | 5 +
>> >>   1 file changed, 5 insertions(+)
>> >>
>> >> diff --git a/gcc/ipa-fnsummary.c b/gcc/ipa-fnsummary.c
>> >> index a46b1445765..9a01be1708b 100644
>> >> --- a/gcc/ipa-fnsummary.c
>> >> +++ b/gcc/ipa-fnsummary.c
>> >> @@ -868,7 +868,12 @@ ipa_fn_summary_t::duplicate (cgraph_node *src,
>> >>   }
>> >>   }
>> >> if (!dst->inlined_to)
>> >> +  {
>> >> +class ipa_size_summary *src_size = ipa_size_summaries->get_create 
>> >> (src);
>> >> +class ipa_size_summary *dst_size = ipa_size_summaries->get_create 
>> >> (dst);
>> > 
>> > This is intended to happen by the default duplicate method of
>> > ipa_size_summaries via to copy constructor. It seems there is a stupid
>> > pasto and the copy constructor is unused since the default duplicate
>> > implementation does nothing (wonder why).
>> > 
>> > I am testing the attached patch.  Does this help?
>> 
>> Yes, It works.  Thanks for your refine.  The default duplicate 
>> implementation is in
>> symbol-summary.h:template class function_summary_base::duplicate, I 
>> tried
>> to call duplicate in it, but it will cause a lot of errors as many classes 
>> doesn't
>> implement the virtual duplicate function.  Please commit your patch once 
>> tested pass :)
> Comitted, thanks!

Unfortunately, this has caused Ada LTO bootstrap to fail when the system
compiler is GCC 4.8.5.  Ada LTO bootstrap seems to be fine when the
system compiler is GCC 7.4.1.  I do not know what is the minimal version
which works.

Not sure to what extent this is a problem but we should at least
document it, I guess.  For what it's worth the warnings and errors that
lead to the bootstrap failure are copied below.

Martin


/home/mjambor/gcc/mine/src/gcc/ada/gnatvsn.adb:57:4: warning: type of 
‘gnatvsn__version_string’ does not match original declaration 
[-Wlto-type-mismatch]
   57 |Version_String : char_array (0 .. Ver_Len_Max - 1);
  |^
/home/mjambor/gcc/mine/src/gcc/version.c:34:12: note: array types have 
different bounds
   34 | const char version_string[] = BASEVER DATESTAMP DEVPHASE REVISION;
  |^
/home/mjambor/gcc/mine/src/gcc/version.c:34:12: note: ‘version_string’ was 
previously declared here
/home/mjambor/gcc/mine/src/gcc/ada/libgnat/a-except.adb:1663:17: warning: type 
of ‘ada__exceptions__to_stderr__put_char_stderr__2’ does not match original 
declaration [-Wlto-type-mismatch]
 1663 |   procedure Put_Char_Stderr (C : Character);
  | ^
/home/mjambor/gcc/mine/src/gcc/ada/cio.c:126:1: note: type mismatch in 
parameter 1
  126 | put_char_stderr (int c)
  | ^
/home/mjambor/gcc/mine/src/gcc/ada/cio.c:126:1: note: type ‘int’ should match 
type ‘character’
/home/mjambor/gcc/mine/src/gcc/ada/cio.c:126:1: note: ‘put_char_stderr’ was 
previously declared here
/home/mjambor/gcc/mine/src/gcc/ada/raise-gcc.c:542:18: warning: type of 
‘__gnat_others_value’ does not match original declaration [-Wlto-type-mismatch]
  542 | extern const int __gnat_others_value;
  |  ^
/home/mjambor/gcc/mine/src/gcc/ada/libgnat/a-exexpr.adb:303:4: note: type 
‘character’ should match type ‘const int’
  303 |Others_Value : constant Character := 'O';
  |^
/home/mjambor/gcc/mine/src/gcc/ada/libgnat/a-exexpr.adb:303:4: note: 
‘ada__exceptions__exception_propagation__others_valueXn’ was previously 
declared here
/home/mjambor/gcc/mine/src/gcc/ada/raise-gcc.c:545:18: warning: type of 
‘__gnat_all_others_value’ does not match original declaration 
[-Wlto-type-mismatch]
  545 | extern const int __gnat_all_others_value;
  |  ^
/home/mjambor/gcc/mine/src/gcc/ada/libgnat/a-exexpr.adb:306:4: note: type 
‘character’ should match type ‘const int’
  306 |All_Others_Value : constant Character := 'A';
  |^
/home/mjambor/gcc/mine/src/gcc/ada/libgnat/a-exexpr.adb:306:4: note: 
‘ada__exceptions__exception_propagation__all_others_valueXn’ was previously 
declared here
/home/mjambor/gcc/mine/src/gcc/ada/raise-gcc.c:548:18: warning: type of 
‘__gnat_unhandled_others_value’ does not match original declaration 
[-Wlto-type-mismatch]
  548 | extern const int __gnat_unhandled_others_value;
  |  ^
/home/mjambor/gcc/mine/src/gcc/ada/libgnat/a-exexpr.adb:309:4: note: type 
‘character’ should match type ‘const int’
  309 |Unhandled_Others_Value : constant Character := 'U';
  |

[PATCH] Add Optimization for various IPA parameters.

2020-01-03 Thread Martin Liška

Hi.

This is similar transformation for IPA passes. This time,
one needs to use opt_for_fn in order to get the right
parameter values.

@Martin, Honza:
There are last few remaining parameters which should use
opt_for_fn:

param_ipa_max_agg_items
param_ipa_cp_unit_growth
param_ipa_sra_max_replacements
param_max_speculative_devirt_maydefs

Can you please help me with these as it's in your code?

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

Ready to be installed?
Thanks,
Martin

gcc/ChangeLog:

2020-01-03  Martin Liska  

* auto-profile.c (auto_profile): Use opt_for_fn
for a parameter.
* ipa-cp.c (ipcp_lattice::add_value): Likewise.
(propagate_vals_across_arith_jfunc): Likewise.
(hint_time_bonus): Likewise.
(incorporate_penalties): Likewise.
(good_cloning_opportunity_p): Likewise.
(perform_estimation_of_a_value): Likewise.
(estimate_local_effects): Likewise.
(ipcp_propagate_stage): Likewise.
* ipa-fnsummary.c (decompose_param_expr): Likewise.
(set_switch_stmt_execution_predicate): Likewise.
(analyze_function_body): Likewise.
* ipa-inline-analysis.c (offline_size): Likewise.
* ipa-inline.c (early_inliner): Likewise.
* ipa-prop.c (ipa_analyze_node): Likewise.
(ipcp_transform_function): Likewise.
* ipa-sra.c (process_scan_results): Likewise.
(ipa_sra_summarize_function): Likewise.
* params.opt: Rename ipcp-unit-growth to
ipa-cp-unit-growth.  Add Optimization for various
IPA-related parameters.
---
 gcc/auto-profile.c|  3 ++-
 gcc/ipa-cp.c  | 44 +++
 gcc/ipa-fnsummary.c   |  7 ---
 gcc/ipa-inline-analysis.c |  7 ---
 gcc/ipa-inline.c  |  6 --
 gcc/ipa-prop.c|  4 ++--
 gcc/ipa-sra.c |  6 --
 gcc/params.opt| 34 +++---
 8 files changed, 63 insertions(+), 48 deletions(-)


diff --git a/gcc/auto-profile.c b/gcc/auto-profile.c
index 6aca2f29022..c5e9f1336a7 100644
--- a/gcc/auto-profile.c
+++ b/gcc/auto-profile.c
@@ -1628,7 +1628,8 @@ auto_profile (void)
function before annotation, so the profile inside bar@loc_foo2
will be useful.  */
 autofdo::stmt_set promoted_stmts;
-for (int i = 0; i < param_early_inliner_max_iterations; i++)
+for (int i = 0; i < opt_for_fn (node->decl,
+param_early_inliner_max_iterations); i++)
   {
 if (!flag_value_profile_transformations
 || !autofdo::afdo_vpt_for_early_inline (_stmts))
diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c
index 43c0d5a6706..def89471abb 100644
--- a/gcc/ipa-cp.c
+++ b/gcc/ipa-cp.c
@@ -1859,7 +1859,8 @@ ipcp_lattice::add_value (valtype newval, cgraph_edge *cs,
 	return false;
   }
 
-  if (!unlimited && values_count == param_ipa_cp_value_list_size)
+  if (!unlimited && values_count == opt_for_fn (cs->caller->decl,
+		param_ipa_cp_value_list_size))
 {
   /* We can only free sources, not the values themselves, because sources
 	 of other values in this SCC might point to them.   */
@@ -1986,12 +1987,15 @@ propagate_vals_across_arith_jfunc (cgraph_edge *cs,
 {
   int i;
 
-  if (src_lat != dest_lat || param_ipa_cp_max_recursive_depth < 1)
+  int max_recursive_depth = opt_for_fn(cs->caller->decl,
+	   param_ipa_cp_max_recursive_depth);
+  if (src_lat != dest_lat || max_recursive_depth < 1)
 	return dest_lat->set_contains_variable ();
 
   /* No benefit if recursive execution is in low probability.  */
   if (cs->sreal_frequency () * 100
-	  <= ((sreal) 1) * param_ipa_cp_min_recursive_probability)
+	  <= ((sreal) 1) * opt_for_fn (cs->caller->decl,
+   param_ipa_cp_min_recursive_probability))
 	return dest_lat->set_contains_variable ();
 
   auto_vec *, 8> val_seeds;
@@ -2019,7 +2023,7 @@ propagate_vals_across_arith_jfunc (cgraph_edge *cs,
   /* Recursively generate lattice values with a limited count.  */
   FOR_EACH_VEC_ELT (val_seeds, i, src_val)
 	{
-	  for (int j = 1; j < param_ipa_cp_max_recursive_depth; j++)
+	  for (int j = 1; j < max_recursive_depth; j++)
 	{
 	  tree cstval = get_val_across_arith_op (opcode, opnd1_type, opnd2,
 		 src_val, res_type);
@@ -3155,11 +3159,11 @@ devirtualization_time_bonus (struct cgraph_node *node,
 /* Return time bonus incurred because of HINTS.  */
 
 static int
-hint_time_bonus (ipa_hints hints)
+hint_time_bonus (cgraph_node *node, ipa_hints hints)
 {
   int result = 0;
   if (hints & (INLINE_HINT_loop_iterations | INLINE_HINT_loop_stride))
-result += param_ipa_cp_loop_hint_bonus;
+result += opt_for_fn (node->decl, param_ipa_cp_loop_hint_bonus);
   return result;
 }
 
@@ -3167,15 +3171,18 @@ hint_time_bonus (ipa_hints hints)
cloning goodness evaluation, do so.  */
 
 static inline int64_t
-incorporate_penalties (ipa_node_params *info, int64_t 

[PATCH] Add Optimization keyword for TREE/RTL optimization passes.

2020-01-03 Thread Martin Liška

Hello.

The patch introduces Optimization keyword for various
parameters that influence an optimization that operates
on function level (TREE/RTL). I manually grepped for
each occurrence and verified that it's really used
within a function context.

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

Ready to be installed?
Thanks,
Martin

gcc/ChangeLog:

2020-01-03  Martin Liska  

* params.opt: Add Optimization for various parameters.
---
 gcc/params.opt | 336 -
 1 file changed, 168 insertions(+), 168 deletions(-)


diff --git a/gcc/params.opt b/gcc/params.opt
index c58a375e4c8..5d39244761a 100644
--- a/gcc/params.opt
+++ b/gcc/params.opt
@@ -23,11 +23,11 @@
 ; Please try to keep this file in ASCII collating order.
 
 -param=align-loop-iterations=
-Common Joined UInteger Var(param_align_loop_iterations) Init(4) Param
+Common Joined UInteger Var(param_align_loop_iterations) Init(4) Param Optimization
 Loops iterating at least selected number of iterations will get loop alignment.
 
 -param=align-threshold=
-Common Joined UInteger Var(param_align_threshold) Init(100) IntegerRange(1, 65536) Param
+Common Joined UInteger Var(param_align_threshold) Init(100) IntegerRange(1, 65536) Param Optimization
 Select fraction of the maximal frequency of executions of basic block in function given basic block get alignment.
 
 -param=asan-globals=
@@ -35,51 +35,51 @@ Common Joined UInteger Var(param_asan_globals) Init(1) IntegerRange(0, 1) Param
 Enable asan globals protection.
 
 -param=asan-instrument-allocas=
-Common Joined UInteger Var(param_asan_protect_allocas) Init(1) IntegerRange(0, 1) Param
+Common Joined UInteger Var(param_asan_protect_allocas) Init(1) IntegerRange(0, 1) Param Optimization
 Enable asan allocas/VLAs protection.
 
 -param=asan-instrument-reads=
-Common Joined UInteger Var(param_asan_instrument_reads) Init(1) IntegerRange(0, 1) Param
+Common Joined UInteger Var(param_asan_instrument_reads) Init(1) IntegerRange(0, 1) Param Optimization
 Enable asan load operations protection.
 
 -param=asan-instrument-writes=
-Common Joined UInteger Var(param_asan_instrument_writes) Init(1) IntegerRange(0, 1) Param
+Common Joined UInteger Var(param_asan_instrument_writes) Init(1) IntegerRange(0, 1) Param Optimization
 Enable asan store operations protection.
 
 -param=asan-instrumentation-with-call-threshold=
-Common Joined UInteger Var(param_asan_instrumentation_with_call_threshold) Init(7000) Param
+Common Joined UInteger Var(param_asan_instrumentation_with_call_threshold) Init(7000) Param Optimization
 Use callbacks instead of inline code if number of accesses in function becomes greater or equal to this number.
 
 -param=asan-memintrin=
-Common Joined UInteger Var(param_asan_memintrin) Init(1) IntegerRange(0, 1) Param
+Common Joined UInteger Var(param_asan_memintrin) Init(1) IntegerRange(0, 1) Param Optimization
 Enable asan builtin functions protection.
 
 -param=asan-stack=
-Common Joined UInteger Var(param_asan_stack) Init(1) IntegerRange(0, 1) Param
+Common Joined UInteger Var(param_asan_stack) Init(1) IntegerRange(0, 1) Param Optimization
 Enable asan stack protection.
 
 -param=asan-use-after-return=
-Common Joined UInteger Var(param_asan_use_after_return) Init(1) IntegerRange(0, 1) Param
+Common Joined UInteger Var(param_asan_use_after_return) Init(1) IntegerRange(0, 1) Param Optimization
 Enable asan detection of use-after-return bugs.
 
 -param=avg-loop-niter=
-Common Joined UInteger Var(param_avg_loop_niter) Init(10) IntegerRange(1, 65536) Param
+Common Joined UInteger Var(param_avg_loop_niter) Init(10) IntegerRange(1, 65536) Param Optimization
 Average number of iterations of a loop.
 
 -param=avoid-fma-max-bits=
-Common Joined UInteger Var(param_avoid_fma_max_bits) IntegerRange(0, 512) Param
+Common Joined UInteger Var(param_avoid_fma_max_bits) IntegerRange(0, 512) Param Optimization
 Maximum number of bits for which we avoid creating FMAs.
 
 -param=builtin-expect-probability=
-Common Joined UInteger Var(param_builtin_expect_probability) Init(90) IntegerRange(0, 100) Param
+Common Joined UInteger Var(param_builtin_expect_probability) Init(90) IntegerRange(0, 100) Param Optimization
 Set the estimated probability in percentage for builtin expect. The default value is 90% probability.
 
 -param=builtin-string-cmp-inline-length=
-Common Joined UInteger Var(param_builtin_string_cmp_inline_length) Init(3) IntegerRange(0, 100) Param
+Common Joined UInteger Var(param_builtin_string_cmp_inline_length) Init(3) IntegerRange(0, 100) Param Optimization
 The maximum length of a constant string for a builtin string cmp call eligible for inlining. The default value is 3.
 
 -param=case-values-threshold=
-Common Joined UInteger Var(param_case_values_threshold) Param
+Common Joined UInteger Var(param_case_values_threshold) Param Optimization
 The smallest number of different values for which it is best to use a jump-table instead of a 

Re: [ PATCH ] [ C++ ] [ libstdc++ ] P0674r1 - Extend support for arrays in make/allocate_shared

2020-01-03 Thread Jonathan Wakely

On 02/01/20 17:16 -0500, JeanHeyd Meneide wrote:

This implementation does not update the internal
__allocate_shared and __make_shared functions (I don't know why there
seems to be a duplicate front-end for those functions: it seems a
little weird to use both? Maybe it's for legacy reasons, albeit if
that is the case then I don't need to update the internal versions and
people should move to the non-internal version, yes?).


Those functions return a __shared_ptr not a shared_ptr.

It's OK to not update them, if anybody is using them they can submit
patches to add array support themselves.



Re: [PATCH] libstdc++: Define std::lexicographical_compare_three_way for C++20

2020-01-03 Thread Jonathan Wakely

On 03/01/20 14:54 +, Jonathan Wakely wrote:

On 29/12/19 12:07 +0100, Stephan Bergmann wrote:
FYI, the above fails with -std=c++2a and recent Clang trunk after  
"Mark the major papers for C++20 consistent comparisons as 'done', 
and start publishing the corresponding feature-test macro":  Clang 
now defines __cpp_impl_three_way_comparison (so 
libstdc++-v3/include/std/version defines 
__cpp_lib_three_way_comparison) but still doesn't define 
__cpp_lib_concepts, so libstdc++-v3/libsupc++/compare doesn't define 
compare_three_way.


I locally managed that for now with extending the surrounding

#if __cpp_lib_three_way_comparison

with

&& __cpp_lib_concepts


+}
+#endif // three_way_comparison


Should be fixed at r279861 on trunk (also attached). This leaves the
five-argument overload defined for Clang, just not the four-argument
one that uses std::compare_three_way.

We could define that overload unconditionally and do something like
this, but I prefer to just omit it rather than define it badly:

 return std::lexicographical_compare_three_way(__first1, __last1,
__first2, __last2,
#if __cpp_lib_concepts
compare_three_way{}
#else
[](auto&& __l, auto&& __r)
{ return __l <=> __r; }
#endif // concepts
);


After writing that, I realised that a better approach might be:

--- a/libstdc++-v3/libsupc++/compare
+++ b/libstdc++-v3/libsupc++/compare
@@ -40,7 +40,9 @@

 namespace std
 {
-#define __cpp_lib_three_way_comparison 201711L
+#if __cpp_lib_concepts
+# define __cpp_lib_three_way_comparison 201711L
+#endif

   // [cmp.categories], comparison category types


i.e. don't pretend the library supports three-way comparison if that
support is incomplete. That will still fix the Clang problem because
if that macro isn't defined then we don't define either overload of
std::lexicographical_compare_three_way.

That seems cleaner to me. Anybody disagree?



Re: [PATCH] libstdc++: Define std::lexicographical_compare_three_way for C++20

2020-01-03 Thread Jonathan Wakely

On 29/12/19 12:07 +0100, Stephan Bergmann wrote:

On 05/12/2019 13:46, Jonathan Wakely wrote:

commit 5012548fd62526fdf5e04aeacee2b127efbac0e0
Author: Jonathan Wakely 
Date:   Thu Dec 5 12:23:53 2019 +

   libstdc++: Define std::lexicographical_compare_three_way for C++20
   * include/bits/stl_algobase.h (lexicographical_compare_three_way):
   Define for C++20.
   * testsuite/25_algorithms/lexicographical_compare_three_way/1.cc: New
   test.
   * testsuite/25_algorithms/lexicographical_compare_three_way/
   constexpr.cc: New test.

diff --git a/libstdc++-v3/include/bits/stl_algobase.h 
b/libstdc++-v3/include/bits/stl_algobase.h
index 98d324827ed..a2fd306e6d0 100644
--- a/libstdc++-v3/include/bits/stl_algobase.h
+++ b/libstdc++-v3/include/bits/stl_algobase.h

[...]

@@ -1456,6 +1459,104 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
 __gnu_cxx::__ops::__iter_comp_iter(__comp));
}
+#if __cpp_lib_three_way_comparison
+#if __cpp_lib_concepts
+  // Iter points to a contiguous range of unsigned narrow character type
+  // or std::byte, suitable for comparison by memcmp.
+  template
+concept __is_byte_iter = contiguous_iterator<_Iter>
+  && __is_byte>::__value != 0
+  && !__gnu_cxx::__numeric_traits>::__is_signed;
+
+  // Return a struct with two members, initialized to the smaller of x and y
+  // (or x if they compare equal) and the result of the comparison x <=> y.
+  template
+constexpr auto
+__min_cmp(_Tp __x, _Tp __y)
+{
+  struct _Res {
+   _Tp _M_min;
+   decltype(__x <=> __y) _M_cmp;
+  };
+  auto __c = __x <=> __y;
+  if (__c > 0)
+   return _Res{__y, __c};
+  return _Res{__x, __c};
+}
+#endif

[...]

+
+  template
+constexpr auto
+lexicographical_compare_three_way(_InputIter1 __first1,
+ _InputIter1 __last1,
+ _InputIter2 __first2,
+ _InputIter2 __last2)
+{
+  return std::lexicographical_compare_three_way(__first1, __last1,
+   __first2, __last2,
+   compare_three_way{});


FYI, the above fails with -std=c++2a and recent Clang trunk after  
"Mark the major papers for C++20 consistent comparisons as 'done', and 
start publishing the corresponding feature-test macro":  Clang now 
defines __cpp_impl_three_way_comparison (so 
libstdc++-v3/include/std/version defines 
__cpp_lib_three_way_comparison) but still doesn't define 
__cpp_lib_concepts, so libstdc++-v3/libsupc++/compare doesn't define 
compare_three_way.


I locally managed that for now with extending the surrounding

#if __cpp_lib_three_way_comparison

with

&& __cpp_lib_concepts


+}
+#endif // three_way_comparison


Should be fixed at r279861 on trunk (also attached). This leaves the
five-argument overload defined for Clang, just not the four-argument
one that uses std::compare_three_way.

We could define that overload unconditionally and do something like
this, but I prefer to just omit it rather than define it badly:

  return std::lexicographical_compare_three_way(__first1, __last1,
__first2, __last2,
#if __cpp_lib_concepts
compare_three_way{}
#else
[](auto&& __l, auto&& __r)
{ return __l <=> __r; }
#endif // concepts
);


commit 9b51d80f860841ea80be6c420970ec8b881c0f9e
Author: redi 
Date:   Fri Jan 3 14:44:39 2020 +

libstdc++: Only use std::compare_three_way when concepts are supported

Clang now supports three-way comparisons. That causes both overloads of
std::lexicographical_compare_three_way to be defined, but the second one
uses std::compare_three_way which depends on concepts. Clang does not
yet support concepts, so the second overload should also depend on
__cpp_lib_concepts.

* include/bits/stl_algobase.h (lexicographical_compare_three_way):
Only define four-argument overload when __cpp_lib_concepts is defined.

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

diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h
index 13de6aecc6c..76c323ab21b 100644
--- a/libstdc++-v3/include/bits/stl_algobase.h
+++ b/libstdc++-v3/include/bits/stl_algobase.h
@@ -1751,6 +1751,7 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
 	: __first2 != __last2 ? strong_ordering::less : strong_ordering::equal;
 }
 
+#if __cpp_lib_concepts
   template
 constexpr auto
 lexicographical_compare_three_way(_InputIter1 __first1,
@@ -1762,6 +1763,7 

[PATCH] Avoid segfault when dumping IPA-CP lattices for unoptimized functions (PR 92917)

2020-01-03 Thread Martin Jambor
Hi,

PR 92917 found yet another place - dumping - where we can no longer rely
on the fact that each function with gimple body has its ipa_node_params
summary because un-optimized ones don't.  Fixed with the following
obvious patch that has passed a bootstrap and testing on an x86_64 and
which I am going to commit now.

Thanks,

Martin


2020-01-02  Martin Jambor  

PR ipa/92917
* ipa-cp.c (print_all_lattices): Skip functions without info.
---
 gcc/ipa-cp.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c
index 43c0d5a6706..4381b35a809 100644
--- a/gcc/ipa-cp.c
+++ b/gcc/ipa-cp.c
@@ -543,8 +543,9 @@ print_all_lattices (FILE * f, bool dump_sources, bool 
dump_benefits)
   class ipa_node_params *info;
 
   info = IPA_NODE_REF (node);
-  /* Skip constprop clones since we don't make lattices for them.  */
-  if (info->ipcp_orig_node)
+  /* Skip unoptimized functions and constprop clones since we don't make
+lattices for them.  */
+  if (!info || info->ipcp_orig_node)
continue;
   fprintf (f, "  Node: %s:\n", node->dump_name ());
   count = ipa_get_param_count (info);
-- 
2.24.0



[PATCH] Mark param_max_fields_for_field_sensitive with Optimization keyword.

2020-01-03 Thread Martin Liška

Hi.

One another fix where -Ox sets a parameter that
is not marked with Optimize keyword. Fixed by
adding the keyword.

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

Ready to be installed?
Thanks,
Martin

gcc/ChangeLog:

2020-01-03  Martin Liska  

PR tree-optimization/92860
* params.opt: (param_max_fields_for_field_sensitive):
Mark with Optimization keyword.
* tree-ssa-structalias.c (use_field_sensitive): Make
it a function.
(get_constraint_for_ptr_offset): Call it.
(create_variable_info_for_1): Likewise.
(init_alias_vars): Do not initialize use_field_sensitive.
---
 gcc/params.opt |  2 +-
 gcc/tree-ssa-structalias.c | 15 ++-
 2 files changed, 11 insertions(+), 6 deletions(-)


diff --git a/gcc/params.opt b/gcc/params.opt
index c58a375e4c8..9c5f98f3a00 100644
--- a/gcc/params.opt
+++ b/gcc/params.opt
@@ -427,7 +427,7 @@ Common Joined UInteger Var(param_early_inliner_max_iterations) Init(1) Param
 The maximum number of nested indirect inlining performed by early inliner.
 
 -param=max-fields-for-field-sensitive=
-Common Joined UInteger Var(param_max_fields_for_field_sensitive) Param
+Common Joined UInteger Var(param_max_fields_for_field_sensitive) Param Optimization
 Maximum number of fields in a structure before pointer analysis treats the structure as a single variable.
 
 -param=max-fsm-thread-length=
diff --git a/gcc/tree-ssa-structalias.c b/gcc/tree-ssa-structalias.c
index 22e90f1..2617109c1da 100644
--- a/gcc/tree-ssa-structalias.c
+++ b/gcc/tree-ssa-structalias.c
@@ -197,7 +197,6 @@
 
And probably more.  */
 
-static bool use_field_sensitive = true;
 static int in_ipa_mode = 0;
 
 /* Used for predecessor bitmaps. */
@@ -337,6 +336,14 @@ struct obstack final_solutions_obstack;
Indexed directly by variable info id.  */
 static vec varmap;
 
+/* Return true if the algorithm should be field sensitive.  */
+
+static bool
+use_field_sensitive ()
+{
+  return param_max_fields_for_field_sensitive > 1;
+}
+
 /* Return the varmap element N */
 
 static inline varinfo_t
@@ -3134,7 +3141,7 @@ get_constraint_for_ptr_offset (tree ptr, tree offset,
 
   /* If we do not do field-sensitive PTA adding offsets to pointers
  does not change the points-to solution.  */
-  if (!use_field_sensitive)
+  if (!use_field_sensitive ())
 {
   get_constraint_for_rhs (ptr, results);
   return;
@@ -6075,7 +6082,7 @@ create_variable_info_for_1 (tree decl, const char *name, bool add_id,
 }
 
   /* Collect field information.  */
-  if (use_field_sensitive
+  if (use_field_sensitive ()
   && var_can_have_subvars (decl)
   /* ???  Force us to not use subfields for globals in IPA mode.
 	 Else we'd have to parse arbitrary initializers.  */
@@ -7182,8 +7189,6 @@ init_base_vars (void)
 static void
 init_alias_vars (void)
 {
-  use_field_sensitive = (param_max_fields_for_field_sensitive > 1);
-
   bitmap_obstack_initialize (_obstack);
   bitmap_obstack_initialize (_obstack);
   bitmap_obstack_initialize (_obstack);



Re: [PATCH 07/13] OpenACC 2.6 deep copy: libgomp parts

2020-01-03 Thread Julian Brown
Hi,

On Sun, 22 Dec 2019 00:01:10 +0100
Thomas Schwinge  wrote:

> I had intentionally left out this assignment in my "In
> 'libgomp/target.c', 'struct splay_tree_key_s', use 'struct
> splay_tree_aux' for infrequently-used or API-specific data" patch,
> <87k16uykb7.fsf@euler.schwinge.homeip.net">http://mid.mail-archive.com/87k16uykb7.fsf@euler.schwinge.homeip.net>,
> and you also don't have that assignment in your r279620 "Use aux
> struct in libgomp for infrequently-used/API-specific data" commit,
> <80e0dba326a4414fd2dbe8401dbd8d8f08445129.1576648001.git.julian@codesourcery.com">http://mid.mail-archive.com/80e0dba326a4414fd2dbe8401dbd8d8f08445129.1576648001.git.julian@codesourcery.com>,
> so curious why it now appears here -- hopefully just an oversight.

This was just an oversight (or a mismerge, perhaps). Thanks for fixing!

Cheers,

Julian


Re: [PING^4][PATCH 0/4] Fix library testsuite compilation for build sysroot

2020-01-03 Thread Julian Brown
Hi Maciej,

On Sun, 22 Dec 2019 00:43:54 + (GMT)
"Maciej W. Rozycki"  wrote:

> On Fri, 20 Dec 2019, Mike Stump wrote:
> 
> > >> This patch series addresses a problem with the testsuite
> > >> compiler being set up across libatomic, libffi, libgo, libgomp
> > >> with no correlation whatsoever to the target compiler being used
> > >> in GCC compilation. Consequently there in no arrangement made to
> > >> set up the compilation sysroot according to the build sysroot
> > >> specified for GCC compilation, causing a catastrophic failure
> > >> across the testsuites affected from the inability to link
> > >> executables.  
> > > 
> > > Ping for:
> > > 
> > > 
> > > 
> > >   
> > 
> > Hum...  I'm wondering who should review this...  Feels like I
> > should, the problem is it intertwines with the build system as
> > well.  So, let me approve the testsuite parts so that can clear the
> > way for someone else to approve the remaining bits (if not
> > obvious).  
> 
>  Thanks for your review; I have applied 4/4 as it doesn't contain any 
> non-testsuite parts and will continue pinging 1/4 and 2/4 for the
> build system bits then (3/4 has been already committed by the Go
> maintainer).
> 
> > Please do watch out for breakages as it goes in.  Thanks.  
> 
>  Sure!

FYI: This patch seems to be causing problems for our (internal -- as
you know!) test harness. I'm not sure if it's a local issue (or at least
something we can work around here), or a problem with the patch itself
though.

I'm currently working on offloading-enabled compilers. I see the same
failure mode for both AMD GCN and NVPTX.

Without the patch, the compiler is found (with [find_gcc] I suppose) and
invoked as x86_64-none-linux-gnu-gcc. That works fine for us, but we do
(I think) "installed testing", which IIUC is atypical.

With the patch, the compiler is invoked as (at the risk of excessive
detail) e.g.:

/scratch/jbrown/nvptx-mainline/obj/gcc-2018.11-99-x86_64-none-linux-gnu-x86_64-linux-gnu/./gcc/xgcc
 
-B/scratch/jbrown/nvptx-mainline/obj/gcc-2018.11-99-x86_64-none-linux-gnu-x86_64-linux-gnu/./gcc/
 
-B/scratch/jbrown/nvptx-mainline/install/opt/codesourcery/x86_64-none-linux-gnu/bin/
 
-B/scratch/jbrown/nvptx-mainline/install/opt/codesourcery/x86_64-none-linux-gnu/lib/
 -isystem 
/scratch/jbrown/nvptx-mainline/install/opt/codesourcery/x86_64-none-linux-gnu/include
 -isystem 
/scratch/jbrown/nvptx-mainline/install/opt/codesourcery/x86_64-none-linux-gnu/sys-include
 
--sysroot=/scratch/jbrown/nvptx-mainline/install/opt/codesourcery/x86_64-none-linux-gnu/libc
 [...]

...and then it fails to find libgomp.spec:

xgcc: fatal error: cannot read spec file 'libgomp.spec': No such file or 
directory

Can your approach be made to work with an offload-enabled compiler? How
should that spec file (and/or the target compiler) be located?

Thanks,

Julian


Re: [Patch, Fortran] OpenMP/OpenACC – fix more issues with OPTIONAL

2020-01-03 Thread Jakub Jelinek
On Tue, Dec 10, 2019 at 06:54:19PM +0100, Tobias Burnus wrote:
> 2019-12-10  Tobias Burnus  
> 
>   gcc/fortran/
>   * trans-openmp.c (gfc_omp_check_optional_argument): Always return a
>   Boolean expression; handle unallocated/disassociated actual arguments
>   as absent if passed to nonallocatable/nonpointer dummy array arguments.
>   (gfc_build_cond_assign): Change to assume a Boolean expr not a pointer.
>   (gfc_omp_finish_clause, gfc_trans_omp_clauses): Assign NULL to generated
>   array-data variable if the argument is absent. Simplify code as
>   'present' is now a Boolean expression.
> 
>   libgomp/
>   * testsuite/libgomp.fortran/optional-map.f90: Add test for
>   unallocated/disassociated actual arguments to nonallocatable/nonpointer
>   dummy arguments; those are/shall be regarded as absent arguments.
>   * testsuite/libgomp.fortran/use_device_ptr-optional-2.f90: Ditto.
>   * testsuite/libgomp.fortran/use_device_ptr-optional-3.f90: New.

Ok.  Sorry for the delay.

Jakub



[PATCH] Do not set -fomit-frame-pointer if TARGET_OMIT_LEAF_FRAME_POINTER_P.

2020-01-03 Thread Martin Liška

Hi.

I'm not fully sure about the change, but -momit-leaf-frame-pointer
probably should not globally omit frame pointers?

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

Ready to be installed?
Thanks,
Martin

gcc/ChangeLog:

2020-01-03  Martin Liska  

PR tree-optimization/92860
* config/i386/i386-options.c (ix86_option_override_internal):
Do not enable -fomit-frame-pointer with -momit-leaf-frame-pointer
as it will globally omit pointers (like in ira.c).
---
 gcc/config/i386/i386-options.c | 2 --
 1 file changed, 2 deletions(-)


diff --git a/gcc/config/i386/i386-options.c b/gcc/config/i386/i386-options.c
index 2acc9fb0cfe..48113738b92 100644
--- a/gcc/config/i386/i386-options.c
+++ b/gcc/config/i386/i386-options.c
@@ -2437,8 +2437,6 @@ ix86_option_override_internal (bool main_args_p,
   /* Keep nonleaf frame pointers.  */
   if (opts->x_flag_omit_frame_pointer)
 opts->x_target_flags &= ~MASK_OMIT_LEAF_FRAME_POINTER;
-  else if (TARGET_OMIT_LEAF_FRAME_POINTER_P (opts->x_target_flags))
-opts->x_flag_omit_frame_pointer = 1;
 
   /* If we're doing fast math, we don't care about comparison order
  wrt NaNs.  This lets us use a shorter comparison sequence.  */



Re: [PATCH] Allow prefer-vector-width= in target attribute (PR target/93089)

2020-01-03 Thread Uros Bizjak
On Fri, Jan 3, 2020 at 9:31 AM Jakub Jelinek  wrote:
>
> Hi!
>
> For a patch I'm going to post next I need to be able to tweak
> prefer_vector_width= for simd clones (the thing is, in the declare simd
> clones it makes no sense to restrict to a subset of vector sizes the
> selected ISA is capable of handling, the choice what vectorization factor
> and ABI for it is done during vectorization of the caller, the simd clones
> already get their arguments in xmm or ymm or zmm registers and it makes e.g.
> no sense for the zmm variant to extract from the zmm registers, perform
> all computations in xmm only and finally store into zmm again).
> For that prefer-vector-width= really needs to be something that can be
> specified in target attribute that simd clones use; I think it can be useful
> for other use cases too, to override this tuning, some function might target
> a different CPU than the rest of the code.

Yes, I agree with the above.

> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>
> 2020-01-03  Jakub Jelinek  
>
> PR target/93089
> * config/i386/i386.opt (x_prefer_vector_width_type): Remove TargetSave
> entry.
> (mprefer-vector-width=): Add Save.
> * config/i386/i386-options.c (ix86_target_string): Add PVW argument, 
> print
> -mprefer-vector-width= if non-zero.  Fix up -mfpmath= comment.
> (ix86_debug_options, ix86_function_specific_print): Adjust
> ix86_target_string callers.
> (ix86_valid_target_attribute_inner_p): Handle prefer-vector-width=.
> (ix86_valid_target_attribute_tree): Likewise.
> * config/i386/i386-options.h (ix86_target_string): Add PVW argument.
> * config/i386/i386-expand.c (ix86_expand_builtin): Adjust
> ix86_target_string caller.
>
> * gcc.target/i386/pr93089-1.c: New test.

LGTM.

Thanks,
Uros.

> --- gcc/config/i386/i386.opt.jj 2020-01-01 12:16:10.228273887 +0100
> +++ gcc/config/i386/i386.opt2020-01-02 14:34:47.497328338 +0100
> @@ -182,10 +182,6 @@ int x_ix86_tune_no_default
>  TargetSave
>  enum ix86_veclibabi x_ix86_veclibabi_type
>
> -;; -mprefer-vector-width=
> -TargetSave
> -enum prefer_vector_width x_prefer_vector_width_type
> -
>  ;; x86 options
>  m128bit-long-double
>  Target RejectNegative Report Mask(128BIT_LONG_DOUBLE) Save
> @@ -595,7 +591,7 @@ Target Alias(mprefer-vector-width=, 128,
>  Use 128-bit AVX instructions instead of 256-bit AVX instructions in the 
> auto-vectorizer.
>
>  mprefer-vector-width=
> -Target Report RejectNegative Joined Var(prefer_vector_width_type) 
> Enum(prefer_vector_width) Init(PVW_NONE)
> +Target Report RejectNegative Joined Var(prefer_vector_width_type) 
> Enum(prefer_vector_width) Init(PVW_NONE) Save
>  Use given register vector width instructions instead of maximum register 
> width in the auto-vectorizer.
>
>  Enum
> --- gcc/config/i386/i386-options.c.jj   2020-01-01 12:16:13.329227004 +0100
> +++ gcc/config/i386/i386-options.c  2020-01-02 14:00:40.299515822 +0100
> @@ -339,7 +339,9 @@ char *
>  ix86_target_string (HOST_WIDE_INT isa, HOST_WIDE_INT isa2,
> int flags, int flags2,
> const char *arch, const char *tune,
> -   enum fpmath_unit fpmath, bool add_nl_p, bool add_abi_p)
> +   enum fpmath_unit fpmath,
> +   enum prefer_vector_width pvw,
> +   bool add_nl_p, bool add_abi_p)
>  {
>/* Flag options.  */
>static struct ix86_target_opts flag_opts[] =
> @@ -493,7 +495,7 @@ ix86_target_string (HOST_WIDE_INT isa, H
>sprintf (flags2_other, "(other flags2: %#x)", flags2);
>  }
>
> -  /* Add -fpmath= option.  */
> +  /* Add -mfpmath= option.  */
>if (fpmath)
>  {
>opts[num][0] = "-mfpmath=";
> @@ -516,6 +518,29 @@ ix86_target_string (HOST_WIDE_INT isa, H
> }
>  }
>
> +  /* Add -mprefer-vector-width= option.  */
> +  if (pvw)
> +{
> +  opts[num][0] = "-mprefer-vector-width=";
> +  switch ((int) pvw)
> +   {
> +   case PVW_AVX128:
> + opts[num++][1] = "128";
> + break;
> +
> +   case PVW_AVX256:
> + opts[num++][1] = "256";
> + break;
> +
> +   case PVW_AVX512:
> + opts[num++][1] = "512";
> + break;
> +
> +   default:
> + gcc_unreachable ();
> +   }
> +}
> +
>/* Any options?  */
>if (num == 0)
>  return NULL;
> @@ -579,8 +604,9 @@ ix86_debug_options (void)
>  {
>char *opts = ix86_target_string (ix86_isa_flags, ix86_isa_flags2,
>target_flags, ix86_target_flags,
> -  ix86_arch_string,ix86_tune_string,
> -  ix86_fpmath, true, true);
> +  ix86_arch_string, ix86_tune_string,
> +  ix86_fpmath, prefer_vector_width_type,
> +  true, true);
>
>if (opts)
> 

Re: [PATCH] Fix x86 abs2 expander for ia32 (PR target/93110)

2020-01-03 Thread Uros Bizjak
On Fri, Jan 3, 2020 at 9:23 AM Jakub Jelinek  wrote:
>
> Hi!
>
> The newly added absdi2 expander doesn't work well on ia32, because it
> requires a xordi3 pattern, which is available even for !TARGET_64BIT,
> but only if TARGET_STV && TARGET_SSE2.
>
> The following patch just uses expand_simple_binop which is able to handle
> the splitting of it into two xorsi3 patterns if needed etc., plus is shorter
> in the expander.  Also, there is no need to build a DImode shift amount and
> then convert_modes it.
>
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, on the
> testcase we now get identical code to what GCC 9 emitted in all of -m32
> -mno-stv -mno-sse, -m32 -msse2 -mstv and -m64 modes, ok for trunk?
>
> 2020-01-03  Jakub Jelinek  
>
> PR target/93110
> * config/i386/i386.md (abs2): Use expand_simple_binop instead of
> emitting ASHIFTRT, XOR and MINUS by hand.  Use gen_int_mode with 
> QImode
> instead of gen_int_shift_amount + convert_modes.
>
> * gcc.dg/torture/pr93110.c: New test.

OK.

Thanks,
Uros.

> --- gcc/config/i386/i386.md.jj  2020-01-01 12:16:10.071276261 +0100
> +++ gcc/config/i386/i386.md 2020-01-02 10:47:26.638399487 +0100
> @@ -9711,30 +9711,16 @@ (define_expand "abs2"
>
>  /* Generate rtx abs using abs (x) = (((signed) x >> (W-1)) ^ x) -
> ((signed) x >> (W-1)) */
> -rtx shift_amount = gen_int_shift_amount (mode,
> -  GET_MODE_PRECISION (mode)
> -  - 1);
> -shift_amount = convert_modes (E_QImode, GET_MODE (shift_amount),
> -   shift_amount, 1);
> -rtx shift_dst = gen_reg_rtx (mode);
> -rtx shift_op = gen_rtx_SET (shift_dst,
> - gen_rtx_fmt_ee (ASHIFTRT, mode,
> - operands[1], shift_amount));
> -rtx clobber = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode,
> -   FLAGS_REG));
> -emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, shift_op,
> -   clobber)));
> -
> -rtx xor_op = gen_rtx_SET (operands[0],
> -   gen_rtx_fmt_ee (XOR, mode, shift_dst,
> -   operands[1]));
> -emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, xor_op, clobber)));
> -
> -rtx minus_op = gen_rtx_SET (operands[0],
> - gen_rtx_fmt_ee (MINUS, mode,
> - operands[0], shift_dst));
> -emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, minus_op,
> -   clobber)));
> +rtx shift_amount = gen_int_mode (GET_MODE_PRECISION (mode) - 1, QImode);
> +rtx shift_dst = expand_simple_binop (mode, ASHIFTRT, operands[1],
> +shift_amount, NULL_RTX,
> +0, OPTAB_DIRECT);
> +rtx xor_dst = expand_simple_binop (mode, XOR, shift_dst, operands[1],
> +  operands[0], 0, OPTAB_DIRECT);
> +rtx minus_dst = expand_simple_binop (mode, MINUS, xor_dst, shift_dst,
> +operands[0], 0, OPTAB_DIRECT);
> +if (!rtx_equal_p (minus_dst, operands[0]))
> +  emit_move_insn (operands[0], minus_dst);
>  DONE;
>})
>
> --- gcc/testsuite/gcc.dg/torture/pr93110.c.jj   2020-01-02 10:50:10.335895988 
> +0100
> +++ gcc/testsuite/gcc.dg/torture/pr93110.c  2020-01-02 10:49:54.248142020 
> +0100
> @@ -0,0 +1,9 @@
> +/* PR target/93110 */
> +/* { dg-do compile } */
> +/* { dg-additional-options "-mtune=core2 -mno-stv" { target { i?86-*-* 
> x86_64-*-* } } } */
> +
> +long long
> +foo (long long a)
> +{
> +  return a > 0 ? a : -a;
> +}
>
> Jakub
>


Re: [PATCH] Fix endless loop in find_single_def_src (PR rtl-optimization/93088)

2020-01-03 Thread Eric Botcazou
> While we could add some hash_table/bitmap or whatever other data structure
> to track registers we've already looked at, having unbounded look through
> register copies looks dangerous to me for compile time complexity in
> pathological cases, and while on certain architectures I could understand
> very deep chains of say reg2 = reg1 + constant; reg3 = reg2 + constant; ...
> (or with post-increment/decrement/modify) if the target addressing mode
> doesn't allow suitable immediates in addresses, having chains of simple
> reg2 = reg1; reg3 = reg2; reg4 = reg3; reg5 = reg4; ...
> chains with thousands copies will unlikely appear and would unlikely result
> in something useful for the loop iv optimization, so this patch instead
> just looks through at most 128 copies (I don't think we need a param for
> that).
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> 
> 2020-01-03  Jakub Jelinek  
> 
>   PR rtl-optimization/93088
>   * loop-iv.c (find_single_def_src): Punt after looking through
>   128 reg copies for regs with single definitions.  Move definitions
>   to first uses.
> 
>   * gcc.target/i386/pr93088.c: New test.

OK with me, thanks.

-- 
Eric Botcazou


[PATCH] Fix endless loop in find_single_def_src (PR rtl-optimization/93088)

2020-01-03 Thread Jakub Jelinek
Hi!

The testcase uses two uninitialized variables in a loop, the iterator
as well as the upper bound in the condition, and due to that and bad luck
we end up with:
(insn 6 70 71 14 (set (reg/v:DI 90 [ pend ])
(reg/v:DI 89 [ p ])) "pr56348.c":29:5 66 {*movdi_internal}
 (nil))
and
(insn 9 88 63 12 (set (reg/v:DI 89 [ p ])
(reg/v:DI 90 [ pend ])) "pr56348.c":28:3 66 {*movdi_internal}
 (nil))
as the only setters of those two pseudos (plus a bunch of uses in loop
conditions).  When loop-iv.c tries to determine loop invariants,
it performs since
https://gcc.gnu.org/ml/gcc-patches/2009-04/msg00246.html
an unbounded search through register copies with single definitions and on
the above loops forever.
While we could add some hash_table/bitmap or whatever other data structure
to track registers we've already looked at, having unbounded look through
register copies looks dangerous to me for compile time complexity in
pathological cases, and while on certain architectures I could understand
very deep chains of say reg2 = reg1 + constant; reg3 = reg2 + constant; ...
(or with post-increment/decrement/modify) if the target addressing mode
doesn't allow suitable immediates in addresses, having chains of simple
reg2 = reg1; reg3 = reg2; reg4 = reg3; reg5 = reg4; ...
chains with thousands copies will unlikely appear and would unlikely result
in something useful for the loop iv optimization, so this patch instead
just looks through at most 128 copies (I don't think we need a param for
that).

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

2020-01-03  Jakub Jelinek  

PR rtl-optimization/93088
* loop-iv.c (find_single_def_src): Punt after looking through
128 reg copies for regs with single definitions.  Move definitions
to first uses.

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

--- gcc/loop-iv.c.jj2020-01-01 12:15:44.596661415 +0100
+++ gcc/loop-iv.c   2020-01-02 18:07:00.238120307 +0100
@@ -1384,24 +1384,23 @@ simple_rhs_p (rtx rhs)
 static rtx
 find_single_def_src (unsigned int regno)
 {
-  df_ref adef;
-  rtx set, src;
+  rtx src = NULL_RTX;
 
-  for (;;)
+  /* Don't look through unbounded number of single definition REG copies,
+ there might be loops for sources with uninitialized variables.  */
+  for (int cnt = 0; cnt < 128; cnt++)
 {
-  rtx note;
-  adef = DF_REG_DEF_CHAIN (regno);
+  df_ref adef = DF_REG_DEF_CHAIN (regno);
   if (adef == NULL || DF_REF_NEXT_REG (adef) != NULL
  || DF_REF_IS_ARTIFICIAL (adef))
return NULL_RTX;
 
-  set = single_set (DF_REF_INSN (adef));
+  rtx set = single_set (DF_REF_INSN (adef));
   if (set == NULL || !REG_P (SET_DEST (set))
  || REGNO (SET_DEST (set)) != regno)
return NULL_RTX;
 
-  note = find_reg_equal_equiv_note (DF_REF_INSN (adef));
-
+  rtx note = find_reg_equal_equiv_note (DF_REF_INSN (adef));
   if (note && function_invariant_p (XEXP (note, 0)))
{
  src = XEXP (note, 0);
--- gcc/testsuite/gcc.target/i386/pr93088.c.jj  2020-01-02 18:25:34.904318975 
+0100
+++ gcc/testsuite/gcc.target/i386/pr93088.c 2020-01-02 18:25:01.944815342 
+0100
@@ -0,0 +1,5 @@
+/* PR rtl-optimization/93088 */
+/* { dg-do compile } */
+/* { dg-options "-O3 -funroll-loops -fno-tree-dominator-opts -fno-tree-vrp -w" 
} */
+
+#include "pr56348.c"

Jakub



[PATCH] Override prefer-vector-width= in x86 simd clones (PR target/93089)

2020-01-03 Thread Jakub Jelinek
Hi!

As mentioned in the previous mail, this is what I intend to commit if/when
the prefer-vector-width= in target attribute patch makes it in.

Bootstrapped/regtested on x86_64-linux and i686-linux.

2020-01-03  Jakub Jelinek  

PR target/93089
* config/i386/i386-options.c (ix86_simd_clone_adjust): If
TARGET_PREFER_AVX128, use prefer-vector-width=256 for 'c' and 'd'
simd clones.  If TARGET_PREFER_AVX256, use prefer-vector-width=512
for 'e' simd clones.

* gcc.target/i386/pr93089-2.c: New test.
* gcc.target/i386/pr93089-3.c: New test.

--- gcc/config/i386/i386-options.c.jj   2020-01-02 14:00:40.299515822 +0100
+++ gcc/config/i386/i386-options.c  2020-01-02 15:13:00.067579822 +0100
@@ -2950,15 +2950,36 @@ ix86_simd_clone_adjust (struct cgraph_no
str = "sse2";
   break;
 case 'c':
-  if (!TARGET_AVX)
+  if (TARGET_PREFER_AVX128)
+   {
+ if (!TARGET_AVX)
+   str = "avx,prefer-vector-width=256";
+ else
+   str = "prefer-vector-width=256";
+   }
+  else if (!TARGET_AVX)
str = "avx";
   break;
 case 'd':
-  if (!TARGET_AVX2)
+  if (TARGET_PREFER_AVX128)
+   {
+ if (!TARGET_AVX2)
+   str = "avx2,prefer-vector-width=256";
+ else
+   str = "prefer-vector-width=256";
+   }
+  else if (!TARGET_AVX2)
str = "avx2";
   break;
 case 'e':
-  if (!TARGET_AVX512F)
+  if (TARGET_PREFER_AVX256)
+   {
+ if (!TARGET_AVX512F)
+   str = "avx512f,prefer-vector-width=512";
+ else
+   str = "prefer-vector-width=512";
+   }
+  else if (!TARGET_AVX512F)
str = "avx512f";
   break;
 default:
--- gcc/testsuite/gcc.target/i386/pr93089-2.c.jj2020-01-02 
15:19:01.345119189 +0100
+++ gcc/testsuite/gcc.target/i386/pr93089-2.c   2020-01-02 15:18:34.767520897 
+0100
@@ -0,0 +1,12 @@
+/* PR target/93089 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fopenmp-simd -mtune=znver1" } */
+/* { dg-final { scan-assembler "vmulps\[^\n\r]*zmm" } } */
+/* { dg-final { scan-assembler "vmulps\[^\n\r]*ymm" } } */
+
+#pragma omp declare simd notinbranch
+float
+foo (float x, float y)
+{
+  return x * y;
+}
--- gcc/testsuite/gcc.target/i386/pr93089-3.c.jj2020-01-02 
15:19:08.460011650 +0100
+++ gcc/testsuite/gcc.target/i386/pr93089-3.c   2020-01-02 15:19:15.734901684 
+0100
@@ -0,0 +1,12 @@
+/* PR target/93089 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fopenmp-simd -mtune=skylake-avx512" } */
+/* { dg-final { scan-assembler "vmulps\[^\n\r]*zmm" } } */
+/* { dg-final { scan-assembler "vmulps\[^\n\r]*ymm" } } */
+
+#pragma omp declare simd notinbranch
+float
+foo (float x, float y)
+{
+  return x * y;
+}

Jakub



[PATCH] Allow prefer-vector-width= in target attribute (PR target/93089)

2020-01-03 Thread Jakub Jelinek
Hi!

For a patch I'm going to post next I need to be able to tweak
prefer_vector_width= for simd clones (the thing is, in the declare simd
clones it makes no sense to restrict to a subset of vector sizes the
selected ISA is capable of handling, the choice what vectorization factor
and ABI for it is done during vectorization of the caller, the simd clones
already get their arguments in xmm or ymm or zmm registers and it makes e.g.
no sense for the zmm variant to extract from the zmm registers, perform
all computations in xmm only and finally store into zmm again).
For that prefer-vector-width= really needs to be something that can be
specified in target attribute that simd clones use; I think it can be useful
for other use cases too, to override this tuning, some function might target
a different CPU than the rest of the code.

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

2020-01-03  Jakub Jelinek  

PR target/93089
* config/i386/i386.opt (x_prefer_vector_width_type): Remove TargetSave
entry.
(mprefer-vector-width=): Add Save.
* config/i386/i386-options.c (ix86_target_string): Add PVW argument, 
print
-mprefer-vector-width= if non-zero.  Fix up -mfpmath= comment.
(ix86_debug_options, ix86_function_specific_print): Adjust
ix86_target_string callers.
(ix86_valid_target_attribute_inner_p): Handle prefer-vector-width=.
(ix86_valid_target_attribute_tree): Likewise.
* config/i386/i386-options.h (ix86_target_string): Add PVW argument.
* config/i386/i386-expand.c (ix86_expand_builtin): Adjust
ix86_target_string caller.

* gcc.target/i386/pr93089-1.c: New test.

--- gcc/config/i386/i386.opt.jj 2020-01-01 12:16:10.228273887 +0100
+++ gcc/config/i386/i386.opt2020-01-02 14:34:47.497328338 +0100
@@ -182,10 +182,6 @@ int x_ix86_tune_no_default
 TargetSave
 enum ix86_veclibabi x_ix86_veclibabi_type
 
-;; -mprefer-vector-width=
-TargetSave
-enum prefer_vector_width x_prefer_vector_width_type
-
 ;; x86 options
 m128bit-long-double
 Target RejectNegative Report Mask(128BIT_LONG_DOUBLE) Save
@@ -595,7 +591,7 @@ Target Alias(mprefer-vector-width=, 128,
 Use 128-bit AVX instructions instead of 256-bit AVX instructions in the 
auto-vectorizer.
 
 mprefer-vector-width=
-Target Report RejectNegative Joined Var(prefer_vector_width_type) 
Enum(prefer_vector_width) Init(PVW_NONE)
+Target Report RejectNegative Joined Var(prefer_vector_width_type) 
Enum(prefer_vector_width) Init(PVW_NONE) Save
 Use given register vector width instructions instead of maximum register width 
in the auto-vectorizer.
 
 Enum
--- gcc/config/i386/i386-options.c.jj   2020-01-01 12:16:13.329227004 +0100
+++ gcc/config/i386/i386-options.c  2020-01-02 14:00:40.299515822 +0100
@@ -339,7 +339,9 @@ char *
 ix86_target_string (HOST_WIDE_INT isa, HOST_WIDE_INT isa2,
int flags, int flags2,
const char *arch, const char *tune,
-   enum fpmath_unit fpmath, bool add_nl_p, bool add_abi_p)
+   enum fpmath_unit fpmath,
+   enum prefer_vector_width pvw,
+   bool add_nl_p, bool add_abi_p)
 {
   /* Flag options.  */
   static struct ix86_target_opts flag_opts[] =
@@ -493,7 +495,7 @@ ix86_target_string (HOST_WIDE_INT isa, H
   sprintf (flags2_other, "(other flags2: %#x)", flags2);
 }
 
-  /* Add -fpmath= option.  */
+  /* Add -mfpmath= option.  */
   if (fpmath)
 {
   opts[num][0] = "-mfpmath=";
@@ -516,6 +518,29 @@ ix86_target_string (HOST_WIDE_INT isa, H
}
 }
 
+  /* Add -mprefer-vector-width= option.  */
+  if (pvw)
+{
+  opts[num][0] = "-mprefer-vector-width=";
+  switch ((int) pvw)
+   {
+   case PVW_AVX128:
+ opts[num++][1] = "128";
+ break;
+
+   case PVW_AVX256:
+ opts[num++][1] = "256";
+ break;
+
+   case PVW_AVX512:
+ opts[num++][1] = "512";
+ break;
+
+   default:
+ gcc_unreachable ();
+   }
+}
+
   /* Any options?  */
   if (num == 0)
 return NULL;
@@ -579,8 +604,9 @@ ix86_debug_options (void)
 {
   char *opts = ix86_target_string (ix86_isa_flags, ix86_isa_flags2,
   target_flags, ix86_target_flags,
-  ix86_arch_string,ix86_tune_string,
-  ix86_fpmath, true, true);
+  ix86_arch_string, ix86_tune_string,
+  ix86_fpmath, prefer_vector_width_type,
+  true, true);
 
   if (opts)
 {
@@ -847,7 +873,8 @@ ix86_function_specific_print (FILE *file
   char *target_string
 = ix86_target_string (ptr->x_ix86_isa_flags, ptr->x_ix86_isa_flags2,
  ptr->x_target_flags, ptr->x_ix86_target_flags,
- NULL, NULL, ptr->x_ix86_fpmath, false, true);
+ 

[PATCH] Fix x86 abs2 expander for ia32 (PR target/93110)

2020-01-03 Thread Jakub Jelinek
Hi!

The newly added absdi2 expander doesn't work well on ia32, because it
requires a xordi3 pattern, which is available even for !TARGET_64BIT,
but only if TARGET_STV && TARGET_SSE2.

The following patch just uses expand_simple_binop which is able to handle
the splitting of it into two xorsi3 patterns if needed etc., plus is shorter
in the expander.  Also, there is no need to build a DImode shift amount and
then convert_modes it.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, on the
testcase we now get identical code to what GCC 9 emitted in all of -m32
-mno-stv -mno-sse, -m32 -msse2 -mstv and -m64 modes, ok for trunk?

2020-01-03  Jakub Jelinek  

PR target/93110
* config/i386/i386.md (abs2): Use expand_simple_binop instead of
emitting ASHIFTRT, XOR and MINUS by hand.  Use gen_int_mode with QImode
instead of gen_int_shift_amount + convert_modes.

* gcc.dg/torture/pr93110.c: New test.

--- gcc/config/i386/i386.md.jj  2020-01-01 12:16:10.071276261 +0100
+++ gcc/config/i386/i386.md 2020-01-02 10:47:26.638399487 +0100
@@ -9711,30 +9711,16 @@ (define_expand "abs2"
 
 /* Generate rtx abs using abs (x) = (((signed) x >> (W-1)) ^ x) -
((signed) x >> (W-1)) */
-rtx shift_amount = gen_int_shift_amount (mode,
-  GET_MODE_PRECISION (mode)
-  - 1);
-shift_amount = convert_modes (E_QImode, GET_MODE (shift_amount),
-   shift_amount, 1);
-rtx shift_dst = gen_reg_rtx (mode);
-rtx shift_op = gen_rtx_SET (shift_dst,
- gen_rtx_fmt_ee (ASHIFTRT, mode,
- operands[1], shift_amount));
-rtx clobber = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode,
-   FLAGS_REG));
-emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, shift_op,
-   clobber)));
-
-rtx xor_op = gen_rtx_SET (operands[0],
-   gen_rtx_fmt_ee (XOR, mode, shift_dst,
-   operands[1]));
-emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, xor_op, clobber)));
-
-rtx minus_op = gen_rtx_SET (operands[0],
- gen_rtx_fmt_ee (MINUS, mode,
- operands[0], shift_dst));
-emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, minus_op,
-   clobber)));
+rtx shift_amount = gen_int_mode (GET_MODE_PRECISION (mode) - 1, QImode);
+rtx shift_dst = expand_simple_binop (mode, ASHIFTRT, operands[1],
+shift_amount, NULL_RTX,
+0, OPTAB_DIRECT);
+rtx xor_dst = expand_simple_binop (mode, XOR, shift_dst, operands[1],
+  operands[0], 0, OPTAB_DIRECT);
+rtx minus_dst = expand_simple_binop (mode, MINUS, xor_dst, shift_dst,
+operands[0], 0, OPTAB_DIRECT);
+if (!rtx_equal_p (minus_dst, operands[0]))
+  emit_move_insn (operands[0], minus_dst);
 DONE;
   })
 
--- gcc/testsuite/gcc.dg/torture/pr93110.c.jj   2020-01-02 10:50:10.335895988 
+0100
+++ gcc/testsuite/gcc.dg/torture/pr93110.c  2020-01-02 10:49:54.248142020 
+0100
@@ -0,0 +1,9 @@
+/* PR target/93110 */
+/* { dg-do compile } */
+/* { dg-additional-options "-mtune=core2 -mno-stv" { target { i?86-*-* 
x86_64-*-* } } } */
+
+long long
+foo (long long a)
+{
+  return a > 0 ? a : -a;
+}

Jakub



[PATCH] Improve (x >> c) << c match.pd optimization (PR tree-optimization/93118)

2020-01-03 Thread Jakub Jelinek
Hi!

As can be seen in the testcase, for the (x >> c) << c optimization into
x & (-1<> 32))<<32
for unsigned long long x - we figure out that after the logical right shift
the upper 32 bits are already zero and optimize away those two casts -
we don't handle that for arithmetic shift or e.g. for
((unsigned long long)(int)(x >> 32))<<32
Still, the upper 32 bits don't really matter on the result and can be
anything.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

2019-01-03  Jakub Jelinek  

PR tree-optimization/93118
* match.pd ((x >> c) << c -> x & (-1<> c) << c into x & (-1<= TYPE_PRECISION (type)
+ || wi::geu_p (wi::to_wide (@1),
+   TYPE_PRECISION (type)
+   - TYPE_PRECISION (TREE_TYPE (@2)
+  (bit_and (convert @0) (lshift { build_minus_one_cst (type); } @1
 
 /* Optimize (x << c) >> c into x & ((unsigned)-1 >> c) for unsigned
types.  */
--- gcc/testsuite/gcc.dg/tree-ssa/pr93118.c.jj  2020-01-02 09:58:21.186274254 
+0100
+++ gcc/testsuite/gcc.dg/tree-ssa/pr93118.c 2020-01-02 09:57:44.959825348 
+0100
@@ -0,0 +1,45 @@
+/* PR tree-optimization/93118 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+/* { dg-final { scan-tree-dump-not ">>" "optimized" } } */
+/* { dg-final { scan-tree-dump-not "<<" "optimized" } } */
+
+#if __SIZEOF_LONG_LONG__ == 8 && __SIZEOF_INT__ == 4 && __CHAR_BIT__ == 8
+unsigned long long
+foo (unsigned long long a)
+{
+  unsigned long long b = a >> 32;
+  int c = b;
+  unsigned long long d = c;
+  return d << 32;
+}
+
+unsigned long long
+bar (unsigned long long a)
+{
+  unsigned long long b = a >> 32;
+  unsigned c = b;
+  unsigned long long d = c;
+  return d << 32;
+}
+
+unsigned long long
+baz (long long a)
+{
+  long long b = a >> 32;
+  unsigned long long c = b;
+  return c << 32;
+}
+
+typedef unsigned V __attribute__((vector_size (2 * sizeof (int;
+typedef int W __attribute__((vector_size (2 * sizeof (int;
+
+void
+quux (W *w, V *v)
+{
+  W a = (W) (*v >> 16);
+  *w = a << 16;
+}
+#else
+int i;
+#endif

Jakub



Re: [Patch, committed, Fortran] PR68020 – Fix implied-shape handling for rank > 2

2020-01-03 Thread Tobias Burnus
Sorry – I had fixed it locally before the commit, but forgot the "git 
add" for that change :-(


Thanks for the fix.

Tobias

On 1/3/20 12:59 AM, Jakub Jelinek wrote:

On Thu, Jan 02, 2020 at 04:43:29PM +0100, Tobias Burnus wrote:

Committed as Rev. 279835 after building an regtesting the attached patch.

+UNRESOLVED: gfortran.dg/implied_shape_5.f90   -O0  compilation failed to 
produce executable
+UNRESOLVED: gfortran.dg/implied_shape_5.f90   -O1  compilation failed to 
produce executable
+UNRESOLVED: gfortran.dg/implied_shape_5.f90   -O2  compilation failed to 
produce executable
+UNRESOLVED: gfortran.dg/implied_shape_5.f90   -O3 -fomit-frame-pointer 
-funroll-loops -fpeel-loops -ftracer -finline-functions  compilation failed to 
produce executable
+UNRESOLVED: gfortran.dg/implied_shape_5.f90   -O3 -g  compilation failed to 
produce executable
+UNRESOLVED: gfortran.dg/implied_shape_5.f90   -Os  compilation failed to 
produce executable

Fixed thusly, tested on x86_64-linux, committed to trunk as obvious.

2020-01-03  Jakub Jelinek  

PR fortran/68020
* gfortran.dg/impled_shape_5.f90: Use dg-do compile rather than dg-do
run.

--- gcc/testsuite/gfortran.dg/implied_shape_5.f90   (revision 279848)
+++ gcc/testsuite/gfortran.dg/implied_shape_5.f90   (working copy)
@@ -1,4 +1,4 @@
-! { dg-do run }
+! { dg-do compile }
  !
  ! PR fortran/68020
  !

Jakub