Move powi folds to match.pd

2015-10-26 Thread Richard Sandiford
Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi.
OK to install?

Thanks,
Richard


gcc/
* builtins.c (fold_builtin_powi): Delete.
(fold_builtin_2): Handle constant powi arguments here.
* match.pd: Add rules previously handled by fold_builtin_powi.

gcc/testsuite/
* gcc.dg/builtins-52.c: Add -O to dg-options.

diff --git a/gcc/builtins.c b/gcc/builtins.c
index 88c0576..3d39d43 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -156,7 +156,6 @@ static tree rewrite_call_expr (location_t, tree, int, tree, 
int, ...);
 static bool validate_arg (const_tree, enum tree_code code);
 static rtx expand_builtin_fabs (tree, rtx, rtx);
 static rtx expand_builtin_signbit (tree, rtx);
-static tree fold_builtin_powi (location_t, tree, tree, tree, tree);
 static tree fold_builtin_bitop (tree, tree);
 static tree fold_builtin_strchr (location_t, tree, tree, tree);
 static tree fold_builtin_memchr (location_t, tree, tree, tree, tree);
@@ -7517,52 +7516,6 @@ fold_const_builtin_pow (tree arg0, tree arg1, tree type)
   return NULL_TREE;
 }
 
-/* Fold a builtin function call to powi, powif, or powil with argument ARG.
-   Return NULL_TREE if no simplification can be made.  */
-static tree
-fold_builtin_powi (location_t loc, tree fndecl ATTRIBUTE_UNUSED,
-  tree arg0, tree arg1, tree type)
-{
-  if (!validate_arg (arg0, REAL_TYPE)
-  || !validate_arg (arg1, INTEGER_TYPE))
-return NULL_TREE;
-
-  /* Optimize pow(1.0,y) = 1.0.  */
-  if (real_onep (arg0))
-return omit_one_operand_loc (loc, type, build_real (type, dconst1), arg1);
-
-  if (tree_fits_shwi_p (arg1))
-{
-  HOST_WIDE_INT c = tree_to_shwi (arg1);
-
-  /* Evaluate powi at compile-time.  */
-  if (TREE_CODE (arg0) == REAL_CST
- && !TREE_OVERFLOW (arg0))
-   {
- REAL_VALUE_TYPE x;
- x = TREE_REAL_CST (arg0);
- real_powi (, TYPE_MODE (type), , c);
- return build_real (type, x);
-   }
-
-  /* Optimize pow(x,0) = 1.0.  */
-  if (c == 0)
-   return omit_one_operand_loc (loc, type, build_real (type, dconst1),
-arg0);
-
-  /* Optimize pow(x,1) = x.  */
-  if (c == 1)
-   return arg0;
-
-  /* Optimize pow(x,-1) = 1.0/x.  */
-  if (c == -1)
-   return fold_build2_loc (loc, RDIV_EXPR, type,
-  build_real (type, dconst1), arg0);
-}
-
-  return NULL_TREE;
-}
-
 /* A subroutine of fold_builtin to fold the various exponent
functions.  Return NULL_TREE if no simplification can be made.
FUNC is the corresponding MPFR exponent function.  */
@@ -9379,7 +9332,16 @@ fold_builtin_2 (location_t loc, tree fndecl, tree arg0, 
tree arg1)
   return fold_const_builtin_pow (arg0, arg1, type);
 
 CASE_FLT_FN (BUILT_IN_POWI):
-  return fold_builtin_powi (loc, fndecl, arg0, arg1, type);
+  if (TREE_CODE (arg0) == REAL_CST
+ && !TREE_OVERFLOW (arg0)
+ && tree_fits_shwi_p (arg1))
+   {
+ HOST_WIDE_INT c = tree_to_shwi (arg1);
+ REAL_VALUE_TYPE x;
+ real_powi (, TYPE_MODE (type), TREE_REAL_CST_PTR (arg0), c);
+ return build_real (type, x);
+   }
+  break;
 
 CASE_FLT_FN (BUILT_IN_COPYSIGN):
   return fold_builtin_copysign (loc, arg0, arg1, type);
diff --git a/gcc/match.pd b/gcc/match.pd
index b681573..a8adffb 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -84,6 +84,7 @@ DEFINE_MATH_FN (LOG10)
 DEFINE_MATH_FN (EXP10)
 DEFINE_MATH_FN (POW)
 DEFINE_MATH_FN (POW10)
+DEFINE_MATH_FN (POWI)
 DEFINE_MATH_FN (SQRT)
 DEFINE_MATH_FN (CBRT)
 DEFINE_MATH_FN (SIN)
@@ -2821,6 +2822,24 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 real_equal (value, )))
  (cbrts @0))
 
+/* powi(1,x) -> 1.  */
+(simplify
+ (POWI real_onep@0 @1)
+ @0)
+
+(simplify
+ (POWI @0 INTEGER_CST@1)
+ (switch
+  /* powi(x,0) -> 1.  */
+  (if (wi::eq_p (@1, 0))
+   { build_real (type, dconst1); })
+  /* powi(x,1) -> x.  */
+  (if (wi::eq_p (@1, 1))
+   @0)
+  /* powi(x,-1) -> 1/x.  */
+  (if (wi::eq_p (@1, -1))
+   (rdiv { build_real (type, dconst1); } @0
+
 /* Narrowing of arithmetic and logical operations. 
 
These are conceptually similar to the transformations performed for
diff --git a/gcc/testsuite/gcc.dg/builtins-52.c 
b/gcc/testsuite/gcc.dg/builtins-52.c
index 684fd66..1cff017 100644
--- a/gcc/testsuite/gcc.dg/builtins-52.c
+++ b/gcc/testsuite/gcc.dg/builtins-52.c
@@ -1,5 +1,5 @@
 /* { dg-do link } */
-/* { dg-options "-ffast-math" } */
+/* { dg-options "-O -ffast-math" } */
 
 extern void link_error(void);
 



Remove constant handling from fold_builtin_{,f}abs

2015-10-26 Thread Richard Sandiford
fold_builtin_fabs and fold_builtin_abs had code to handle constant
arguments, but this simply duplicated what the following fold_build1_loc
would do for ABS_EXPR.

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

Thanks,
Richard


gcc/
* builtins.c (fold_builtin_fabs): Remove constant handling.
(fold_builtin_abs): Likewise.

diff --git a/gcc/builtins.c b/gcc/builtins.c
index ed0030d..a03dffc 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -7847,8 +7847,6 @@ fold_builtin_fabs (location_t loc, tree arg, tree type)
 return NULL_TREE;
 
   arg = fold_convert_loc (loc, type, arg);
-  if (TREE_CODE (arg) == REAL_CST)
-return fold_abs_const (arg, type);
   return fold_build1_loc (loc, ABS_EXPR, type, arg);
 }
 
@@ -7861,8 +7859,6 @@ fold_builtin_abs (location_t loc, tree arg, tree type)
 return NULL_TREE;
 
   arg = fold_convert_loc (loc, type, arg);
-  if (TREE_CODE (arg) == INTEGER_CST)
-return fold_abs_const (arg, type);
   return fold_build1_loc (loc, ABS_EXPR, type, arg);
 }
 



Rename logb and significand folds

2015-10-26 Thread Richard Sandiford
fold_builtin_logb and fold_builtin_significand now only handle
constant arguments, so this patch renames them to fold_const...,
to match fold_const_builtin_pow.  The idea is to differentiate
constant-only folds so that they can be moved to a const_binop-like
function in future.

The functions also had some unnecessary calls to STRIP_NOPS, which
I think are left over from code that has already moved to match.pd.

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

Thanks,
Richard


gcc/
* builtins.c (fold_builtin_logb): Rename to...
(fold_const_builtin_logb): ...this and remove STRIP_NOPS call.
(fold_builtin_significand): Rename to...
(fold_const_builtin_significand): ...this and remove STRIP_NOPS call.
(fold_builtin_1): Update accordingly.

diff --git a/gcc/builtins.c b/gcc/builtins.c
index 86eac5c..260b66d 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -7916,13 +7916,11 @@ fold_builtin_carg (location_t loc, tree arg, tree type)
 /* Fold a call to builtin logb/ilogb.  */
 
 static tree
-fold_builtin_logb (location_t loc, tree arg, tree rettype)
+fold_const_builtin_logb (location_t loc, tree arg, tree rettype)
 {
   if (! validate_arg (arg, REAL_TYPE))
 return NULL_TREE;
 
-  STRIP_NOPS (arg);
-
   if (TREE_CODE (arg) == REAL_CST && ! TREE_OVERFLOW (arg))
 {
   const REAL_VALUE_TYPE *const value = TREE_REAL_CST_PTR (arg);
@@ -7967,13 +7965,11 @@ fold_builtin_logb (location_t loc, tree arg, tree 
rettype)
 /* Fold a call to builtin significand, if radix == 2.  */
 
 static tree
-fold_builtin_significand (location_t loc, tree arg, tree rettype)
+fold_const_builtin_significand (location_t loc, tree arg, tree rettype)
 {
   if (! validate_arg (arg, REAL_TYPE))
 return NULL_TREE;
 
-  STRIP_NOPS (arg);
-
   if (TREE_CODE (arg) == REAL_CST && ! TREE_OVERFLOW (arg))
 {
   const REAL_VALUE_TYPE *const value = TREE_REAL_CST_PTR (arg);
@@ -9002,11 +8998,11 @@ fold_builtin_1 (location_t loc, tree fndecl, tree arg0)
   break;
 
 CASE_FLT_FN (BUILT_IN_SIGNIFICAND):
-  return fold_builtin_significand (loc, arg0, type);
+  return fold_const_builtin_significand (loc, arg0, type);
 
 CASE_FLT_FN (BUILT_IN_ILOGB):
 CASE_FLT_FN (BUILT_IN_LOGB):
-  return fold_builtin_logb (loc, arg0, type);
+  return fold_const_builtin_logb (loc, arg0, type);
 
 case BUILT_IN_ISASCII:
   return fold_builtin_isascii (loc, arg0);



Re: Move min(max...) and max(min...) folds to match.pd

2015-10-26 Thread Richard Biener
On Mon, Oct 26, 2015 at 11:00 AM, Richard Sandiford
 wrote:
> This handles both integer and floating-point arguments.  It's needed
> for the follow-on patch to move fmin and fmax to match.pd.
>
> Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi.
> OK to install?

Ok.

Thanks,
Richard.

> Thanks,
> Richard
>
>
> gcc/
> * fold-const.c (fold_minmax): Delete.
> (fold_binary_loc): Don't call it.
> * match.pd: Add rules previously handled by fold_minmax.
>
> diff --git a/gcc/fold-const.c b/gcc/fold-const.c
> index ffad732..e8ff1de 100644
> --- a/gcc/fold-const.c
> +++ b/gcc/fold-const.c
> @@ -8073,49 +8073,6 @@ fold_truth_andor (location_t loc, enum tree_code code, 
> tree type,
>return NULL_TREE;
>  }
>
> -/* Fold a binary expression of code CODE and type TYPE with operands
> -   OP0 and OP1, containing either a MIN-MAX or a MAX-MIN combination.
> -   Return the folded expression if folding is successful.  Otherwise,
> -   return NULL_TREE.  */
> -
> -static tree
> -fold_minmax (location_t loc, enum tree_code code, tree type, tree op0, tree 
> op1)
> -{
> -  enum tree_code compl_code;
> -
> -  if (code == MIN_EXPR)
> -compl_code = MAX_EXPR;
> -  else if (code == MAX_EXPR)
> -compl_code = MIN_EXPR;
> -  else
> -gcc_unreachable ();
> -
> -  /* MIN (MAX (a, b), b) == b.  */
> -  if (TREE_CODE (op0) == compl_code
> -  && operand_equal_p (TREE_OPERAND (op0, 1), op1, 0))
> -return omit_one_operand_loc (loc, type, op1, TREE_OPERAND (op0, 0));
> -
> -  /* MIN (MAX (b, a), b) == b.  */
> -  if (TREE_CODE (op0) == compl_code
> -  && operand_equal_p (TREE_OPERAND (op0, 0), op1, 0)
> -  && reorder_operands_p (TREE_OPERAND (op0, 1), op1))
> -return omit_one_operand_loc (loc, type, op1, TREE_OPERAND (op0, 1));
> -
> -  /* MIN (a, MAX (a, b)) == a.  */
> -  if (TREE_CODE (op1) == compl_code
> -  && operand_equal_p (op0, TREE_OPERAND (op1, 0), 0)
> -  && reorder_operands_p (op0, TREE_OPERAND (op1, 1)))
> -return omit_one_operand_loc (loc, type, op0, TREE_OPERAND (op1, 1));
> -
> -  /* MIN (a, MAX (b, a)) == a.  */
> -  if (TREE_CODE (op1) == compl_code
> -  && operand_equal_p (op0, TREE_OPERAND (op1, 1), 0)
> -  && reorder_operands_p (op0, TREE_OPERAND (op1, 0)))
> -return omit_one_operand_loc (loc, type, op0, TREE_OPERAND (op1, 0));
> -
> -  return NULL_TREE;
> -}
> -
>  /* Helper that tries to canonicalize the comparison ARG0 CODE ARG1
> by changing CODE to reduce the magnitude of constants involved in
> ARG0 of the comparison.
> @@ -10426,15 +10383,7 @@ fold_binary_loc (location_t loc,
>return NULL_TREE;
>
>  case MIN_EXPR:
> -  tem = fold_minmax (loc, MIN_EXPR, type, arg0, arg1);
> -  if (tem)
> -   return tem;
> -  goto associate;
> -
>  case MAX_EXPR:
> -  tem = fold_minmax (loc, MAX_EXPR, type, arg0, arg1);
> -  if (tem)
> -   return tem;
>goto associate;
>
>  case TRUTH_ANDIF_EXPR:
> diff --git a/gcc/match.pd b/gcc/match.pd
> index e02379f..338644c 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -1176,6 +1176,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>   (simplify
>(minmax @0 @0)
>@0))
> +/* min(max(x,y),y) -> y.  */
> +(simplify
> + (min:c (max:c @0 @1) @1)
> + @1)
> +/* max(min(x,y),y) -> y.  */
> +(simplify
> + (max:c (min:c @0 @1) @1)
> + @1)
>  (simplify
>   (min @0 @1)
>   (if (INTEGRAL_TYPE_P (type)
>


[Ada] Missing error on conflicting declarations

2015-10-26 Thread Arnaud Charlet
With This patch the compiler properly rejects a subprogram body whose
signature is type conformant with a previous expression function in
the same scope.

Compiling same_signature,adb must yield:

  same_signature.adb:8:04: body conflicts with expression function at line 5

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

procedure Same_Signature is

   function My_Add (A, B : Integer) return Integer
   is (A - B);

   function My_Add (A, B : Integer) return Integer is
   begin
  return A + B;
   end My_Add;

begin
   Put_Line (My_Add (5, 6)'Img);
end Same_Signature;

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

2015-10-26  Ed Schonberg  

* sem_ch6.adb (Find_Corresponding_Spec): Reject a subprogram
body whose signature is type conformant with a previous expression
function.

Index: sem_ch6.adb
===
--- sem_ch6.adb (revision 229321)
+++ sem_ch6.adb (working copy)
@@ -7310,6 +7310,19 @@
then
   return E;
 
+   --  Expression functions can be completions, but cannot be
+   --  completed by an explicit body.
+
+   elsif Comes_From_Source (E)
+ and then Comes_From_Source (N)
+ and then Nkind (N) = N_Subprogram_Body
+ and then Nkind (Original_Node (Unit_Declaration_Node (E))) =
+N_Expression_Function
+   then
+  Error_Msg_Sloc := Sloc (E);
+  Error_Msg_N ("body conflicts with expression function#", N);
+  return Empty;
+
elsif not Has_Completion (E) then
   if Nkind (N) /= N_Subprogram_Body_Stub then
  Set_Corresponding_Spec (N, E);


[PATCH] Fix VEC_COND_EXPR types when vectorizing conditional expressions

2015-10-26 Thread Alan Hayward
VEC_COND_EXPRs have been changed to use boolean vectors for the first
argument.
This changes the vectorizing conditional expressions to use this new
format,
fixing the compiler failures for the 65947-*.c tests.


2015-10-26  Alan Hayward 

gcc/
PR tree-optimization/65947
* tree-vect-loop.c (vect_create_epilog_for_reduction):
Fix VEC_COND_EXPR types.


Cheers,
Alan.





fix_veccondexprtypes.patch
Description: Binary data


Re: [PATCH][auto-inc-dec.c] Account for cost of move operation in FORM_PRE_ADD and FORM_POST_ADD cases

2015-10-26 Thread Bernd Schmidt


On 10/26/2015 11:40 AM, Kyrill Tkachov wrote:

In the FORM_POST_ADD case the pass transforms:
*a
...
b <- a + c

into

b <- a
...
*(b += c) post


However, the code in attempt_change that compares the costs of the
before and after sequences
has an oversight. When calculating the cost of the new sequence it
doesn't take into account the cost of the
b <- a move. This patch fixes the calculation by calling seq_cost on the
result of the emit_move_insn call
we do to emit that move.


But isn't that balanced by the fact that it doesn't seem to take into 
account the gain of removing the inc_insn either? So I think this can't 
be right.



+  new_mov_cost = seq_cost (mov_insn, speed);
+}
+
+  new_cost = new_mem_cost + new_mov_cost;


Here I'd just replace the first line with
  new_cost += seq_cost (...)
and lose the extra variable.

I seem to recall Richard had a rewrite of all the autoinc code. I wonder 
what happened to that?



Bernd


Re: Move expN folds to match.pd

2015-10-26 Thread Richard Biener
On Mon, Oct 26, 2015 at 11:32 AM, Marc Glisse  wrote:
> On Mon, 26 Oct 2015, Richard Sandiford wrote:
>
>> +  /* expN(logN(x)) -> x.  */
>> +  (simplify
>> +   (exps (logs @0))
>> +   @0))
>
>
> We are not very consistent about it, but wasn't there an idea that we should
> use non_lvalue in most such places?

Hmm, probably.  IIRC the builtins.c code always wraps a NOP_EXPR around
constants.

OTOH I hope that the delayed folding branch will get merged for C++ and thus
we can get rid of _all_ NON_VALUE_EXPRs produced by folding.  At least the
C FE no longer requires them.

Richard.

> --
> Marc Glisse


[Ada] Front-end inlining and predicates

2015-10-26 Thread Arnaud Charlet
The front-end cannot inline subprograms that contain certain declarations,
such as nested subprograms.  If the the subprogram to inline includes a
subtype declaration with predicates, it cannot be inlined because the
analysis of the predicate will generate (nested) predicate functions.

Source:

---
package body Foo
with SPARK_Mode
is

   pragma Warnings (Off, "analyzing unreferenced procedure *");

   G_V  : Natural  := 123;
   G_VC : constant Natural := G_V;
   G_SC : constant Natural := 500;

   procedure Test_05 (A, B : Natural;
  O: out Boolean)
   is
  --  ok
  subtype T is Natural range 0 .. A  with Predicate => (3 <= T);
  subtype U is Natural range 0 .. 10 with Predicate => (B <= U);
  subtype V is Natural range 0 .. 10 with Predicate => (V in G_VC .. G_SC);

  X : Natural := 10;
   begin
  O := X in T | U | V;
   end Test_05;

end Foo;
--
package Foo
with SPARK_Mode
is
   pragma Elaborate_Body;
end Foo;
--
Command:

   gcc -c -gnatd.F foo.adb

Output:

foo.adb:15:07: info:
   no contextual analysis of "Test_05"(subtype declaration with predicate)

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

2015-10-26  Ed Schonberg  

* inline.adb (Has_Excluded_Declaration): A subtype declaration
with a predicate aspect generates a subprogram, and therefore
prevents the inlining of the enclosing subprogram.

Index: inline.adb
===
--- inline.adb  (revision 229313)
+++ inline.adb  (working copy)
@@ -3513,6 +3513,37 @@
   ("cannot inline & (nested procedure instantiation)?",
D, Subp);
 return True;
+
+ --  Subtype declarations with predicates will generate predicate
+ --  functions, i.e. nested subprogram bodies, so inlining is not
+ --  possible.
+
+ elsif Nkind (D) = N_Subtype_Declaration
+   and then Present (Aspect_Specifications (D))
+ then
+declare
+   A: Node_Id;
+   A_Id : Aspect_Id;
+
+begin
+   A := First (Aspect_Specifications (D));
+   while Present (A) loop
+  A_Id := Get_Aspect_Id (Chars (Identifier (A)));
+
+  if A_Id = Aspect_Predicate
+or else A_Id = Aspect_Static_Predicate
+or else A_Id = Aspect_Dynamic_Predicate
+  then
+ Cannot_Inline
+   ("cannot inline & "
+& "(subtype declaration with predicate)?",
+D, Subp);
+ return True;
+  end if;
+
+  Next (A);
+   end loop;
+end;
  end if;
 
  Next (D);


[Ada] Clean up in s-osinte

2015-10-26 Thread Arnaud Charlet
This patch cleans the way getpagesize() is imported and removes an
inconsistency wrt the underlying C routine. No change in functionality.

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

2015-10-26  Arnaud Charlet  

* s-osinte-hpux.ads, s-osinte-aix.ads, s-osinte-solaris-posix.ads,
s-osinte-darwin.ads, s-osinte-android.ads, s-osinte-freebsd.ads,
s-taprop-posix.adb (Get_Page_Size): C function returns an int. Adjust
callers accordingly.

Index: s-osinte-hpux.ads
===
--- s-osinte-hpux.ads   (revision 229313)
+++ s-osinte-hpux.ads   (working copy)
@@ -7,7 +7,7 @@
 --  S p e c --
 --  --
 --   Copyright (C) 1991-1994, Florida State University  --
---Copyright (C) 1995-2014, Free Software Foundation, Inc.   --
+--Copyright (C) 1995-2015, Free Software Foundation, Inc.   --
 --  --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -301,8 +301,7 @@
--  Returns the stack base of the specified thread. Only call this function
--  when Stack_Base_Available is True.
 
-   function Get_Page_Size return size_t;
-   function Get_Page_Size return Address;
+   function Get_Page_Size return int;
pragma Import (C, Get_Page_Size, "getpagesize");
--  Returns the size of a page
 
Index: s-osinte-aix.ads
===
--- s-osinte-aix.ads(revision 229313)
+++ s-osinte-aix.ads(working copy)
@@ -7,7 +7,7 @@
 --  S p e c --
 --  --
 -- Copyright (C) 1991-1994, Florida State University--
---  Copyright (C) 1995-2014, Free Software Foundation, Inc. --
+--  Copyright (C) 1995-2015, Free Software Foundation, Inc. --
 --  --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -319,8 +319,7 @@
--  Returns the stack base of the specified thread. Only call this function
--  when Stack_Base_Available is True.
 
-   function Get_Page_Size return size_t;
-   function Get_Page_Size return Address;
+   function Get_Page_Size return int;
pragma Import (C, Get_Page_Size, "getpagesize");
--  Returns the size of a page
 
Index: s-osinte-solaris-posix.ads
===
--- s-osinte-solaris-posix.ads  (revision 229313)
+++ s-osinte-solaris-posix.ads  (working copy)
@@ -7,7 +7,7 @@
 --  S p e c --
 --  --
 -- Copyright (C) 1991-1994, Florida State University--
---  Copyright (C) 1995-2014, Free Software Foundation, Inc. --
+--  Copyright (C) 1995-2015, Free Software Foundation, Inc. --
 --  --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -300,8 +300,7 @@
--  Returns the stack base of the specified thread. Only call this function
--  when Stack_Base_Available is True.
 
-   function Get_Page_Size return size_t;
-   function Get_Page_Size return Address;
+   function Get_Page_Size return int;
pragma Import (C, Get_Page_Size, "getpagesize");
--  Returns the size of a page
 
Index: s-osinte-darwin.ads
===
--- s-osinte-darwin.ads (revision 229313)
+++ s-osinte-darwin.ads (working copy)
@@ -7,7 +7,7 @@
 --  S p e c --
 --  --
 -- Copyright (C) 1991-1994, Florida State University--
---  Copyright (C) 1995-2014, Free Software Foundation, Inc. --
+--  Copyright (C) 1995-2015, Free Software Foundation, Inc. --
 --  --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -299,8 +299,7 @@
--  returns the stack base of the specified thread. 

[Ada] Extraction of components/discriminants of concurrent types

2015-10-26 Thread Arnaud Charlet
This patch allows First_Component and First_Component_Or_Discriminant to apply
to protected and task types. No change in behavior, no test needed. The patch
is aimed at clients of the compiler front-end.

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

2015-10-26  Hristian Kirtchev  

* einfo.adb (First_Component): Update the assertion to allow
for concurrent types.
(First_Component_Or_Discriminant): Update the assertion to allow for
concurrent types.
* einfo.ads: Update the documentation of attributes First_Component
and First_Component_Or_Discriminant along with uses in entities.

Index: einfo.adb
===
--- einfo.adb   (revision 229333)
+++ einfo.adb   (working copy)
@@ -6926,7 +6926,9 @@
 
begin
   pragma Assert
-(Is_Record_Type (Id) or else Is_Incomplete_Or_Private_Type (Id));
+(Is_Concurrent_Type (Id)
+  or else Is_Incomplete_Or_Private_Type (Id)
+  or else Is_Record_Type (Id));
 
   Comp_Id := First_Entity (Id);
   while Present (Comp_Id) loop
@@ -6946,8 +6948,9 @@
 
begin
   pragma Assert
-(Is_Record_Type (Id)
+(Is_Concurrent_Type (Id)
   or else Is_Incomplete_Or_Private_Type (Id)
+  or else Is_Record_Type (Id)
   or else Has_Discriminants (Id));
 
   Comp_Id := First_Entity (Id);
Index: einfo.ads
===
--- einfo.ads   (revision 229343)
+++ einfo.ads   (working copy)
@@ -1286,14 +1286,15 @@
 --   objects.
 
 --First_Component (synthesized)
---   Applies to record types. Returns the first component by following the
---   chain of declared entities for the record until a component is found
---   (one with an Ekind of E_Component). The discriminants are skipped. If
---   the record is null, then Empty is returned.
+--   Applies to incomplete, private, protected, record and task types.
+--   Returns the first component by following the chain of declared
+--   entities for the type a component is found (one with an Ekind of
+--   E_Component). The discriminants are skipped. If the record is null,
+--   then Empty is returned.
 
 --First_Component_Or_Discriminant (synthesized)
---  Similar to First_Component, but discriminants are not skipped, so will
---  find the first discriminant if discriminants are present.
+--   Similar to First_Component, but discriminants are not skipped, so will
+--   find the first discriminant if discriminants are present.
 
 --First_Entity (Node17)
 --   Defined in all entities which act as scopes to which a list of
@@ -6263,6 +6264,8 @@
--SPARK_Pragma_Inherited  (Flag265)
--Uses_Lock_Free  (Flag188)
--Uses_Sec_Stack  (Flag95)   ???
+   --First_Component (synth)
+   --First_Component_Or_Discriminant (synth)
--Has_Entries (synth)
--Has_Interrupt_Handler   (synth)
--Number_Entries  (synth)
@@ -6410,6 +6413,8 @@
--SPARK_Aux_Pragma_Inherited  (Flag266)
--SPARK_Pragma_Inherited  (Flag265)
--Uses_Sec_Stack  (Flag95)   ???
+   --First_Component (synth)
+   --First_Component_Or_Discriminant (synth)
--Has_Entries (synth)
--Number_Entries  (synth)
--(plus type attributes)


[Ada] In an element iterator, the element is constant if the container is.

2015-10-26 Thread Arnaud Charlet
This patch adds a legality check to element iterators over containers: the
element is a constant if the container object is a constant, even if the
container type has a Variable_Indexing aspect.

Compiling the following must be rejected with:

 strange_behavior.adb:12:07: left hand side of assignment must be a variable

---
with Ada.Containers.Doubly_Linked_Lists;
procedure Strange_Behavior is
   
   package Integer_Lists is new
  Ada.Containers.Doubly_Linked_Lists (Element_Type => Integer);

   L : constant Integer_Lists.List := Integer_Lists.Empty_List;
  
begin
  
   for Item of L loop
  Item := 0;
   end loop;
  
end Strange_Behavior; 

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

2015-10-26  Ed Schonberg  

* exp_ch5.adb (Expand_Iterator_Loop_Over_Container): For
an element iterator loop, the element is a constant if the
container object is a constant, even if the container type has
a Variable_Indexing aspect.

Index: exp_ch5.adb
===
--- exp_ch5.adb (revision 229313)
+++ exp_ch5.adb (working copy)
@@ -3864,10 +3864,14 @@
 Set_Debug_Info_Needed (Id);
 
 --  If the container does not have a variable indexing aspect,
---  the element is a constant in the loop.
+--  the element is a constant in the loop. The container itself
+--  may be constant, in which case the element is a constant as
+--  well. The container has been rewritten as a call to Iterate,
+--  so examine original node.
 
 if No (Find_Value_Of_Aspect
  (Container_Typ, Aspect_Variable_Indexing))
+  or else not Is_Variable (Original_Node (Container))
 then
Set_Ekind (Id, E_Constant);
 end if;


Re: Move some bit and binary optimizations in simplify and match

2015-10-26 Thread Richard Biener
On Sat, Oct 24, 2015 at 11:15 PM, Marc Glisse  wrote:
> On Fri, 23 Oct 2015, Hurugalawadi, Naveen wrote:
>
> + (minus (bit_and:cs @0 (bit_not @1)) (bit_and:s @0 @1))
>
> I am not sure why we have :c on one bit_and but not the other.

Clearly an omission.

> + (bit_ior:c (bit_and:c @0 (bit_not @1)) (bit_and:c (bit_not @0) @1))
>
> Here on the other hand, I believe the :c on bit_ior is redundant.

Yes.  It's somewhat twisty ;)  I wonder why it doesn't get you a genmatch
warning for duplicate patterns though.  A it does:

test.pd:2:3 warning: duplicate pattern
 (bit_ior:c (bit_and:c @0 (bit_not @1)) (bit_and:c (bit_not @0) @1))
  ^
test.pd:2:3 warning: previous pattern defined here
 (bit_ior:c (bit_and:c @0 (bit_not @1)) (bit_and:c (bit_not @0) @1))
  ^
(BIT_IOR_EXPR (BIT_AND_EXPR (BIT_NOT_EXPR @0) @1) (BIT_AND_EXPR @0
(BIT_NOT_EXPR @1)))

so please watch out for them when building.

Richard.

>
> --
> Marc Glisse


Don't create SSA names until in SSA form

2015-10-26 Thread Richard Sandiford
An upcoming patch adds a fold from hypot(x,x) to fabs(x)*sqrt(2).
This is unusual in that it could trigger in the gimplifier but would
require new SSA names to be created.  This patch makes sure that we
don't try to create new SSA names when we're not yet in SSA form.

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

Thanks,
Richard


gcc/
* gimple-match-head.c (maybe_push_res_to_seq): Don't attempt
to create new SSA names if not in SSA form.

diff --git a/gcc/gimple-match-head.c b/gcc/gimple-match-head.c
index 8f72919..1345cf9 100644
--- a/gcc/gimple-match-head.c
+++ b/gcc/gimple-match-head.c
@@ -331,7 +331,11 @@ maybe_push_res_to_seq (code_helper rcode, tree type, tree 
*ops,
  && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[2])))
return NULL_TREE;
   if (!res)
-   res = make_ssa_name (type);
+   {
+ if (!gimple_in_ssa_p (cfun))
+   return NULL_TREE;
+ res = make_ssa_name (type);
+   }
   maybe_build_generic_op (rcode, type, [0], ops[1], ops[2]);
   gimple *new_stmt = gimple_build_assign (res, rcode,
 ops[0], ops[1], ops[2]);
@@ -361,7 +365,11 @@ maybe_push_res_to_seq (code_helper rcode, tree type, tree 
*ops,
}
   gcc_assert (nargs != 0);
   if (!res)
-   res = make_ssa_name (type);
+   {
+ if (!gimple_in_ssa_p (cfun))
+   return NULL_TREE;
+ res = make_ssa_name (type);
+   }
   gimple *new_stmt = gimple_build_call (decl, nargs, ops[0], ops[1], 
ops[2]);
   gimple_call_set_lhs (new_stmt, res);
   gimple_seq_add_stmt_without_update (seq, new_stmt);



Move copysign folds to match.pd

2015-10-26 Thread Richard Sandiford
Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi.
OK to install?

Thanks,
Richard


gcc/
* builtins.c (fold_builtin_copysign): Delete.
(fold_builtin_2): Handle constant copysign arguments here.
* match.pd: Add rules previously handled by fold_builtin_copysign.

diff --git a/gcc/builtins.c b/gcc/builtins.c
index ae7e7ef..ed0030d 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -7781,46 +7781,6 @@ fold_builtin_strncmp (location_t loc, tree arg1, tree 
arg2, tree len)
   return NULL_TREE;
 }
 
-/* Fold function call to builtin copysign, copysignf or copysignl with
-   arguments ARG1 and ARG2.  Return NULL_TREE if no simplification can
-   be made.  */
-
-static tree
-fold_builtin_copysign (location_t loc, tree arg1, tree arg2, tree type)
-{
-  if (!validate_arg (arg1, REAL_TYPE)
-  || !validate_arg (arg2, REAL_TYPE))
-return NULL_TREE;
-
-  /* copysign(X,X) is X.  */
-  if (operand_equal_p (arg1, arg2, 0))
-return fold_convert_loc (loc, type, arg1);
-
-  /* If ARG1 and ARG2 are compile-time constants, determine the result.  */
-  if (TREE_CODE (arg1) == REAL_CST
-  && TREE_CODE (arg2) == REAL_CST
-  && !TREE_OVERFLOW (arg1)
-  && !TREE_OVERFLOW (arg2))
-{
-  REAL_VALUE_TYPE c1, c2;
-
-  c1 = TREE_REAL_CST (arg1);
-  c2 = TREE_REAL_CST (arg2);
-  /* c1.sign := c2.sign.  */
-  real_copysign (, );
-  return build_real (type, c1);
-}
-
-  /* copysign(X, Y) is fabs(X) when Y is always non-negative.
- Remember to evaluate Y for side-effects.  */
-  if (tree_expr_nonnegative_p (arg2))
-return omit_one_operand_loc (loc, type,
-fold_build1_loc (loc, ABS_EXPR, type, arg1),
-arg2);
-
-  return NULL_TREE;
-}
-
 /* Fold a call to builtin isascii with argument ARG.  */
 
 static tree
@@ -9278,7 +9238,16 @@ fold_builtin_2 (location_t loc, tree fndecl, tree arg0, 
tree arg1)
   break;
 
 CASE_FLT_FN (BUILT_IN_COPYSIGN):
-  return fold_builtin_copysign (loc, arg0, arg1, type);
+  if (TREE_CODE (arg0) == REAL_CST
+ && TREE_CODE (arg1) == REAL_CST
+ && !TREE_OVERFLOW (arg0)
+ && !TREE_OVERFLOW (arg1))
+   {
+ REAL_VALUE_TYPE c1 = TREE_REAL_CST (arg0);
+ real_copysign (, TREE_REAL_CST_PTR (arg1));
+ return build_real (type, c1);
+   }
+  break;
 
 CASE_FLT_FN (BUILT_IN_FMIN):
   return fold_builtin_fmin_fmax (loc, arg0, arg1, type, /*max=*/false);
diff --git a/gcc/match.pd b/gcc/match.pd
index e50f5bb..e02379f 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -2541,6 +2541,16 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  (POW real_onep@0 @1)
  @0)
 
+(simplify
+ /* copysign(x,x) -> x.  */
+ (COPYSIGN @0 @0)
+ @0)
+
+(simplify
+ /* copysign(x,y) -> fabs(x) if y is nonnegative.  */
+ (COPYSIGN @0 tree_expr_nonnegative_p@1)
+ (abs @0))
+
 /* Canonicalization of sequences of math builtins.  These rules represent
IL simplifications but are not necessarily optimizations.
 



Move fmin and fmax folds to match.pd

2015-10-26 Thread Richard Sandiford
Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi.
OK to install?

Thanks,
Richard


gcc/
* builtins.c (fold_builtin_fmin_fmax): Delete.
(fold_builtin_2): Handle constant fmin and fmax arguments here.
* match.pd: Add rules previously handled by fold_builtin_fmin_fmax.

diff --git a/gcc/builtins.c b/gcc/builtins.c
index 6cd8879..86eac5c 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -7891,51 +7891,6 @@ fold_builtin_fma (location_t loc, tree arg0, tree arg1, 
tree arg2, tree type)
   return NULL_TREE;
 }
 
-/* Fold a call to builtin fmin or fmax.  */
-
-static tree
-fold_builtin_fmin_fmax (location_t loc, tree arg0, tree arg1,
-   tree type, bool max)
-{
-  if (validate_arg (arg0, REAL_TYPE) && validate_arg (arg1, REAL_TYPE))
-{
-  /* Calculate the result when the argument is a constant.  */
-  tree res = do_mpfr_arg2 (arg0, arg1, type, (max ? mpfr_max : mpfr_min));
-
-  if (res)
-   return res;
-
-  /* If either argument is NaN, return the other one.  Avoid the
-transformation if we get (and honor) a signalling NaN.  Using
-omit_one_operand() ensures we create a non-lvalue.  */
-  if (TREE_CODE (arg0) == REAL_CST
- && real_isnan (_REAL_CST (arg0))
- && (! HONOR_SNANS (arg0)
- || ! TREE_REAL_CST (arg0).signalling))
-   return omit_one_operand_loc (loc, type, arg1, arg0);
-  if (TREE_CODE (arg1) == REAL_CST
- && real_isnan (_REAL_CST (arg1))
- && (! HONOR_SNANS (arg1)
- || ! TREE_REAL_CST (arg1).signalling))
-   return omit_one_operand_loc (loc, type, arg0, arg1);
-
-  /* Transform fmin/fmax(x,x) -> x.  */
-  if (operand_equal_p (arg0, arg1, OEP_PURE_SAME))
-   return omit_one_operand_loc (loc, type, arg0, arg1);
-
-  /* Convert fmin/fmax to MIN_EXPR/MAX_EXPR.  C99 requires these
-functions to return the numeric arg if the other one is NaN.
-These tree codes don't honor that, so only transform if
--ffinite-math-only is set.  C99 doesn't require -0.0 to be
-handled, so we don't have to worry about it either.  */
-  if (flag_finite_math_only)
-   return fold_build2_loc (loc, (max ? MAX_EXPR : MIN_EXPR), type,
-   fold_convert_loc (loc, type, arg0),
-   fold_convert_loc (loc, type, arg1));
-}
-  return NULL_TREE;
-}
-
 /* Fold a call to builtin carg(a+bi) -> atan2(b,a).  */
 
 static tree
@@ -9241,10 +9196,14 @@ fold_builtin_2 (location_t loc, tree fndecl, tree arg0, 
tree arg1)
   break;
 
 CASE_FLT_FN (BUILT_IN_FMIN):
-  return fold_builtin_fmin_fmax (loc, arg0, arg1, type, /*max=*/false);
+  if (validate_arg (arg0, REAL_TYPE) && validate_arg (arg1, REAL_TYPE))
+   return do_mpfr_arg2 (arg0, arg1, type, mpfr_min);
+  break;
 
 CASE_FLT_FN (BUILT_IN_FMAX):
-  return fold_builtin_fmin_fmax (loc, arg0, arg1, type, /*max=*/true);
+  if (validate_arg (arg0, REAL_TYPE) && validate_arg (arg1, REAL_TYPE))
+   return do_mpfr_arg2 (arg0, arg1, type, mpfr_max);
+  break;
 
 case BUILT_IN_ISGREATER:
   return fold_builtin_unordered_cmp (loc, fndecl,
diff --git a/gcc/match.pd b/gcc/match.pd
index 338644c..f2e7d64 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -103,6 +103,8 @@ DEFINE_MATH_FN (CABS)
 DEFINE_MATH_FN (TRUNC)
 DEFINE_MATH_FN (NEARBYINT)
 DEFINE_MATH_FN (SIGNBIT)
+DEFINE_MATH_FN (FMIN)
+DEFINE_MATH_FN (FMAX)
 
 DEFINE_INT_AND_FLOAT_ROUND_FN (FLOOR)
 DEFINE_INT_AND_FLOAT_ROUND_FN (CEIL)
@@ -1170,9 +1172,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  (minus (convert @1) (convert @2)))
 
 
-/* Simplifications of MIN_EXPR and MAX_EXPR.  */
+/* Simplifications of MIN_EXPR, MAX_EXPR, fmin() and fmax().  */
 
-(for minmax (min max)
+(for minmax (min max FMIN FMAX)
  (simplify
   (minmax @0 @0)
   @0))
@@ -1196,7 +1198,26 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   && TYPE_MAX_VALUE (type)
   && operand_equal_p (@1, TYPE_MAX_VALUE (type), OEP_ONLY_CONST))
   @1))
-
+(for minmax (FMIN FMAX)
+ /* If either argument is NaN, return the other one.  Avoid the
+transformation if we get (and honor) a signalling NaN.  */
+ (simplify
+  (minmax:c @0 REAL_CST@1)
+  (if (real_isnan (TREE_REAL_CST_PTR (@1))
+   && (!HONOR_SNANS (@1) || !TREE_REAL_CST (@1).signalling))
+   @0)))
+/* Convert fmin/fmax to MIN_EXPR/MAX_EXPR.  C99 requires these
+   functions to return the numeric arg if the other one is NaN.
+   MIN and MAX don't honor that, so only transform if -ffinite-math-only
+   is set.  C99 doesn't require -0.0 to be handled, so we don't have to
+   worry about it either.  */
+(if (flag_finite_math_only)
+ (simplify
+  (FMIN @0 @1)
+  (min @0 @1))
+ (simplify
+  (FMAX @0 @1)
+  (max @0 @1)))
 
 /* Simplifications of shift and rotates.  */
 



Re: [PATCH] libjava: fix locale handling when sorting JNI methods

2015-10-26 Thread Andrew Haley
On 23/10/15 04:56, Mike Frysinger wrote:
> 2015-10-22  Mike Frysinger  
> 
>   * scripts/check_jni_methods.sh.in: Run sort with LC_ALL=C, and
>   combine `sort|uniq` into `sort -u`.

Looks OK to me.

Andrew.



Re: Move powi folds to match.pd

2015-10-26 Thread Richard Biener
On Mon, Oct 26, 2015 at 10:48 AM, Richard Sandiford
 wrote:
> Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi.
> OK to install?

Ok.

Thanks,
Richard.

> Thanks,
> Richard
>
>
> gcc/
> * builtins.c (fold_builtin_powi): Delete.
> (fold_builtin_2): Handle constant powi arguments here.
> * match.pd: Add rules previously handled by fold_builtin_powi.
>
> gcc/testsuite/
> * gcc.dg/builtins-52.c: Add -O to dg-options.
>
> diff --git a/gcc/builtins.c b/gcc/builtins.c
> index 88c0576..3d39d43 100644
> --- a/gcc/builtins.c
> +++ b/gcc/builtins.c
> @@ -156,7 +156,6 @@ static tree rewrite_call_expr (location_t, tree, int, 
> tree, int, ...);
>  static bool validate_arg (const_tree, enum tree_code code);
>  static rtx expand_builtin_fabs (tree, rtx, rtx);
>  static rtx expand_builtin_signbit (tree, rtx);
> -static tree fold_builtin_powi (location_t, tree, tree, tree, tree);
>  static tree fold_builtin_bitop (tree, tree);
>  static tree fold_builtin_strchr (location_t, tree, tree, tree);
>  static tree fold_builtin_memchr (location_t, tree, tree, tree, tree);
> @@ -7517,52 +7516,6 @@ fold_const_builtin_pow (tree arg0, tree arg1, tree 
> type)
>return NULL_TREE;
>  }
>
> -/* Fold a builtin function call to powi, powif, or powil with argument ARG.
> -   Return NULL_TREE if no simplification can be made.  */
> -static tree
> -fold_builtin_powi (location_t loc, tree fndecl ATTRIBUTE_UNUSED,
> -  tree arg0, tree arg1, tree type)
> -{
> -  if (!validate_arg (arg0, REAL_TYPE)
> -  || !validate_arg (arg1, INTEGER_TYPE))
> -return NULL_TREE;
> -
> -  /* Optimize pow(1.0,y) = 1.0.  */
> -  if (real_onep (arg0))
> -return omit_one_operand_loc (loc, type, build_real (type, dconst1), 
> arg1);
> -
> -  if (tree_fits_shwi_p (arg1))
> -{
> -  HOST_WIDE_INT c = tree_to_shwi (arg1);
> -
> -  /* Evaluate powi at compile-time.  */
> -  if (TREE_CODE (arg0) == REAL_CST
> - && !TREE_OVERFLOW (arg0))
> -   {
> - REAL_VALUE_TYPE x;
> - x = TREE_REAL_CST (arg0);
> - real_powi (, TYPE_MODE (type), , c);
> - return build_real (type, x);
> -   }
> -
> -  /* Optimize pow(x,0) = 1.0.  */
> -  if (c == 0)
> -   return omit_one_operand_loc (loc, type, build_real (type, dconst1),
> -arg0);
> -
> -  /* Optimize pow(x,1) = x.  */
> -  if (c == 1)
> -   return arg0;
> -
> -  /* Optimize pow(x,-1) = 1.0/x.  */
> -  if (c == -1)
> -   return fold_build2_loc (loc, RDIV_EXPR, type,
> -  build_real (type, dconst1), arg0);
> -}
> -
> -  return NULL_TREE;
> -}
> -
>  /* A subroutine of fold_builtin to fold the various exponent
> functions.  Return NULL_TREE if no simplification can be made.
> FUNC is the corresponding MPFR exponent function.  */
> @@ -9379,7 +9332,16 @@ fold_builtin_2 (location_t loc, tree fndecl, tree 
> arg0, tree arg1)
>return fold_const_builtin_pow (arg0, arg1, type);
>
>  CASE_FLT_FN (BUILT_IN_POWI):
> -  return fold_builtin_powi (loc, fndecl, arg0, arg1, type);
> +  if (TREE_CODE (arg0) == REAL_CST
> + && !TREE_OVERFLOW (arg0)
> + && tree_fits_shwi_p (arg1))
> +   {
> + HOST_WIDE_INT c = tree_to_shwi (arg1);
> + REAL_VALUE_TYPE x;
> + real_powi (, TYPE_MODE (type), TREE_REAL_CST_PTR (arg0), c);
> + return build_real (type, x);
> +   }
> +  break;
>
>  CASE_FLT_FN (BUILT_IN_COPYSIGN):
>return fold_builtin_copysign (loc, arg0, arg1, type);
> diff --git a/gcc/match.pd b/gcc/match.pd
> index b681573..a8adffb 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -84,6 +84,7 @@ DEFINE_MATH_FN (LOG10)
>  DEFINE_MATH_FN (EXP10)
>  DEFINE_MATH_FN (POW)
>  DEFINE_MATH_FN (POW10)
> +DEFINE_MATH_FN (POWI)
>  DEFINE_MATH_FN (SQRT)
>  DEFINE_MATH_FN (CBRT)
>  DEFINE_MATH_FN (SIN)
> @@ -2821,6 +2822,24 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>  real_equal (value, )))
>   (cbrts @0))
>
> +/* powi(1,x) -> 1.  */
> +(simplify
> + (POWI real_onep@0 @1)
> + @0)
> +
> +(simplify
> + (POWI @0 INTEGER_CST@1)
> + (switch
> +  /* powi(x,0) -> 1.  */
> +  (if (wi::eq_p (@1, 0))
> +   { build_real (type, dconst1); })
> +  /* powi(x,1) -> x.  */
> +  (if (wi::eq_p (@1, 1))
> +   @0)
> +  /* powi(x,-1) -> 1/x.  */
> +  (if (wi::eq_p (@1, -1))
> +   (rdiv { build_real (type, dconst1); } @0
> +
>  /* Narrowing of arithmetic and logical operations.
>
> These are conceptually similar to the transformations performed for
> diff --git a/gcc/testsuite/gcc.dg/builtins-52.c 
> b/gcc/testsuite/gcc.dg/builtins-52.c
> index 684fd66..1cff017 100644
> --- a/gcc/testsuite/gcc.dg/builtins-52.c
> +++ b/gcc/testsuite/gcc.dg/builtins-52.c
> @@ -1,5 +1,5 @@
>  /* { dg-do link } */
> -/* { dg-options "-ffast-math" } */
> +/* { dg-options "-O -ffast-math" } */
>
>  extern void link_error(void);

Re: [PATCH, PR68062] Fix uniform vector operation lowering

2015-10-26 Thread Ilya Enkovich
On 26 Oct 10:56, Richard Biener wrote:
> On Mon, Oct 26, 2015 at 10:35 AM, Ilya Enkovich  
> wrote:
> > On 26 Oct 10:09, Richard Biener wrote:
> >> On Sat, Oct 24, 2015 at 12:29 AM, Ilya Enkovich  
> >> wrote:
> >> > 2015-10-24 0:32 GMT+03:00 Jeff Law :
> >> >> On 10/23/2015 09:26 AM, Ilya Enkovich wrote:
> >> >>>
> >> >>> Hi,
> >> >>>
> >> >>> This patch checks optab exists before using it vector vector statement
> >> >>> lowering.  It fixes compilation of test from PR68062 with 
> >> >>> -funsigned-char
> >> >>> option added (doesn't fix original testcase).  Bootstrapped for
> >> >>> x86_64-unknown-linux-gnu.  OK for trunk if no regressions?
> >> >>>
> >> >>> Thanks,
> >> >>> Ilya
> >> >>> --
> >> >>> gcc/
> >> >>>
> >> >>> 2015-10-23  Ilya Enkovich  
> >> >>>
> >> >>> * tree-vect-generic.c (expand_vector_operations_1): Check
> >> >>> optab exists before use it.
> >> >>>
> >> >>> gcc/testsuite/
> >> >>>
> >> >>> 2015-10-23  Ilya Enkovich  
> >> >>>
> >> >>> * g++.dg/pr68062.C: New test.
> >> >>
> >> >> OK.
> >> >>
> >> >> Just curious, what was the tree code for which we couldn't find a 
> >> >> suitable
> >> >> optab?
> >> >
> >> > Those are various comparison codes.
> >>
> >> Yeah, sorry for missing that check.  Btw, I was curious to see that we miss
> >> a way to query from optab_tag the "kind" (normal, conversion, etc.) so code
> >> can decide what optab_handler function to call (optab_handler or
> >> convert_optab_handler).  So the code I added errs on the "simplistic" side
> >> and hopes that matching lhs and rhs1 type always gets us a non-convert 
> >> optab...
> >
> > So probably better fix is
> >
> > diff --git a/gcc/tree-vect-generic.c b/gcc/tree-vect-generic.c
> > index d1fc0ba..73c5cc5 100644
> > --- a/gcc/tree-vect-generic.c
> > +++ b/gcc/tree-vect-generic.c
> > @@ -1533,7 +1533,8 @@ expand_vector_operations_1 (gimple_stmt_iterator *gsi)
> >&& TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (TREE_TYPE (srhs1)))
> >  {
> >op = optab_for_tree_code (code, TREE_TYPE (type), optab_scalar);
> > -  if (optab_handler (op, TYPE_MODE (TREE_TYPE (type))) != 
> > CODE_FOR_nothing)
> > +  if (op >= FIRST_NORM_OPTAB && op <= LAST_NORM_OPTAB
> > + && optab_handler (op, TYPE_MODE (TREE_TYPE (type))) != 
> > CODE_FOR_nothing)
> > {
> >   tree slhs = make_ssa_name (TREE_TYPE (srhs1));
> >   gimple *repl = gimple_build_assign (slhs, code, srhs1, srhs2);
> >
> > ?
> 
> Ah, didn't know we have those constants - yes, that's a better fix.
> After all we want
> optab_handler to return sth sensible for it.

I'll install it then.  Here is a version rebased on trunk.

Thanks,
Ilya
--
gcc/

2015-10-26  Ilya Enkovich  

* tree-vect-generic.c (expand_vector_operations_1): Check
optab type before using it.


diff --git a/gcc/tree-vect-generic.c b/gcc/tree-vect-generic.c
index 9c59402..a376ca2 100644
--- a/gcc/tree-vect-generic.c
+++ b/gcc/tree-vect-generic.c
@@ -1533,7 +1533,7 @@ expand_vector_operations_1 (gimple_stmt_iterator *gsi)
   && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (TREE_TYPE (srhs1)))
 {
   op = optab_for_tree_code (code, TREE_TYPE (type), optab_scalar);
-  if (op != unknown_optab
+  if (op >= FIRST_NORM_OPTAB && op <= LAST_NORM_OPTAB
  && optab_handler (op, TYPE_MODE (TREE_TYPE (type))) != 
CODE_FOR_nothing)
{
  tree slhs = make_ssa_name (TREE_TYPE (srhs1));


Re: Move expN folds to match.pd

2015-10-26 Thread Richard Biener
On Mon, Oct 26, 2015 at 10:50 AM, Richard Sandiford
 wrote:
> Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi.
> OK to install?

Ok.

Thanks,
Richard.

> Thanks,
> Richard
>
>
> gcc/
> * builtins.c (fold_builtin_exponent): Delete.
> (fold_builtin_2): Handle constant expN arguments here.
> * match.pd: Fold expN(logN(x)) -> x.
>
> diff --git a/gcc/builtins.c b/gcc/builtins.c
> index 3d39d43..e5a00ee 100644
> --- a/gcc/builtins.c
> +++ b/gcc/builtins.c
> @@ -7516,47 +7516,6 @@ fold_const_builtin_pow (tree arg0, tree arg1, tree 
> type)
>return NULL_TREE;
>  }
>
> -/* A subroutine of fold_builtin to fold the various exponent
> -   functions.  Return NULL_TREE if no simplification can be made.
> -   FUNC is the corresponding MPFR exponent function.  */
> -
> -static tree
> -fold_builtin_exponent (location_t loc, tree fndecl, tree arg,
> -  int (*func)(mpfr_ptr, mpfr_srcptr, mp_rnd_t))
> -{
> -  if (validate_arg (arg, REAL_TYPE))
> -{
> -  tree type = TREE_TYPE (TREE_TYPE (fndecl));
> -  tree res;
> -
> -  /* Calculate the result when the argument is a constant.  */
> -  if ((res = do_mpfr_arg1 (arg, type, func, NULL, NULL, 0)))
> -   return res;
> -
> -  /* Optimize expN(logN(x)) = x.  */
> -  if (flag_unsafe_math_optimizations)
> -   {
> - const enum built_in_function fcode = builtin_mathfn_code (arg);
> -
> - if ((func == mpfr_exp
> -  && (fcode == BUILT_IN_LOG
> -  || fcode == BUILT_IN_LOGF
> -  || fcode == BUILT_IN_LOGL))
> - || (func == mpfr_exp2
> - && (fcode == BUILT_IN_LOG2
> - || fcode == BUILT_IN_LOG2F
> - || fcode == BUILT_IN_LOG2L))
> - || (func == mpfr_exp10
> - && (fcode == BUILT_IN_LOG10
> - || fcode == BUILT_IN_LOG10F
> - || fcode == BUILT_IN_LOG10L)))
> -   return fold_convert_loc (loc, type, CALL_EXPR_ARG (arg, 0));
> -   }
> -}
> -
> -  return NULL_TREE;
> -}
> -
>  /* Fold function call to builtin memchr.  ARG1, ARG2 and LEN are the
> arguments to the call, and TYPE is its return type.
> Return NULL_TREE if no simplification can be made.  */
> @@ -9004,14 +8963,20 @@ fold_builtin_1 (location_t loc, tree fndecl, tree 
> arg0)
>  break;
>
>  CASE_FLT_FN (BUILT_IN_EXP):
> -  return fold_builtin_exponent (loc, fndecl, arg0, mpfr_exp);
> +  if (validate_arg (arg0, REAL_TYPE))
> +   return do_mpfr_arg1 (arg0, type, mpfr_exp, NULL, NULL, 0);
> +  break;
>
>  CASE_FLT_FN (BUILT_IN_EXP2):
> -  return fold_builtin_exponent (loc, fndecl, arg0, mpfr_exp2);
> +  if (validate_arg (arg0, REAL_TYPE))
> +   return do_mpfr_arg1 (arg0, type, mpfr_exp2, NULL, NULL, 0);
> +  break;
>
>  CASE_FLT_FN (BUILT_IN_EXP10):
>  CASE_FLT_FN (BUILT_IN_POW10):
> -  return fold_builtin_exponent (loc, fndecl, arg0, mpfr_exp10);
> +  if (validate_arg (arg0, REAL_TYPE))
> +   return do_mpfr_arg1 (arg0, type, mpfr_exp10, NULL, NULL, 0);
> +  break;
>
>  CASE_FLT_FN (BUILT_IN_EXPM1):
>if (validate_arg (arg0, REAL_TYPE))
> diff --git a/gcc/match.pd b/gcc/match.pd
> index a8adffb..303889b 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -2408,12 +2408,16 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
> (rdiv @0 (exps:s @1))
>  (mult @0 (exps (negate @1)
>
> - /* Special case, optimize logN(expN(x)) = x.  */
>   (for logs (LOG LOG2 LOG10 LOG10)
>exps (EXP EXP2 EXP10 POW10)
> +  /* logN(expN(x)) -> x.  */
>(simplify
> (logs (exps @0))
> -@0))
> +   @0)
> +  /* expN(logN(x)) -> x.  */
> +  (simplify
> +   (exps (logs @0))
> +   @0))
>
>   /* Optimize logN(func()) for various exponential functions.  We
>  want to determine the value "x" and the power "exponent" in
>


Re: Move copysign folds to match.pd

2015-10-26 Thread Richard Biener
On Mon, Oct 26, 2015 at 10:54 AM, Richard Sandiford
 wrote:
> Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi.
> OK to install?

Ok.

Thanks,
Richard.

> Thanks,
> Richard
>
>
> gcc/
> * builtins.c (fold_builtin_copysign): Delete.
> (fold_builtin_2): Handle constant copysign arguments here.
> * match.pd: Add rules previously handled by fold_builtin_copysign.
>
> diff --git a/gcc/builtins.c b/gcc/builtins.c
> index ae7e7ef..ed0030d 100644
> --- a/gcc/builtins.c
> +++ b/gcc/builtins.c
> @@ -7781,46 +7781,6 @@ fold_builtin_strncmp (location_t loc, tree arg1, tree 
> arg2, tree len)
>return NULL_TREE;
>  }
>
> -/* Fold function call to builtin copysign, copysignf or copysignl with
> -   arguments ARG1 and ARG2.  Return NULL_TREE if no simplification can
> -   be made.  */
> -
> -static tree
> -fold_builtin_copysign (location_t loc, tree arg1, tree arg2, tree type)
> -{
> -  if (!validate_arg (arg1, REAL_TYPE)
> -  || !validate_arg (arg2, REAL_TYPE))
> -return NULL_TREE;
> -
> -  /* copysign(X,X) is X.  */
> -  if (operand_equal_p (arg1, arg2, 0))
> -return fold_convert_loc (loc, type, arg1);
> -
> -  /* If ARG1 and ARG2 are compile-time constants, determine the result.  */
> -  if (TREE_CODE (arg1) == REAL_CST
> -  && TREE_CODE (arg2) == REAL_CST
> -  && !TREE_OVERFLOW (arg1)
> -  && !TREE_OVERFLOW (arg2))
> -{
> -  REAL_VALUE_TYPE c1, c2;
> -
> -  c1 = TREE_REAL_CST (arg1);
> -  c2 = TREE_REAL_CST (arg2);
> -  /* c1.sign := c2.sign.  */
> -  real_copysign (, );
> -  return build_real (type, c1);
> -}
> -
> -  /* copysign(X, Y) is fabs(X) when Y is always non-negative.
> - Remember to evaluate Y for side-effects.  */
> -  if (tree_expr_nonnegative_p (arg2))
> -return omit_one_operand_loc (loc, type,
> -fold_build1_loc (loc, ABS_EXPR, type, arg1),
> -arg2);
> -
> -  return NULL_TREE;
> -}
> -
>  /* Fold a call to builtin isascii with argument ARG.  */
>
>  static tree
> @@ -9278,7 +9238,16 @@ fold_builtin_2 (location_t loc, tree fndecl, tree 
> arg0, tree arg1)
>break;
>
>  CASE_FLT_FN (BUILT_IN_COPYSIGN):
> -  return fold_builtin_copysign (loc, arg0, arg1, type);
> +  if (TREE_CODE (arg0) == REAL_CST
> + && TREE_CODE (arg1) == REAL_CST
> + && !TREE_OVERFLOW (arg0)
> + && !TREE_OVERFLOW (arg1))
> +   {
> + REAL_VALUE_TYPE c1 = TREE_REAL_CST (arg0);
> + real_copysign (, TREE_REAL_CST_PTR (arg1));
> + return build_real (type, c1);
> +   }
> +  break;
>
>  CASE_FLT_FN (BUILT_IN_FMIN):
>return fold_builtin_fmin_fmax (loc, arg0, arg1, type, /*max=*/false);
> diff --git a/gcc/match.pd b/gcc/match.pd
> index e50f5bb..e02379f 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -2541,6 +2541,16 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>   (POW real_onep@0 @1)
>   @0)
>
> +(simplify
> + /* copysign(x,x) -> x.  */
> + (COPYSIGN @0 @0)
> + @0)
> +
> +(simplify
> + /* copysign(x,y) -> fabs(x) if y is nonnegative.  */
> + (COPYSIGN @0 tree_expr_nonnegative_p@1)
> + (abs @0))
> +
>  /* Canonicalization of sequences of math builtins.  These rules represent
> IL simplifications but are not necessarily optimizations.
>
>


Re: Remove constant handling from fold_builtin_{,f}abs

2015-10-26 Thread Richard Biener
On Mon, Oct 26, 2015 at 10:56 AM, Richard Sandiford
 wrote:
> fold_builtin_fabs and fold_builtin_abs had code to handle constant
> arguments, but this simply duplicated what the following fold_build1_loc
> would do for ABS_EXPR.
>
> Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi.
> OK to install?

Ok.

Thanks,
Richard.

> Thanks,
> Richard
>
>
> gcc/
> * builtins.c (fold_builtin_fabs): Remove constant handling.
> (fold_builtin_abs): Likewise.
>
> diff --git a/gcc/builtins.c b/gcc/builtins.c
> index ed0030d..a03dffc 100644
> --- a/gcc/builtins.c
> +++ b/gcc/builtins.c
> @@ -7847,8 +7847,6 @@ fold_builtin_fabs (location_t loc, tree arg, tree type)
>  return NULL_TREE;
>
>arg = fold_convert_loc (loc, type, arg);
> -  if (TREE_CODE (arg) == REAL_CST)
> -return fold_abs_const (arg, type);
>return fold_build1_loc (loc, ABS_EXPR, type, arg);
>  }
>
> @@ -7861,8 +7859,6 @@ fold_builtin_abs (location_t loc, tree arg, tree type)
>  return NULL_TREE;
>
>arg = fold_convert_loc (loc, type, arg);
> -  if (TREE_CODE (arg) == INTEGER_CST)
> -return fold_abs_const (arg, type);
>return fold_build1_loc (loc, ABS_EXPR, type, arg);
>  }
>
>


[Committed] Inline get_vi_for_tree into intra_create_variable_infos

2015-10-26 Thread Tom de Vries

Hi,

this no-functional-changes patch inlines get_vi_for_tree into 
intra_create_variable_infos.


It exposes the interaction with create_variable_info_for_1, and makes it 
clear that we're using none of the constraint handling from 
create_variable_info_for.


Bootstrapped and reg-tested on x86_64.

Committed as trivial.

Thanks,
- Tom
Inline get_vi_for_tree into intra_create_variable_infos

2015-10-24  Tom de Vries  

	* tree-ssa-structalias.c (intra_create_variable_infos): Inline
	get_vi_for_tree call.
---
 gcc/tree-ssa-structalias.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/gcc/tree-ssa-structalias.c b/gcc/tree-ssa-structalias.c
index 66a04b2..c5a7e2a 100644
--- a/gcc/tree-ssa-structalias.c
+++ b/gcc/tree-ssa-structalias.c
@@ -5857,7 +5857,12 @@ intra_create_variable_infos (struct function *fn)
  passed-by-reference argument.  */
   for (t = DECL_ARGUMENTS (fn->decl); t; t = DECL_CHAIN (t))
 {
-  varinfo_t p = get_vi_for_tree (t);
+  varinfo_t p = lookup_vi_for_tree (t);
+  if (p == NULL)
+	{
+	  p = create_variable_info_for_1 (t, alias_get_name (t));
+	  insert_vi_for_tree (t, p);
+	}
 
   /* For restrict qualified pointers build a representative for
 	 the pointed-to object.  Note that this ends up handling
-- 
1.9.1



[Ada] Pragma Volatile_Function has no effect on subprogram body

2015-10-26 Thread Arnaud Charlet
This patch modifies the analysis of pragmas that appear on package specs and
and subprogram bodies. The new model of analysis allows for pragmas to appear
out of order, but they are still analyzed according to internal precedence. The
patch removes the restrictions concerning the declarations order of pragmas
Abstract_State, Initial_Condition and Initializes.


-- Source --


--  vol_funcs.ads

package Vol_Funcs with SPARK_Mode is
   type Int is new Natural range 0 .. 5 with Volatile;

   type Rec is record
  Comp : Natural := 0;
   end record with Volatile;

   Int_Obj : Int with Volatile;
   Rec_Obj : Rec with Volatile;

   --  Completion by subprogram body

   function Func_1_Int (Val : Int) return Boolean
 with Volatile_Function;

   function Func_1_Rec (Val : Rec) return Boolean
 with Volatile_Function;

   --  Completion by expression function

   function Func_2_Int (Val : Int) return Boolean
 with Volatile_Function;

   function Func_2_Rec (Val : Rec) return Boolean
 with Volatile_Function;

   --  Stand alone expression function (no completion required)

   function Func_3_Int (Val : Int) return Boolean is (True)
 with Volatile_Function;

   function Func_3_Rec (Val : Rec) return Boolean is (True)
 with Volatile_Function;
end Vol_Funcs;

--  vol_funcs.adb

package body Vol_Funcs with SPARK_Mode is

   --  Completion by subprogram body

   function Func_1_Int (Val : Int) return Boolean is
   begin return True; end Func_1_Int;

   function Func_1_Rec (Val : Rec) return Boolean is
   begin return True; end Func_1_Rec;

   --  Completion by expression function

   function Func_2_Int (Val : Int) return Boolean is
   begin return True; end Func_2_Int;

   function Func_2_Rec (Val : Rec) return Boolean is
   begin return True; end Func_2_Rec;

   --  Stand alone subprogram body (no initial declaration)

   function Func_4_Int (Val : Int) return Boolean
 with Volatile_Function
   is begin return True; end Func_4_Int;

   function Func_4_Rec (Val : Rec) return Boolean
 with Volatile_Function
   is begin return True; end Func_4_Rec;

   Status : Boolean;

begin
   Status := Func_1_Int (Int_Obj);   --  Error
   Status := Func_1_Rec (Rec_Obj);   --  OK
   Status := Func_2_Int (Int_Obj);   --  Error
   Status := Func_2_Rec (Rec_Obj);   --  OK
   Status := Func_3_Int (Int_Obj);   --  Error
   Status := Func_3_Rec (Rec_Obj);   --  OK
   Status := Func_4_Int (Int_Obj);   --  Error
   Status := Func_4_Rec (Rec_Obj);   --  OK
end Vol_Funcs;


-- Compilation and output --


$ gcc -c vol_funcs.adb
vol_funcs.adb:32:26: volatile object cannot act as actual in a call (SPARK RM
  7.1.3(12))
vol_funcs.adb:34:26: volatile object cannot act as actual in a call (SPARK RM
  7.1.3(12))
vol_funcs.adb:36:26: volatile object cannot act as actual in a call (SPARK RM
  7.1.3(12))
vol_funcs.adb:38:26: volatile object cannot act as actual in a call (SPARK RM
  7.1.3(12))

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

2015-10-26  Hristian Kirtchev  

* sem_ch13.adb (Analyze_Aspect_Specifications): The processing
for aspects Abstract_State, Ghost, Initial_Condition, Initializes
and Refined_State no longer have to take SPARK_Mode into account.
(Insert_After_SPARK_Mode): Removed.
(Insert_Pragma): Update profile and comment on usage. The routine can
now insert a pragma after the "header" of an instance.
* sem_prag.adb (Analyze_If_Available): New routine.
(Analyze_Pragma): Do not reset the Analyzed flag of various
SPARK pragmas as they use the Is_Analyzed_Pragma attribute to
avoid reanalysis. Various pragmas now trigger the analysis
of related pragmas that depend on or are dependent on the
current pragma. Remove the declaration order checks related
to pragmas Abstract_State, Initial_Condition and Initializes.
(Analyze_Pre_Post_Condition): Analyze pragmas SPARK_Mode and
Volatile_Function prior to analyzing the pre/postcondition.
(Check_Declaration_Order): Removed.
(Check_Distinct_Name): Ensure that a potentially duplicated pragma
Test_Case is not the pragma being analyzed.
(Is_Followed_By_Pragma): Removed.

Index: sem_prag.adb
===
--- sem_prag.adb(revision 229330)
+++ sem_prag.adb(working copy)
@@ -2760,6 +2760,10 @@
   --  is the entity of the related subprogram. Subp_Decl is the declaration
   --  of the related subprogram. Sets flag Legal when the pragma is legal.
 
+  procedure Analyze_If_Present (Id : 

[PATCH, 1/2] Add handle_param parameter to create_variable_info_for_1

2015-10-26 Thread Tom de Vries

Hi,

this no-functional-changes patch copies the restrict var declaration 
code from intra_create_variable_infos to create_variable_info_for_1.


The code was copied rather than moved, since in fipa-pta mode the 
varinfo p for the parameter t may already exist due to 
create_function_info_for, in which case we're not calling 
create_variable_info_for_1 to set p, meaning the copied code won't get 
triggered.


Bootstrapped and reg-tested on x86_64.

OK for trunk?

Thanks,
- Tom
Add handle_param parameter to create_variable_info_for_1

2015-10-26  Tom de Vries  

	* tree-ssa-structalias.c (struct variable_info): Add
	restrict_pointed_var field.
	(create_variable_info_for_1): Add and handle handle_param parameter.
	(create_variable_info_for): Call create_variable_info_for_1 with extra
	arg.
	(intra_create_variable_infos): Same.  Handle case that
	p->restrict_pointed_var is unequal zero.
---
 gcc/tree-ssa-structalias.c | 40 ++--
 1 file changed, 30 insertions(+), 10 deletions(-)

diff --git a/gcc/tree-ssa-structalias.c b/gcc/tree-ssa-structalias.c
index 63a3d02..3fdad3a 100644
--- a/gcc/tree-ssa-structalias.c
+++ b/gcc/tree-ssa-structalias.c
@@ -272,6 +272,9 @@ struct variable_info
   /* True if this field has only restrict qualified pointers.  */
   unsigned int only_restrict_pointers : 1;
 
+  /* The id of the pointed-to restrict var in case only_restrict_pointers.  */
+  unsigned int restrict_pointed_var;
+
   /* True if this represents a heap var created for a restrict qualified
  pointer.  */
   unsigned int is_restrict_var : 1;
@@ -5608,10 +5611,10 @@ check_for_overlaps (vec fieldstack)
 
 /* Create a varinfo structure for NAME and DECL, and add it to VARMAP.
This will also create any varinfo structures necessary for fields
-   of DECL.  */
+   of DECL.  DECL is a function parameter if HANDLE_PARAM is set.  */
 
 static varinfo_t
-create_variable_info_for_1 (tree decl, const char *name)
+create_variable_info_for_1 (tree decl, const char *name, bool handle_param)
 {
   varinfo_t vi, newvi;
   tree decl_type = TREE_TYPE (decl);
@@ -5687,6 +5690,17 @@ create_variable_info_for_1 (tree decl, const char *name)
   if (POINTER_TYPE_P (TREE_TYPE (decl))
 	  && TYPE_RESTRICT (TREE_TYPE (decl)))
 	vi->only_restrict_pointers = 1;
+  if (vi->only_restrict_pointers
+	  && handle_param)
+	{
+	  varinfo_t rvi;
+	  tree heapvar = build_fake_var_decl (TREE_TYPE (decl_type));
+	  DECL_EXTERNAL (heapvar) = 1;
+	  rvi = create_variable_info_for_1 (heapvar, "PARM_NOALIAS", false);
+	  rvi->is_restrict_var = 1;
+	  insert_vi_for_tree (heapvar, rvi);
+	  vi->restrict_pointed_var = rvi->id;
+	}
   fieldstack.release ();
   return vi;
 }
@@ -5738,7 +5752,7 @@ create_variable_info_for_1 (tree decl, const char *name)
 static unsigned int
 create_variable_info_for (tree decl, const char *name)
 {
-  varinfo_t vi = create_variable_info_for_1 (decl, name);
+  varinfo_t vi = create_variable_info_for_1 (decl, name, false);
   unsigned int id = vi->id;
 
   insert_vi_for_tree (decl, vi);
@@ -5880,7 +5894,8 @@ intra_create_variable_infos (struct function *fn)
   varinfo_t p = lookup_vi_for_tree (t);
   if (p == NULL)
 	{
-	  p = create_variable_info_for_1 (t, alias_get_name (t));
+	  p = create_variable_info_for_1 (t, alias_get_name (t),
+	  recursive_restrict_p);
 	  insert_vi_for_tree (t, p);
 	}
 
@@ -5890,12 +5905,17 @@ intra_create_variable_infos (struct function *fn)
 	 in the first/last subfield of the object.  */
   if (recursive_restrict_p)
 	{
-	  varinfo_t vi;
-	  tree heapvar = build_fake_var_decl (TREE_TYPE (TREE_TYPE (t)));
-	  DECL_EXTERNAL (heapvar) = 1;
-	  vi = create_variable_info_for_1 (heapvar, "PARM_NOALIAS");
-	  vi->is_restrict_var = 1;
-	  insert_vi_for_tree (heapvar, vi);
+	  varinfo_t vi = get_varinfo (p->restrict_pointed_var);
+	  if (vi == NULL)
+	{
+	  tree heapvar = build_fake_var_decl (TREE_TYPE (TREE_TYPE (t)));
+	  DECL_EXTERNAL (heapvar) = 1;
+	  vi = create_variable_info_for_1 (heapvar, "PARM_NOALIAS", false);
+	  vi->is_restrict_var = 1;
+	  insert_vi_for_tree (heapvar, vi);
+	  p->restrict_pointed_var = vi->id;
+	  p->only_restrict_pointers = 1;
+	}
 	  make_constraint_from (p, vi->id);
 	  make_restrict_var_constraints (vi);
 	  continue;
-- 
1.9.1



[PATCH, 2/2] Handle recursive restrict pointer in create_variable_info_for_1

2015-10-26 Thread Tom de Vries

Hi,

this patch enables recursive restrict handling in 
create_variable_info_for_1.


This allows us to interpret all restricts in a function parameter
"int *restrict *restrict *restrict a".

This patch is the first step towards implementing a generic fix for PR67742.

Bootstrapped and reg-tested on x86_64.

OK for trunk?

Thanks,
- Tom
Handle recursive restrict pointer in create_variable_info_for_1

2015-10-26  Tom de Vries  

	* tree-ssa-structalias.c (create_variable_info_for_1): Enable recursive
	handling of restrict pointers.
	(make_restrict_var_constraints): Handle restrict vars recursively.

	* gcc.dg/tree-ssa/restrict-7.c: New test.
---
 gcc/testsuite/gcc.dg/tree-ssa/restrict-7.c | 12 
 gcc/tree-ssa-structalias.c | 13 +++--
 2 files changed, 23 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/restrict-7.c

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/restrict-7.c b/gcc/testsuite/gcc.dg/tree-ssa/restrict-7.c
new file mode 100644
index 000..f7a68c7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/restrict-7.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-fre1" } */
+
+int
+f (int *__restrict__ *__restrict__ *__restrict__ a, int *b)
+{
+  *b = 1;
+  ***a  = 2;
+  return *b;
+}
+
+/* { dg-final { scan-tree-dump-times "return 1" 1 "fre1" } } */
diff --git a/gcc/tree-ssa-structalias.c b/gcc/tree-ssa-structalias.c
index 3fdad3a..3839f67 100644
--- a/gcc/tree-ssa-structalias.c
+++ b/gcc/tree-ssa-structalias.c
@@ -5696,7 +5696,7 @@ create_variable_info_for_1 (tree decl, const char *name, bool handle_param)
 	  varinfo_t rvi;
 	  tree heapvar = build_fake_var_decl (TREE_TYPE (decl_type));
 	  DECL_EXTERNAL (heapvar) = 1;
-	  rvi = create_variable_info_for_1 (heapvar, "PARM_NOALIAS", false);
+	  rvi = create_variable_info_for_1 (heapvar, "PARM_NOALIAS", true);
 	  rvi->is_restrict_var = 1;
 	  insert_vi_for_tree (heapvar, rvi);
 	  vi->restrict_pointed_var = rvi->id;
@@ -5867,7 +5867,16 @@ make_restrict_var_constraints (varinfo_t vi)
 if (vi->may_have_pointers)
   {
 	if (vi->only_restrict_pointers)
-	  make_constraint_from_global_restrict (vi, "GLOBAL_RESTRICT");
+	  {
+	varinfo_t rvi = get_varinfo (vi->restrict_pointed_var);
+	if (rvi != NULL)
+	  {
+		make_constraint_from (vi, rvi->id);
+		make_restrict_var_constraints (rvi);
+	  }
+	else
+	  make_constraint_from_global_restrict (vi, "GLOBAL_RESTRICT");
+	  }
 	else
 	  make_copy_constraint (vi, nonlocal_id);
   }
-- 
1.9.1



[PATCH] Fix PR68087

2015-10-26 Thread Markus Trippelsdorf
Hi,

the patch below fixes PR68087, an ICE caused by referring to a negative
constexpr array element.

Bootstrapped and tested on ppc64le.
OK for trunk?

gcc-5 also needs a slightly different fix. I'll post that as a
follow-up, once this one gets approved.

PR c++/68087
* constexpr.c (cxx_eval_array_reference): Guard call to
tree_to_shwi().

diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index ebca411b3eb4..0828a90b0e75 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -1782,8 +1782,7 @@ cxx_eval_array_reference (const constexpr_ctx *ctx, tree 
t,
   gcc_unreachable ();
 }
 
-  i = tree_to_shwi (index);
-  if (i < 0)
+  if (!tree_fits_shwi_p (index) || tree_to_shwi (index) < 0)
 {
   if (!ctx->quiet)
error ("negative array subscript");
@@ -1792,6 +1791,7 @@ cxx_eval_array_reference (const constexpr_ctx *ctx, tree 
t,
 }
 
   bool found;
+  i = tree_to_shwi (index);
   if (TREE_CODE (ary) == CONSTRUCTOR)
 {
   HOST_WIDE_INT ix = find_array_ctor_elt (ary, index);
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-array13.C 
b/gcc/testsuite/g++.dg/cpp0x/constexpr-array13.C
new file mode 100644
index ..ef18a60f3038
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-array13.C
@@ -0,0 +1,7 @@
+// PR c++/68087
+// { dg-do compile { target c++11 } }
+
+constexpr char c[] = "hello";
+constexpr const char *p = c;
+
+static_assert(*(p - 1) == 'h', ""); // { dg-error "non-constant|negative" }
-- 
Markus


[patch committed SH] Fix PR target/68091

2015-10-26 Thread Kaz Kojima
I've applied the attached one liner as a quick fix for PR target/68091
which is a 6 regression.  sh_vector_mode_supported_p returns true even
if the target has no mov insns for some vector modes and causes ICEs
for several vector tests.  Tested on sh4-unknown-linux-gnu.

Regards,
kaz
--
2015-10-26  Kaz Kojima  

PR target/68091
* config/sh/sh.c (sh_vector_mode_supported_p): Use
TARGET_SHMEDIA_FPU instead of TARGET_FPU_ANY.

diff --git a/gcc/config/sh/sh.c b/gcc/config/sh/sh.c
index f8187e4..a153845 100644
--- a/gcc/config/sh/sh.c
+++ b/gcc/config/sh/sh.c
@@ -12133,7 +12133,7 @@ sh_atomic_assign_expand_fenv (tree *hold, tree *clear, 
tree *update)
 bool
 sh_vector_mode_supported_p (machine_mode mode)
 {
-  if (TARGET_FPU_ANY
+  if (TARGET_SHMEDIA_FPU
   && ((mode == V2SFmode)
  || (mode == V4SFmode)
  || (mode == V16SFmode)))


Re: [PATCH] c/67882 - improve -Warray-bounds for invalid offsetof

2015-10-26 Thread Bernd Schmidt

On 10/23/2015 10:40 PM, Martin Sebor wrote:


The original code deliberately avoids diagnosing the case of last
array members with bounds greater than 1 (see the comment about
"a poor man's flexible array member" added with a fix for bug
41935) and I didn't want to change that.


Jakub added that, Cc'd. Do you recall why this was done?


But if there is sentiment for tightening it up I would be very
much in favor.


I'd be in favor, but this is Joseph's call really.


Bernd


Re: Drop types_compatible_p from operand_equal_p

2015-10-26 Thread Richard Biener
On Sat, 24 Oct 2015, Jan Hubicka wrote:

> Hi, as discussed earlier, the types_compatible_p in operand_equal_p 
> seems redundant. (it is callers work to figure out how much of type 
> matching it wants.  If not, we probably want to treat most of other 
> references and casts simlar way).
> 
> Bootstrapped/regtested x86_64-linux. OK?

Ok.

Btw, you need to audit tree hashing for required changes with respect
to your ones to operand_equal_p.  operand_equal_p is the equality
function for it.

Thanks,
Richard.

>   * fold-const.c (operand_equal_p): Drop types_compatible_p when
>   comparing references.
> 
> Index: fold-const.c
> ===
> --- fold-const.c  (revision 229278)
> +++ fold-const.c  (working copy)
> @@ -2982,9 +2982,6 @@ operand_equal_p (const_tree arg0, const_
>  TYPE_SIZE (TREE_TYPE (arg1)),
>  flags)))
>   return 0;
> -   /* Verify that access happens in similar types.  */
> -   if (!types_compatible_p (TREE_TYPE (arg0), TREE_TYPE (arg1)))
> - return 0;
> /* Verify that accesses are TBAA compatible.  */
> if (flag_strict_aliasing
> && (!alias_ptr_types_compatible_p
> 
> 

-- 
Richard Biener 
SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 
21284 (AG Nuernberg)


[PATCH]Add -fprofile-use option for check_effective_target_freorder.

2015-10-26 Thread Renlin Li

Hi all,

After r228136, flag_reorder_blocks_and_partition is canceled when 
-fprofile-use is not specified.


In this case check_effective_target_freorder() is not able to check the 
proper target support.
This is a simple patch to add "-fprofile-use" option that effective 
target check.


Okay to commit on the trunk?

Regards,
Renlin Li

gcc/testsuite/ChangeLog:

2015-10-26  Renlin Li  

* lib/target-supports.exp (check_effective_target_freorder): Add
-fprofile-use flag.
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index b543519..0dc13be 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -960,11 +960,12 @@ proc check_effective_target_fstack_protector {} {
 
 # Return 1 if compilation with -freorder-blocks-and-partition is error-free
 # for trivial code, 0 otherwise.
+# -freorder-blocks-and-partition has no effect if given without -fprofile-use.
 
 proc check_effective_target_freorder {} {
 return [check_no_compiler_messages freorder object {
 	void foo (void) { }
-} "-freorder-blocks-and-partition"]
+} "-freorder-blocks-and-partition -fprofile-use"]
 }
 
 # Return 1 if -fpic and -fPIC are supported, as in no warnings or errors


Move expN folds to match.pd

2015-10-26 Thread Richard Sandiford
Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi.
OK to install?

Thanks,
Richard


gcc/
* builtins.c (fold_builtin_exponent): Delete.
(fold_builtin_2): Handle constant expN arguments here.
* match.pd: Fold expN(logN(x)) -> x.

diff --git a/gcc/builtins.c b/gcc/builtins.c
index 3d39d43..e5a00ee 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -7516,47 +7516,6 @@ fold_const_builtin_pow (tree arg0, tree arg1, tree type)
   return NULL_TREE;
 }
 
-/* A subroutine of fold_builtin to fold the various exponent
-   functions.  Return NULL_TREE if no simplification can be made.
-   FUNC is the corresponding MPFR exponent function.  */
-
-static tree
-fold_builtin_exponent (location_t loc, tree fndecl, tree arg,
-  int (*func)(mpfr_ptr, mpfr_srcptr, mp_rnd_t))
-{
-  if (validate_arg (arg, REAL_TYPE))
-{
-  tree type = TREE_TYPE (TREE_TYPE (fndecl));
-  tree res;
-
-  /* Calculate the result when the argument is a constant.  */
-  if ((res = do_mpfr_arg1 (arg, type, func, NULL, NULL, 0)))
-   return res;
-
-  /* Optimize expN(logN(x)) = x.  */
-  if (flag_unsafe_math_optimizations)
-   {
- const enum built_in_function fcode = builtin_mathfn_code (arg);
-
- if ((func == mpfr_exp
-  && (fcode == BUILT_IN_LOG
-  || fcode == BUILT_IN_LOGF
-  || fcode == BUILT_IN_LOGL))
- || (func == mpfr_exp2
- && (fcode == BUILT_IN_LOG2
- || fcode == BUILT_IN_LOG2F
- || fcode == BUILT_IN_LOG2L))
- || (func == mpfr_exp10
- && (fcode == BUILT_IN_LOG10
- || fcode == BUILT_IN_LOG10F
- || fcode == BUILT_IN_LOG10L)))
-   return fold_convert_loc (loc, type, CALL_EXPR_ARG (arg, 0));
-   }
-}
-
-  return NULL_TREE;
-}
-
 /* Fold function call to builtin memchr.  ARG1, ARG2 and LEN are the
arguments to the call, and TYPE is its return type.
Return NULL_TREE if no simplification can be made.  */
@@ -9004,14 +8963,20 @@ fold_builtin_1 (location_t loc, tree fndecl, tree arg0)
 break;
 
 CASE_FLT_FN (BUILT_IN_EXP):
-  return fold_builtin_exponent (loc, fndecl, arg0, mpfr_exp);
+  if (validate_arg (arg0, REAL_TYPE))
+   return do_mpfr_arg1 (arg0, type, mpfr_exp, NULL, NULL, 0);
+  break;
 
 CASE_FLT_FN (BUILT_IN_EXP2):
-  return fold_builtin_exponent (loc, fndecl, arg0, mpfr_exp2);
+  if (validate_arg (arg0, REAL_TYPE))
+   return do_mpfr_arg1 (arg0, type, mpfr_exp2, NULL, NULL, 0);
+  break;
 
 CASE_FLT_FN (BUILT_IN_EXP10):
 CASE_FLT_FN (BUILT_IN_POW10):
-  return fold_builtin_exponent (loc, fndecl, arg0, mpfr_exp10);
+  if (validate_arg (arg0, REAL_TYPE))
+   return do_mpfr_arg1 (arg0, type, mpfr_exp10, NULL, NULL, 0);
+  break;
 
 CASE_FLT_FN (BUILT_IN_EXPM1):
   if (validate_arg (arg0, REAL_TYPE))
diff --git a/gcc/match.pd b/gcc/match.pd
index a8adffb..303889b 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -2408,12 +2408,16 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(rdiv @0 (exps:s @1))
 (mult @0 (exps (negate @1)
 
- /* Special case, optimize logN(expN(x)) = x.  */
  (for logs (LOG LOG2 LOG10 LOG10)
   exps (EXP EXP2 EXP10 POW10)
+  /* logN(expN(x)) -> x.  */
   (simplify
(logs (exps @0))
-@0))
+   @0)
+  /* expN(logN(x)) -> x.  */
+  (simplify
+   (exps (logs @0))
+   @0))
 
  /* Optimize logN(func()) for various exponential functions.  We
 want to determine the value "x" and the power "exponent" in



Re: Move hypot folds to match.pd

2015-10-26 Thread Richard Biener
On Mon, Oct 26, 2015 at 10:38 AM, Richard Sandiford
 wrote:
> Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi.
> OK to install?

Ok.

Thanks,
Richard.

> Thanks,
> Richard
>
>
> gcc/
> * builtins.c (fold_builtin_hypot): Delete.
> (fold_builtin_2): Handle constant hypot arguments here.
> * match.pd: Fold hypot(x, 0) and hypot(0, x) to x.  Canonicalize
> hypot(x, x) to fabs(x)*sqrt(2).
>
> diff --git a/gcc/builtins.c b/gcc/builtins.c
> index f947f1e..64106a1 100644
> --- a/gcc/builtins.c
> +++ b/gcc/builtins.c
> @@ -7475,39 +7475,6 @@ fold_builtin_bswap (tree fndecl, tree arg)
>return NULL_TREE;
>  }
>
> -/* Fold a builtin function call to hypot, hypotf, or hypotl.  Return
> -   NULL_TREE if no simplification can be made.  */
> -
> -static tree
> -fold_builtin_hypot (location_t loc, tree arg0, tree arg1, tree type)
> -{
> -  tree res;
> -
> -  if (!validate_arg (arg0, REAL_TYPE)
> -  || !validate_arg (arg1, REAL_TYPE))
> -return NULL_TREE;
> -
> -  /* Calculate the result when the argument is a constant.  */
> -  if ((res = do_mpfr_arg2 (arg0, arg1, type, mpfr_hypot)))
> -return res;
> -
> -  /* If either argument is zero, hypot is fabs of the other.  */
> -  if (real_zerop (arg0))
> -return fold_build1_loc (loc, ABS_EXPR, type, arg1);
> -  else if (real_zerop (arg1))
> -return fold_build1_loc (loc, ABS_EXPR, type, arg0);
> -
> -  /* hypot(x,x) -> fabs(x)*sqrt(2).  */
> -  if (flag_unsafe_math_optimizations
> -  && operand_equal_p (arg0, arg1, OEP_PURE_SAME))
> -return fold_build2_loc (loc, MULT_EXPR, type,
> -   fold_build1_loc (loc, ABS_EXPR, type, arg0),
> -   build_real_truncate (type, dconst_sqrt2 ()));
> -
> -  return NULL_TREE;
> -}
> -
> -
>  /* Fold a builtin function call to pow, powf, or powl.  Return
> NULL_TREE if no simplification can be made.  */
>  static tree
> @@ -9456,7 +9423,10 @@ fold_builtin_2 (location_t loc, tree fndecl, tree 
> arg0, tree arg1)
>  break;
>
>  CASE_FLT_FN (BUILT_IN_HYPOT):
> -  return fold_builtin_hypot (loc, arg0, arg1, type);
> +  if (validate_arg (arg0, REAL_TYPE)
> + && validate_arg (arg1, REAL_TYPE))
> +   return do_mpfr_arg2 (arg0, arg1, type, mpfr_hypot);
> +  break;
>
>  CASE_FLT_FN (BUILT_IN_CPOW):
>if (validate_arg (arg0, COMPLEX_TYPE)
> diff --git a/gcc/match.pd b/gcc/match.pd
> index 00c6e7c..8cd55f6 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -2520,6 +2520,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>(RINT integer_valued_real_p@0)
>@0))
>
> +/* hypot(x,0) and hypot(0,x) -> abs(x).  */
> +(simplify
> + (hypot:c @0 real_zerop@1)
> + (abs @0))
> +
>  /* Canonicalization of sequences of math builtins.  These rules represent
> IL simplifications but are not necessarily optimizations.
>
> @@ -2618,6 +2623,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>(CABS (complex @0 @0))
>(mult (abs @0) { build_real_truncate (type, dconst_sqrt2 ()); }))
>
> + /* hypot(x,x) -> fabs(x)*sqrt(2).  */
> + (simplify
> +  (HYPOT @0 @0)
> +  (mult (abs @0) { build_real_truncate (type, dconst_sqrt2 ()); }))
> +
>   /* cexp(x+yi) -> exp(x)*cexpi(y).  */
>   (for cexps (CEXP)
>exps (EXP)
>


Re: [OpenACC 4/11] C FE changes

2015-10-26 Thread Jakub Jelinek
On Mon, Oct 26, 2015 at 09:59:49AM +0100, Jakub Jelinek wrote:
> Ok for trunk with those changes fixed.

Oops, I've missed that there is no checking of the type (that the
expressions have INTEGRAL_TYPE_P); in the C FE, this is sometimes done
already during the parsing, sometimes during c_finish_omp_clauses.

Jakub


Re: Move pow folds to match.pd

2015-10-26 Thread Richard Biener
On Mon, Oct 26, 2015 at 10:44 AM, Richard Sandiford
 wrote:
> Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi.
> OK to install?

Ok.

Thanks,
Richard.

> Thanks,
> Richard
>
>
> gcc/
> * builtins.c (fold_builtin_pow): Delete in favor of...
> (fold_const_builtin_pow): ...this new function.  Only handle constant
> arguments.
> (fold_builtin_2): Update accordingly.
> * match.pd: Add rules previously handled by fold_builtin_pow.
>
> gcc/testsuite/
> * gcc.dg/torture/builtin-math-1.c: Skip at -O0.
>
> diff --git a/gcc/builtins.c b/gcc/builtins.c
> index 64106a1..88c0576 100644
> --- a/gcc/builtins.c
> +++ b/gcc/builtins.c
> @@ -156,7 +156,6 @@ static tree rewrite_call_expr (location_t, tree, int, 
> tree, int, ...);
>  static bool validate_arg (const_tree, enum tree_code code);
>  static rtx expand_builtin_fabs (tree, rtx, rtx);
>  static rtx expand_builtin_signbit (tree, rtx);
> -static tree fold_builtin_pow (location_t, tree, tree, tree, tree);
>  static tree fold_builtin_powi (location_t, tree, tree, tree, tree);
>  static tree fold_builtin_bitop (tree, tree);
>  static tree fold_builtin_strchr (location_t, tree, tree, tree);
> @@ -7478,7 +7477,7 @@ fold_builtin_bswap (tree fndecl, tree arg)
>  /* Fold a builtin function call to pow, powf, or powl.  Return
> NULL_TREE if no simplification can be made.  */
>  static tree
> -fold_builtin_pow (location_t loc, tree fndecl, tree arg0, tree arg1, tree 
> type)
> +fold_const_builtin_pow (tree arg0, tree arg1, tree type)
>  {
>tree res;
>
> @@ -7490,127 +7489,28 @@ fold_builtin_pow (location_t loc, tree fndecl, tree 
> arg0, tree arg1, tree type)
>if ((res = do_mpfr_arg2 (arg0, arg1, type, mpfr_pow)))
>  return res;
>
> -  /* Optimize pow(1.0,y) = 1.0.  */
> -  if (real_onep (arg0))
> -return omit_one_operand_loc (loc, type, build_real (type, dconst1), 
> arg1);
> -
> -  if (TREE_CODE (arg1) == REAL_CST
> +  /* Check for an integer exponent.  */
> +  if (TREE_CODE (arg0) == REAL_CST
> +  && !TREE_OVERFLOW (arg0)
> +  && TREE_CODE (arg1) == REAL_CST
>&& !TREE_OVERFLOW (arg1))
>  {
> -  REAL_VALUE_TYPE cint;
> -  REAL_VALUE_TYPE c;
> -  HOST_WIDE_INT n;
> -
> -  c = TREE_REAL_CST (arg1);
> -
> -  /* Optimize pow(x,0.0) = 1.0.  */
> -  if (real_equal (, ))
> -   return omit_one_operand_loc (loc, type, build_real (type, dconst1),
> -arg0);
> -
> -  /* Optimize pow(x,1.0) = x.  */
> -  if (real_equal (, ))
> -   return arg0;
> -
> -  /* Optimize pow(x,-1.0) = 1.0/x.  */
> -  if (real_equal (, ))
> -   return fold_build2_loc (loc, RDIV_EXPR, type,
> -   build_real (type, dconst1), arg0);
> -
> -  /* Optimize pow(x,0.5) = sqrt(x).  */
> -  if (flag_unsafe_math_optimizations
> - && real_equal (, ))
> +  REAL_VALUE_TYPE cint1;
> +  const REAL_VALUE_TYPE *c0 = TREE_REAL_CST_PTR (arg0);
> +  const REAL_VALUE_TYPE *c1 = TREE_REAL_CST_PTR (arg1);
> +  HOST_WIDE_INT n1 = real_to_integer (c1);
> +  real_from_integer (, VOIDmode, n1, SIGNED);
> +  /* Attempt to evaluate pow at compile-time, unless this should
> +raise an exception.  */
> +  if (real_identical (c1, )
> + && (n1 > 0
> + || (!flag_trapping_math && !flag_errno_math)
> + || !real_equal (c0, )))
> {
> - tree sqrtfn = mathfn_built_in (type, BUILT_IN_SQRT);
> -
> - if (sqrtfn != NULL_TREE)
> -   return build_call_expr_loc (loc, sqrtfn, 1, arg0);
> -   }
> -
> -  /* Optimize pow(x,1.0/3.0) = cbrt(x).  */
> -  if (flag_unsafe_math_optimizations)
> -   {
> - const REAL_VALUE_TYPE dconstroot
> -   = real_value_truncate (TYPE_MODE (type), dconst_third ());
> -
> - if (real_equal (, ))
> -   {
> - tree cbrtfn = mathfn_built_in (type, BUILT_IN_CBRT);
> - if (cbrtfn != NULL_TREE)
> -   return build_call_expr_loc (loc, cbrtfn, 1, arg0);
> -   }
> -   }
> -
> -  /* Check for an integer exponent.  */
> -  n = real_to_integer ();
> -  real_from_integer (, VOIDmode, n, SIGNED);
> -  if (real_identical (, ))
> -   {
> - /* Attempt to evaluate pow at compile-time, unless this should
> -raise an exception.  */
> - if (TREE_CODE (arg0) == REAL_CST
> - && !TREE_OVERFLOW (arg0)
> - && (n > 0
> - || (!flag_trapping_math && !flag_errno_math)
> - || !real_equal (_REAL_CST (arg0), )))
> -   {
> - REAL_VALUE_TYPE x;
> - bool inexact;
> -
> - x = TREE_REAL_CST (arg0);
> - inexact = real_powi (, TYPE_MODE (type), , n);
> - if (flag_unsafe_math_optimizations || !inexact)
> -   return build_real (type, x);
> -   }

Re: Allow more complex call replacements in gimple-fold.c

2015-10-26 Thread Richard Sandiford
Richard Biener  writes:
> On Mon, Oct 26, 2015 at 10:41 AM, Richard Sandiford
>  wrote:
>> An upcoming patch adds a match.pd rule that folds pow(pow(x,y),z)
>> to pow(x,y*z).  This fold can reuse the existing pow gimple statement
>> and simply replace the operands with x and y*z.  However, the y*z
>> itself requires a separate gimple statement and the code wasn't
>> prepared to handle that.
>>
>> Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi.
>> OK to install?
>
> Hmm, I put the assert there because of the !inplace case but I see the
> is_tree_code case alredy behaves the same.
>
> I think the intent of fold_stmt_inplace (and thus the 'inplace' case)
> was that no additional stmts are inserted (and obviously the
> stmt itself being not replaced, so gsi_stmt () is the same before and
> after).
>
> So I think both the is_gimple_assign && is_tree_code and the
> case you are amending need a
>
>   if (inplace && !gimple_seq_empty_p (*seq))
>return false;

OK.  I was wondering about that, but the comment isn't clear whether
inserting extra statements before the original statement is OK, as long
as the final statement has the same form.

If this hasn't caused problems for tree codes, do you think that means
that callers don't care about extra statements matter in practice,
that there simply aren't many fold patterns like this, or that most
cases where this kind of fold hits are caught earlier?  Just worried
about introducing a pessimisation...

Should we simply have that check before:

  if (gcond *cond_stmt = dyn_cast  (stmt))

so that it's common to all cases?

Thanks,
Richard



[Ada] Expression functions, internal bodies and freezing of contracts

2015-10-26 Thread Arnaud Charlet
This patch ensures that only source package and subprogram bodies "freeze" the
contract of the nearest enclosing package body.


-- Source --


--  expr_funcs.ads

package Expr_Funcs
  with SPARK_Mode,
   Abstract_State => State
is
   Var_1 : Integer := 1;

   function In_Spec return Boolean is (Var_1 = 1)
 with Global => (Input => (State, Var_1));
   --  Does not freeze

   function Spec_And_Body return Boolean
 with Global => (Input => (State, Var_2));
   --  See body

   Var_2 : Integer := 2;
end Expr_Funcs;

--  expr_funcs.adb

package body Expr_Funcs
  with SPARK_Mode,
   Refined_State => (State => (Constit_1, Constit_2))--  Error
is
   Constit_1 : Integer := 1;

   function In_Body return Boolean is (Constit_1 = 1)
 with Global => (Input => Constit_1);
   --  Does not freeze

   package Nested_Expr_Funcs is
  function Nested_In_Spec return Boolean is (Constit_1 = 1)
with Global => (Input => Constit_1);
  --  Does not freeze
   end Nested_Expr_Funcs;

   function Spec_And_Body return Boolean is (Constit_1 = 1)
 with Refined_Global => (Input => Constit_1);
   --  Freezes because it acts as a completion. As a result Constit_2 in
   --  Refined_State appears as undefined.

   Constit_2 : Integer := 2;
end Expr_Funcs;


-- Compilation and output --


$ gcc -c expr_funcs.adb
expr_funcs.adb:1:14: body of package "Expr_Funcs" has unused hidden states
expr_funcs.adb:1:14: variable "Constit_2" defined at line 22
expr_funcs.adb:3:08: body "Spec_And_Body" declared at line 17 freezes the
  contract of "Expr_Funcs"
expr_funcs.adb:3:08: all constituents must be declared before body at line 17
expr_funcs.adb:3:47: "Constit_2" is undefined

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

2015-10-26  Hristian Kirtchev  

* sem_ch7.adb, sem_ch6.adb (Analyze_Subprogram_Body_Helper): Only source
bodies should "freeze" the contract of the nearest enclosing
package body.

Index: sem_ch7.adb
===
--- sem_ch7.adb (revision 229313)
+++ sem_ch7.adb (working copy)
@@ -564,8 +564,12 @@
   --  Freeze_xxx mechanism because it must also work in the context of
   --  generics where normal freezing is disabled.
 
-  Analyze_Enclosing_Package_Body_Contract (N);
+  --  Only bodies coming from source should cause this type of "freezing"
 
+  if Comes_From_Source (N) then
+ Analyze_Enclosing_Package_Body_Contract (N);
+  end if;
+
   --  Find corresponding package specification, and establish the current
   --  scope. The visible defining entity for the package is the defining
   --  occurrence in the spec. On exit from the package body, all body
Index: sem_ch6.adb
===
--- sem_ch6.adb (revision 229313)
+++ sem_ch6.adb (working copy)
@@ -3011,8 +3011,15 @@
   --  decoupled from the usual Freeze_xxx mechanism because it must also
   --  work in the context of generics where normal freezing is disabled.
 
-  Analyze_Enclosing_Package_Body_Contract (N);
+  --  Only bodies coming from source should cause this type of "freezing".
+  --  Expression functions that act as bodies and complete an initial
+  --  declaration must be included in this category, hence the use of
+  --  Original_Node.
 
+  if Comes_From_Source (Original_Node (N)) then
+ Analyze_Enclosing_Package_Body_Contract (N);
+  end if;
+
   --  Generic subprograms are handled separately. They always have a
   --  generic specification. Determine whether current scope has a
   --  previous declaration.


[Ada] Spurious duplicate Default_Iterator error

2015-10-26 Thread Arnaud Charlet
This patch fixes a bug that caused the compiler to issue the error "default
iterator must be unique" when one of the alleged "duplicates" is overridden by
another. This can happen in cases involving types derived from types declared
in generic formal packages. The error message (when it is correct) is also
improved to mention where the duplicate declarations occur. No small test is
available.

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

2015-10-26  Bob Duff  

* sem_ch13.adb (Check_Iterator_Functions): For a Default_Iterator
aspect, make sure an implicitly declared interpretation is
overridden by an explicit one.

Index: sem_ch13.adb
===
--- sem_ch13.adb(revision 229320)
+++ sem_ch13.adb(working copy)
@@ -4277,8 +4277,8 @@
  else
 declare
Default : Entity_Id := Empty;
-   I : Interp_Index;
-   It : Interp;
+   I   : Interp_Index;
+   It  : Interp;
 
 begin
Get_First_Interp (Expr, I, It);
@@ -4289,12 +4289,21 @@
  Remove_Interp (I);
 
   elsif Present (Default) then
- Error_Msg_N ("default iterator must be unique", Expr);
- Error_Msg_Sloc := Sloc (Default);
- Error_Msg_N ("\\possible interpretation#", Expr);
- Error_Msg_Sloc := Sloc (It.Nam);
- Error_Msg_N ("\\possible interpretation#", Expr);
 
+ --  An explicit one should override an implicit one
+
+ if Comes_From_Source (Default) =
+  Comes_From_Source (It.Nam)
+ then
+Error_Msg_N ("default iterator must be unique", Expr);
+Error_Msg_Sloc := Sloc (Default);
+Error_Msg_N ("\\possible interpretation#", Expr);
+Error_Msg_Sloc := Sloc (It.Nam);
+Error_Msg_N ("\\possible interpretation#", Expr);
+
+ elsif Comes_From_Source (It.Nam) then
+Default := It.Nam;
+ end if;
   else
  Default := It.Nam;
   end if;


[Ada] Local name hides global item

2015-10-26 Thread Arnaud Charlet
This patch modifies the analysis of pragmas Depends, Global, Refined_Depends
and Refined_Global when they appear in a subprogram body. The pragmas are now
analyzed immediately and in pairs. This preserves the inherent dependency of
[Refined_]Depends on [Refined_]Global and prevents a visibility issue due to
delayed analysis.


-- Source --


--  pack.ads

package Pack
  with SPARK_Mode,
   Abstract_State => State
is
   procedure Proc
 with Global => (In_Out => State);
end Pack;

--  pack.adb

with Pack.Child;

package body Pack
  with SPARK_Mode,
   Refined_State => (State => (Pack.Child.State))
is
   procedure Proc
 with Refined_Global => (In_Out => (Child.State))
   is
  Child : Integer := 1;
   begin null; end Proc;
end Pack;

--  pack-child.ads

private package Pack.Child
  with Abstract_State => (State with Part_Of => Pack.State)
is
end Pack.Child;

-
-- Compilation --
-

$ gcc -c pack.adb

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

2015-10-26  Hristian Kirtchev  

* contracts.adb (Analyze_Subprogram_Body_Contract): Do not analyze
pragmas Refined_Global and Refined_Depends because these pragmas
are now fully analyzed when encountered.
(Inherit_Pragma): Update the call to attribute Is_Inherited.
* sem_prag.adb (Analyze_Contract_Cases_In_Decl_Part): Add a guard
to prevent reanalysis. Mark the pragma as analyzed at the end of
the processing.
(Analyze_Depends_Global): New parameter profile
and comment on usage. Do not fully analyze the pragma, this is
now done at the outer level.
(Analyze_Depends_In_Decl_Part): Add a guard to prevent reanalysis.
Mark the pragma as analyzed at the end of the processing.
(Analyze_External_Property_In_Decl_Part): Add a guard to prevent
reanalysis.  Mark the pragma as analyzed at the end of the processing.
(Analyze_Global_In_Decl_Part): Add a guard to prevent reanalysis. Mark
the pragma as analyzed at the end of the processing.
(Analyze_Initial_Condition_In_Decl_Part): Add a guard to prevent
reanalysis.  Mark the pragma as analyzed at the end of the processing.
(Analyze_Initializes_In_Decl_Part): Add a guard to prevent reanalysis.
Mark the pragma as analyzed at the end of the processing.
(Analyze_Pragma): Reset the Analyzed flag on various pragmas that
require delayed full analysis. Contract_Cases is now analyzed
immediately when it applies to a subprogram body stub. Pragmas Depends,
Global, Refined_Depends and Refined_Global are now analyzed
in pairs when they appear in a subprogram body [stub].
(Analyze_Pre_Post_Condition_In_Decl_Part): Add a guard to
prevent reanalysis.  Mark the pragma as analyzed at the end of
the processing.
(Analyze_Refined_Depends_Global_Post): Update the comment on usage.
(Analyze_Refined_Depends_In_Decl_Part): Add a guard to prevent
reanalysis. Mark the pragma as analyzed at the end of the processing.
(Analyze_Refined_Global_In_Decl_Part): Add a guard to prevent
reanalysis. Mark the pragma as analyzed at the end of the processing.
(Analyze_Refined_State_In_Decl_Part): Add a guard to prevent
reanalysis. Mark the pragma as analyzed at the end of the processing.
(Analyze_Test_Case_In_Decl_Part): Add a guard to prevent reanalysis.
Mark the pragma as analyzed at the end of the processing.
(Is_Followed_By_Pragma): New routine.
* sinfo.adb (Is_Analyzed_Pragma): New routine.
(Is_Inherited): Renamed to Is_Inherited_Pragma.
(Set_Is_Analyzed_Pragma): New routine.
(Set_Is_Inherited): Renamed to Set_Is_Inherited_Pragma.
* sinfo.ads Rename attribute Is_Inherited to Is_Inherited_Pragma
and update occurrences in nodes.
(Is_Analyzed_Pragma): New routine along with pragma Inline.
(Is_Inherited): Renamed to Is_Inherited_Pragma along with pragma Inline.
(Set_Is_Analyzed_Pragma): New routine along with pragma Inline.
(Set_Is_Inherited): Renamed to Set_Is_Inherited_Pragma along
with pragma Inline.

Index: sinfo.adb
===
--- sinfo.adb   (revision 229328)
+++ sinfo.adb   (working copy)
@@ -1760,6 +1760,14 @@
   return Flag13 (N);
end Is_Accessibility_Actual;
 
+   function Is_Analyzed_Pragma
+  (N : Node_Id) return Boolean is
+   begin
+  pragma Assert (False
+or else NT (N).Nkind = N_Pragma);
+  return Flag5 (N);
+   end Is_Analyzed_Pragma;
+
function Is_Asynchronous_Call_Block
   (N : Node_Id) return Boolean is
begin
@@ -1918,13 +1926,13 @@
   return Flag11 (N);
end Is_In_Discriminant_Check;
 
-   function Is_Inherited
+   function Is_Inherited_Pragma
   (N : Node_Id) 

[Ada] Contracts on protected entries and task units

2015-10-26 Thread Arnaud Charlet
This patch implements pragmas [Refined_]Depends and [Refined_]Global on
protected entries and task units. As a prerequisite, the patch implements
aspect specifications on entry bodies as specified in Ada 2012 (AI12-0169):

   ENTRY_BODY ::=
 entry DEFINING_IDENTIFIER ENTRY_BODY_FORMAL_PART
   [ASPECT_SPECIFICATIONS] ENTRY_BARRIER
 is
DECLARATIVE_PART
 begin
HANDLED_SEQUENCE_OF_STATEMENTS
 end [entry_IDENTIFIER];


-- Source --


--  synchronized_contracts.ads

package Synchronized_Contracts
  with SPARK_Mode,
   Abstract_State => State
is
   Var : Integer := 1;

   protected type Prot_Typ_1 is
  entry Prot_Ent (Formal : out Integer)
with Global  => (Input => (State, Var)),
 Depends => (Formal => (State, Var));
   end Prot_Typ_1;

   protected Prot_Typ_2 is
  entry Prot_Ent (Formal : out Integer);
  pragma Global  ((Input => State));
  pragma Depends ((Formal => State));
   end Prot_Typ_2;

   task type Task_Typ_1
 with Global  => (Input => State, Output => Var),
  Depends => (Var => State);

   task Task_Typ_2;
   pragma Global  ((Output => (State, Var)));
   pragma Depends (((State, Var) => null));
end Synchronized_Contracts;

--  synchronized_contracts.adb

package body Synchronized_Contracts
  with SPARK_Mode,
   Refined_State => (State => Constit)
is
   Constit : Integer := 2;

   protected body Prot_Typ_1 is
  entry Prot_Ent (Formal : out Integer) when True is
 pragma Refined_Global  ((Input => (Constit, Var)));
 pragma Refined_Depends ((Formal => (Constit, Var)));
  begin
 Formal := Constit + Var;
  end Prot_Ent;
   end Prot_Typ_1;

   protected body Prot_Typ_2 is
  entry Prot_Ent (Formal : out Integer)
with Refined_Global  => (Input => Constit),
 Refined_Depends => (Formal => Constit)
when True is
  begin
 Formal := Constit + 1;
  end Prot_Ent;
   end Prot_Typ_2;

   task body Task_Typ_1 is
  pragma Refined_Global  ((Input => Constit, Output => Var));
  pragma Refined_Depends ((Var => Constit));
   begin
  null;
   end Task_Typ_1;

   task body Task_Typ_2
 with Refined_Global  => (Output => (Constit, Var)),
  Refined_Depends => ((Constit, Var) => null)
   is
   begin
  null;
   end Task_Typ_2;
end Synchronized_Contracts;

-
-- Compilation --
-

$ gcc -c synchronized_contracts.adb

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

2015-10-26  Hristian Kirtchev  

* aspects.adb Add an entry for entry bodies in table
Has_Aspect_Specifications_Flag.
(Aspects_On_Body_Or_Stub_OK): Entry bodies now allow for certain
aspects.
* contracts.adb (Add_Contract_Items): Code cleanup. Add
processing for entry bodies, entry declarations and task units.
(Analyze_Subprogram_Body_Contract): Renamed
to Analyze_Entry_Or_Subprogram_Body_Contract. Do not
analyze the contract of an entry body unless annotating the
original tree.
(Analyze_Subprogram_Contract): Renamed to
Analyze_Entry_Or_Subprogram_Contract.  Do not analyze the contract
of an entry declaration unless annotating the original tree.
(Analyze_Task_Contract): New routine.
* contracts.ads (Add_Contract_Item): Update the comment on usage.
(Analyze_Package_Body_Contract): Update comment on usage.
(Analyze_Package_Contract): Update the comment on usage.
(Analyze_Subprogram_Body_Contract): Renamed to
Analyze_Entry_Or_Subprogram_Body_Contract.
(Analyze_Subprogram_Body_Stub_Contract): Update the comment on usage.
(Analyze_Subprogram_Contract): Renamed to
Analyze_Entry_Or_Subprogram_Contract.
(Analyze_Task_Contract): New routine.
* einfo.adb (Contract): Restructure the assertion to include
entries and task units.
(SPARK_Pragma): This attribute now applies to operators.
(SPARK_Pragma_Inherited): This flag now applies to operators.
(Set_Contract): Restructure the assertion to include entries and task
units.
(Set_SPARK_Pragma): This attribute now applies to operators.
(Set_SPARK_Pragma_Inherited): This flag now applies to operators.
(Write_Field34_Name): Write out all Ekinds that have a contract.
(Write_Field40_Name): SPARK_Pragma now applies to operators.
* einfo.ads: Update the documentation of attribute Contract along
with usage in nodes.  Update the documentation of attributes
SPARK_Pragma and SPARK_Pragma_Inherited.
* exp_ch6.adb (Freeze_Subprogram): Update the call to
Analyze_Subprogram_Contract.
* par-ch9.adb (P_Entry_Barrier): Do not parse keyword "is" as it
is not part of the entry barrier production.
(P_Entry_Body): Parse the optional aspect specifications. 

[Ada] Spurious errors with -gnatE and -gnatwl

2015-10-26 Thread Arnaud Charlet
This patch removes spurious errors triggered by the switches -gnatE (Dynamic
elaboration) and -gnatwl (list elaboration warnings) when the elaboration
call is appears in the prefix of an access attribute.

Compiling

   gcc -c dds-translator.adb -gnatE -gnatwl

must yield:

   dds-translator-generated_code.adb:12:63:
info: access to "endian_translate" during elaboration
   dds-translator-generated_code.adb:12:63:
info: implicit pragma Elaborate_All for
"x86_translate.acft_attitude_command" generated
   dds-translator-generated_code.adb:12:63:
info: "init" called at dds-translator.adb:50
   dds-translator-display_list_generated_code.adb:10:68:
info: access to "endian_translate" during elaboration
   dds-translator-display_list_generated_code.adb:10:68:
info: implicit pragma Elaborate_All for
"x86_translate.display_list_cb_fixed_repeat" generated
   dds-translator-display_list_generated_code.adb:10:68:
info: "display_list_init" called at dds-translator.adb:51

---
WITH system;
PACKAGE dds.translator IS
   PRAGMA Elaborate_Body;
   TYPE translator_access IS
  ACCESS PROCEDURE (address : system.address; size_in_bytes : natural);

   PROCEDURE init_it;
END dds.translator;
---
WITH interfaces;
WITH system;
PACKAGE BODY dds.translator is
   max_msg_id : CONSTANT := 16_384;

   bits_per_long  : CONSTANT := 32;
   TYPE unsigned_long IS NEW interfaces.unsigned_32;
   FOR unsigned_long'size USE bits_per_long;

   TYPE msg_ids IS NEW unsigned_long;
   SUBTYPE valid_msg_ids IS msg_ids RANGE 1 .. max_msg_id;

   TYPE translator_infos IS RECORD
  operator  : translator_access;
  max_size_in_bytes : natural;
   END RECORD;
   TYPE translators IS ARRAY (valid_msg_ids) OF translator_infos;
   PACKAGE generated_code IS
  translate : translators := (OTHERS => (NULL, 0));
  PROCEDURE init;
   END generated_code;
   PACKAGE BODY generated_code IS SEPARATE;
   USE generated_code;

   TYPE display_list_translator_access IS
  ACCESS PROCEDURE (address : system.address; size_in_bytes : natural);
   TYPE display_list_translator_infos IS RECORD
  operator  : display_list_translator_access;
  max_size_in_bytes : natural;
   END RECORD;

   TYPE display_list_translators IS
   ARRAY (valid_msg_ids) OF display_list_translator_infos;
   PACKAGE display_list_generated_code IS
  display_list_translate : display_list_translators :=
  (OTHERS => (NULL, 0));
  PROCEDURE display_list_init;
   END display_list_generated_code;
   PACKAGE BODY display_list_generated_code IS SEPARATE;
   USE display_list_generated_code;

   PROCEDURE init_it is
   begin
  init;
  display_list_init;
   END init_it;

BEGIN
   init;
   display_list_init;
END dds.translator;
---
PACKAGE dds is

END dds;
---
PACKAGE numeric.types IS

   TYPE integers IS RANGE -2_147_483_648 .. +2_147_483_647;

   SUBTYPE integer32s IS integers;

   SUBTYPE uinteger16s IS integers RANGE 0 .. 65_535;
   SUBTYPE unsigned_halfword IS uinteger16s;
   SUBTYPE int_unsigned_16_bit IS uinteger16s;

   SUBTYPE integer16s IS integers RANGE -32_768 .. +32_767;
   SUBTYPE single_integer IS integer16s;
   SUBTYPE signed_halfword IS integer16s;

   SUBTYPE uinteger8s IS integers RANGE 0 .. 255;
   SUBTYPE int_unsigned_8_bit IS uinteger8s;

   SUBTYPE integer8s IS integers RANGE -128 .. 127;
   SUBTYPE int_8_bit IS integer8s;

END numeric.types;
---
PACKAGE numeric IS
   PRAGMA pure;
END numeric;
---
WITH system;
PACKAGE x86_translate.acft_attitude_command IS

id: CONSTANT := 4736;
byte_count: CONSTANT := 16 + 16;
message_name  : CONSTANT String := "ACFT_ATTITUDE_COMMAND";

PROCEDURE endian_translate
   (msg_address : system.address; size_in_bytes:natural);

END x86_translate.acft_attitude_command;
---
WITH system;

PACKAGE x86_translate.display_list_cb_fixed_repeat IS

id: CONSTANT := 111;
byte_count: CONSTANT := 4;
message_name  : CONSTANT String := "display_list_CB_FIXED_REPEAT";

PROCEDURE endian_translate
   (msg_address : system.address; size_in_bytes:natural);

END x86_translate.display_list_cb_fixed_repeat;

WITH numeric.types;
WITH system;

PACKAGE x86_translate IS
   FUNCTION tr (n : numeric.types.integers; bits : natural)
RETURN numeric.types.integers;

   -- Aggregate types or special cases

   PROCEDURE tr (address : system.address; bits: natural);

END x86_translate;
---
WITH x86_translate.display_list_cb_fixed_repeat;
SEPARATE (dds.translator)
PACKAGE BODY display_list_generated_code IS

   PROCEDURE display_list_init IS
   BEGIN
  -- Adacore
 display_list_translate (x86_translate.display_list_cb_fixed_repeat.id) :=
   (x86_translate.display_list_cb_fixed_repeat.endian_translate'access,
  x86_translate.display_list_cb_fixed_repeat.byte_count);
   END;
END display_list_generated_code;
---
WITH x86_translate.acft_attitude_command;


[Ada] Spawning processes with no PATH

2015-10-26 Thread Arnaud Charlet
This patch fixes a bug in which GNAT.Expect.Non_Blocking_Spawn fails to find an
executable when the PATH environment variable is not set. The executable
should be found if it contains a directory name.

The following test should execute quietly.

gnatmake -q do_nothing.adb
gnatmake -q spawn.adb
unset PATH
./spawn

procedure Do_Nothing is
begin
   null;
end Do_Nothing;

with GNAT.Expect;
with GNAT.OS_Lib;
Procedure Spawn is

   P : GNAT.Expect.Process_Descriptor;
   T : constant GNAT.Os_Lib.Argument_List(1..0) := ( others => null);
begin
   GNAT.Expect.Non_Blocking_Spawn(P, "./do_nothing", T);
end Spawn;

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

2015-10-26  Bob Duff  

* adaint.c (__gnat_locate_exec_on_path): If the PATH environment
variable is not set, do not return NULL, because we can still find
the executable if it includes a directory name.

Index: adaint.c
===
--- adaint.c(revision 229320)
+++ adaint.c(working copy)
@@ -2787,16 +2787,19 @@
   apath_val = (char *) alloca (EXPAND_BUFFER_SIZE);
 
   WS2SC (apath_val, wapath_val, EXPAND_BUFFER_SIZE);
-  return __gnat_locate_exec (exec_name, apath_val);
 
 #else
   char *path_val = getenv ("PATH");
 
-  if (path_val == NULL) return NULL;
+  /* If PATH is not defined, proceed with __gnat_locate_exec anyway, so we can
+ find files that contain directory names.  */
+
+  if (path_val == NULL) path_val = "";
   apath_val = (char *) alloca (strlen (path_val) + 1);
   strcpy (apath_val, path_val);
+#endif
+
   return __gnat_locate_exec (exec_name, apath_val);
-#endif
 }
 
 /* Dummy functions for Osint import for non-VMS systems.


Re: Move some bit and binary optimizations in simplify and match

2015-10-26 Thread Richard Biener
On Mon, Oct 26, 2015 at 10:26 AM, Richard Biener
 wrote:
> On Sat, Oct 24, 2015 at 11:15 PM, Marc Glisse  wrote:
>> On Fri, 23 Oct 2015, Hurugalawadi, Naveen wrote:
>>
>> + (minus (bit_and:cs @0 (bit_not @1)) (bit_and:s @0 @1))
>>
>> I am not sure why we have :c on one bit_and but not the other.
>
> Clearly an omission.
>
>> + (bit_ior:c (bit_and:c @0 (bit_not @1)) (bit_and:c (bit_not @0) @1))
>>
>> Here on the other hand, I believe the :c on bit_ior is redundant.
>
> Yes.  It's somewhat twisty ;)  I wonder why it doesn't get you a genmatch
> warning for duplicate patterns though.  A it does:
>
> test.pd:2:3 warning: duplicate pattern
>  (bit_ior:c (bit_and:c @0 (bit_not @1)) (bit_and:c (bit_not @0) @1))
>   ^
> test.pd:2:3 warning: previous pattern defined here
>  (bit_ior:c (bit_and:c @0 (bit_not @1)) (bit_and:c (bit_not @0) @1))
>   ^
> (BIT_IOR_EXPR (BIT_AND_EXPR (BIT_NOT_EXPR @0) @1) (BIT_AND_EXPR @0
> (BIT_NOT_EXPR @1)))
>
> so please watch out for them when building.

I'm testing a patch to fix both issues.

Richard.

> Richard.
>
>>
>> --
>> Marc Glisse


Move hypot folds to match.pd

2015-10-26 Thread Richard Sandiford
Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi.
OK to install?

Thanks,
Richard


gcc/
* builtins.c (fold_builtin_hypot): Delete.
(fold_builtin_2): Handle constant hypot arguments here.
* match.pd: Fold hypot(x, 0) and hypot(0, x) to x.  Canonicalize
hypot(x, x) to fabs(x)*sqrt(2).

diff --git a/gcc/builtins.c b/gcc/builtins.c
index f947f1e..64106a1 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -7475,39 +7475,6 @@ fold_builtin_bswap (tree fndecl, tree arg)
   return NULL_TREE;
 }
 
-/* Fold a builtin function call to hypot, hypotf, or hypotl.  Return
-   NULL_TREE if no simplification can be made.  */
-
-static tree
-fold_builtin_hypot (location_t loc, tree arg0, tree arg1, tree type)
-{
-  tree res;
-
-  if (!validate_arg (arg0, REAL_TYPE)
-  || !validate_arg (arg1, REAL_TYPE))
-return NULL_TREE;
-
-  /* Calculate the result when the argument is a constant.  */
-  if ((res = do_mpfr_arg2 (arg0, arg1, type, mpfr_hypot)))
-return res;
-
-  /* If either argument is zero, hypot is fabs of the other.  */
-  if (real_zerop (arg0))
-return fold_build1_loc (loc, ABS_EXPR, type, arg1);
-  else if (real_zerop (arg1))
-return fold_build1_loc (loc, ABS_EXPR, type, arg0);
-
-  /* hypot(x,x) -> fabs(x)*sqrt(2).  */
-  if (flag_unsafe_math_optimizations
-  && operand_equal_p (arg0, arg1, OEP_PURE_SAME))
-return fold_build2_loc (loc, MULT_EXPR, type,
-   fold_build1_loc (loc, ABS_EXPR, type, arg0),
-   build_real_truncate (type, dconst_sqrt2 ()));
-
-  return NULL_TREE;
-}
-
-
 /* Fold a builtin function call to pow, powf, or powl.  Return
NULL_TREE if no simplification can be made.  */
 static tree
@@ -9456,7 +9423,10 @@ fold_builtin_2 (location_t loc, tree fndecl, tree arg0, 
tree arg1)
 break;
 
 CASE_FLT_FN (BUILT_IN_HYPOT):
-  return fold_builtin_hypot (loc, arg0, arg1, type);
+  if (validate_arg (arg0, REAL_TYPE)
+ && validate_arg (arg1, REAL_TYPE))
+   return do_mpfr_arg2 (arg0, arg1, type, mpfr_hypot);
+  break;
 
 CASE_FLT_FN (BUILT_IN_CPOW):
   if (validate_arg (arg0, COMPLEX_TYPE)
diff --git a/gcc/match.pd b/gcc/match.pd
index 00c6e7c..8cd55f6 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -2520,6 +2520,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (RINT integer_valued_real_p@0)
   @0))
 
+/* hypot(x,0) and hypot(0,x) -> abs(x).  */
+(simplify
+ (hypot:c @0 real_zerop@1)
+ (abs @0))
+
 /* Canonicalization of sequences of math builtins.  These rules represent
IL simplifications but are not necessarily optimizations.
 
@@ -2618,6 +2623,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (CABS (complex @0 @0))
   (mult (abs @0) { build_real_truncate (type, dconst_sqrt2 ()); }))
 
+ /* hypot(x,x) -> fabs(x)*sqrt(2).  */
+ (simplify
+  (HYPOT @0 @0)
+  (mult (abs @0) { build_real_truncate (type, dconst_sqrt2 ()); }))
+
  /* cexp(x+yi) -> exp(x)*cexpi(y).  */
  (for cexps (CEXP)
   exps (EXP)



Move pow folds to match.pd

2015-10-26 Thread Richard Sandiford
Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi.
OK to install?

Thanks,
Richard


gcc/
* builtins.c (fold_builtin_pow): Delete in favor of...
(fold_const_builtin_pow): ...this new function.  Only handle constant
arguments.
(fold_builtin_2): Update accordingly.
* match.pd: Add rules previously handled by fold_builtin_pow.

gcc/testsuite/
* gcc.dg/torture/builtin-math-1.c: Skip at -O0.

diff --git a/gcc/builtins.c b/gcc/builtins.c
index 64106a1..88c0576 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -156,7 +156,6 @@ static tree rewrite_call_expr (location_t, tree, int, tree, 
int, ...);
 static bool validate_arg (const_tree, enum tree_code code);
 static rtx expand_builtin_fabs (tree, rtx, rtx);
 static rtx expand_builtin_signbit (tree, rtx);
-static tree fold_builtin_pow (location_t, tree, tree, tree, tree);
 static tree fold_builtin_powi (location_t, tree, tree, tree, tree);
 static tree fold_builtin_bitop (tree, tree);
 static tree fold_builtin_strchr (location_t, tree, tree, tree);
@@ -7478,7 +7477,7 @@ fold_builtin_bswap (tree fndecl, tree arg)
 /* Fold a builtin function call to pow, powf, or powl.  Return
NULL_TREE if no simplification can be made.  */
 static tree
-fold_builtin_pow (location_t loc, tree fndecl, tree arg0, tree arg1, tree type)
+fold_const_builtin_pow (tree arg0, tree arg1, tree type)
 {
   tree res;
 
@@ -7490,127 +7489,28 @@ fold_builtin_pow (location_t loc, tree fndecl, tree 
arg0, tree arg1, tree type)
   if ((res = do_mpfr_arg2 (arg0, arg1, type, mpfr_pow)))
 return res;
 
-  /* Optimize pow(1.0,y) = 1.0.  */
-  if (real_onep (arg0))
-return omit_one_operand_loc (loc, type, build_real (type, dconst1), arg1);
-
-  if (TREE_CODE (arg1) == REAL_CST
+  /* Check for an integer exponent.  */
+  if (TREE_CODE (arg0) == REAL_CST
+  && !TREE_OVERFLOW (arg0)
+  && TREE_CODE (arg1) == REAL_CST
   && !TREE_OVERFLOW (arg1))
 {
-  REAL_VALUE_TYPE cint;
-  REAL_VALUE_TYPE c;
-  HOST_WIDE_INT n;
-
-  c = TREE_REAL_CST (arg1);
-
-  /* Optimize pow(x,0.0) = 1.0.  */
-  if (real_equal (, ))
-   return omit_one_operand_loc (loc, type, build_real (type, dconst1),
-arg0);
-
-  /* Optimize pow(x,1.0) = x.  */
-  if (real_equal (, ))
-   return arg0;
-
-  /* Optimize pow(x,-1.0) = 1.0/x.  */
-  if (real_equal (, ))
-   return fold_build2_loc (loc, RDIV_EXPR, type,
-   build_real (type, dconst1), arg0);
-
-  /* Optimize pow(x,0.5) = sqrt(x).  */
-  if (flag_unsafe_math_optimizations
- && real_equal (, ))
+  REAL_VALUE_TYPE cint1;
+  const REAL_VALUE_TYPE *c0 = TREE_REAL_CST_PTR (arg0);
+  const REAL_VALUE_TYPE *c1 = TREE_REAL_CST_PTR (arg1);
+  HOST_WIDE_INT n1 = real_to_integer (c1);
+  real_from_integer (, VOIDmode, n1, SIGNED);
+  /* Attempt to evaluate pow at compile-time, unless this should
+raise an exception.  */
+  if (real_identical (c1, )
+ && (n1 > 0
+ || (!flag_trapping_math && !flag_errno_math)
+ || !real_equal (c0, )))
{
- tree sqrtfn = mathfn_built_in (type, BUILT_IN_SQRT);
-
- if (sqrtfn != NULL_TREE)
-   return build_call_expr_loc (loc, sqrtfn, 1, arg0);
-   }
-
-  /* Optimize pow(x,1.0/3.0) = cbrt(x).  */
-  if (flag_unsafe_math_optimizations)
-   {
- const REAL_VALUE_TYPE dconstroot
-   = real_value_truncate (TYPE_MODE (type), dconst_third ());
-
- if (real_equal (, ))
-   {
- tree cbrtfn = mathfn_built_in (type, BUILT_IN_CBRT);
- if (cbrtfn != NULL_TREE)
-   return build_call_expr_loc (loc, cbrtfn, 1, arg0);
-   }
-   }
-
-  /* Check for an integer exponent.  */
-  n = real_to_integer ();
-  real_from_integer (, VOIDmode, n, SIGNED);
-  if (real_identical (, ))
-   {
- /* Attempt to evaluate pow at compile-time, unless this should
-raise an exception.  */
- if (TREE_CODE (arg0) == REAL_CST
- && !TREE_OVERFLOW (arg0)
- && (n > 0
- || (!flag_trapping_math && !flag_errno_math)
- || !real_equal (_REAL_CST (arg0), )))
-   {
- REAL_VALUE_TYPE x;
- bool inexact;
-
- x = TREE_REAL_CST (arg0);
- inexact = real_powi (, TYPE_MODE (type), , n);
- if (flag_unsafe_math_optimizations || !inexact)
-   return build_real (type, x);
-   }
-   }
-}
-
-  if (flag_unsafe_math_optimizations)
-{
-  const enum built_in_function fcode = builtin_mathfn_code (arg0);
-
-  /* Optimize pow(expN(x),y) = expN(x*y).  */
-  if (BUILTIN_EXPONENT_P (fcode))
-   {
- tree expfn = TREE_OPERAND (CALL_EXPR_FN (arg0), 0);
- tree arg = CALL_EXPR_ARG (arg0, 0);
- arg = 

Split constant handling out of fold_builtin_fma

2015-10-26 Thread Richard Sandiford
Just makes an upcoming patch a bit clearer.

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

Thanks,
Richard


gcc/
* builtins.c (fold_builtin_fma): Remove constant handling.
(fold_builtin_3): Handle constant fma arguments here.

diff --git a/gcc/builtins.c b/gcc/builtins.c
index a03dffc..6cd8879 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -7881,18 +7881,13 @@ fold_fma (location_t loc ATTRIBUTE_UNUSED,
 static tree
 fold_builtin_fma (location_t loc, tree arg0, tree arg1, tree arg2, tree type)
 {
+  /* ??? Only expand to FMA_EXPR if it's directly supported.  */
   if (validate_arg (arg0, REAL_TYPE)
   && validate_arg (arg1, REAL_TYPE)
-  && validate_arg (arg2, REAL_TYPE))
-{
-  tree tem = fold_fma (loc, type, arg0, arg1, arg2);
-  if (tem)
-   return tem;
+  && validate_arg (arg2, REAL_TYPE)
+  && optab_handler (fma_optab, TYPE_MODE (type)) != CODE_FOR_nothing)
+return fold_build3_loc (loc, FMA_EXPR, type, arg0, arg1, arg2);
 
-  /* ??? Only expand to FMA_EXPR if it's directly supported.  */
-  if (optab_handler (fma_optab, TYPE_MODE (type)) != CODE_FOR_nothing)
-return fold_build3_loc (loc, FMA_EXPR, type, arg0, arg1, arg2);
-}
   return NULL_TREE;
 }
 
@@ -9307,8 +9302,9 @@ fold_builtin_3 (location_t loc, tree fndecl,
   return fold_builtin_sincos (loc, arg0, arg1, arg2);
 
 CASE_FLT_FN (BUILT_IN_FMA):
+  if (tree tem = fold_fma (loc, type, arg0, arg1, arg2))
+   return tem;
   return fold_builtin_fma (loc, arg0, arg1, arg2, type);
-break;
 
 CASE_FLT_FN (BUILT_IN_REMQUO):
   if (validate_arg (arg0, REAL_TYPE)



Re: Don't create SSA names until in SSA form

2015-10-26 Thread Richard Biener
On Mon, Oct 26, 2015 at 10:36 AM, Richard Sandiford
 wrote:
> An upcoming patch adds a fold from hypot(x,x) to fabs(x)*sqrt(2).
> This is unusual in that it could trigger in the gimplifier but would
> require new SSA names to be created.  This patch makes sure that we
> don't try to create new SSA names when we're not yet in SSA form.
>
> Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi.
> OK to install?

Please use

 if (gimple_in_ssa_p (cfun))
  res = make_ssa_name (type);
 else
  res = create_tmp_reg (type);

Ok with that change.

Thanks,
Richard.

> Thanks,
> Richard
>
>
> gcc/
> * gimple-match-head.c (maybe_push_res_to_seq): Don't attempt
> to create new SSA names if not in SSA form.
>
> diff --git a/gcc/gimple-match-head.c b/gcc/gimple-match-head.c
> index 8f72919..1345cf9 100644
> --- a/gcc/gimple-match-head.c
> +++ b/gcc/gimple-match-head.c
> @@ -331,7 +331,11 @@ maybe_push_res_to_seq (code_helper rcode, tree type, 
> tree *ops,
>   && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[2])))
> return NULL_TREE;
>if (!res)
> -   res = make_ssa_name (type);
> +   {
> + if (!gimple_in_ssa_p (cfun))
> +   return NULL_TREE;
> + res = make_ssa_name (type);
> +   }
>maybe_build_generic_op (rcode, type, [0], ops[1], ops[2]);
>gimple *new_stmt = gimple_build_assign (res, rcode,
>  ops[0], ops[1], ops[2]);
> @@ -361,7 +365,11 @@ maybe_push_res_to_seq (code_helper rcode, tree type, 
> tree *ops,
> }
>gcc_assert (nargs != 0);
>if (!res)
> -   res = make_ssa_name (type);
> +   {
> + if (!gimple_in_ssa_p (cfun))
> +   return NULL_TREE;
> + res = make_ssa_name (type);
> +   }
>gimple *new_stmt = gimple_build_call (decl, nargs, ops[0], ops[1], 
> ops[2]);
>gimple_call_set_lhs (new_stmt, res);
>gimple_seq_add_stmt_without_update (seq, new_stmt);
>


Re: [Patch, Fortran, 66927, v2.1] [6 Regression] ICE in gfc_conf_procedure_call

2015-10-26 Thread Andre Vehreschild
Hi all,

unfortunately did my last patch create a segfault on some 32-bit
system. This happens because in the scalarizer the lower bound of the
deferred length array of the source= expression was taken to be
constant zero instead of taking that information from the array
descriptor. This patch fixes the segfault by taking the lower -- and to
keep it in sync also the upper -- bound from the array descriptor when
doing the array assign in the allocate (). 

Bootstrapped and regtested on x86_64-linux-gnu/f21.

Ok for trunk?

Sorry for the regression.

Regards,
Andre

On Sun, 25 Oct 2015 13:31:02 +0100
Andre Vehreschild  wrote:

> Hi Paul, hi all,
> 
> thanks for the review. Submitted as r229294.
> 
> Regards,
>   Andre
> 
> On Sun, 25 Oct 2015 08:43:24 +0100
> Paul Richard Thomas  wrote:
> 
> > Dear Andre,
> > 
> > As far as I can see, the problems with PR57117 are specific to RESHAPE
> > and need not affect committing your patch. To my surprise, the
> > combination of your patch and mine for PR67171 fixes PR67044 in that
> > the ICE no longer occurs. I have to get my head around how to write a
> > testcase for it that tests the functionality though!
> > 
> > You can commit this patch to trunk. As I said elsewhere, I will rename
> > the testcase for PR67171.
> > 
> > Many thanks for the patch.
> > 
> > Paul
> > 
> > On 23 October 2015 at 09:44, Paul Richard Thomas
> >  wrote:
> > > Dear Andre,
> > >
> > > I will wait until you fix the problems that Dominique has pointed out.
> > > However, if by Sunday afternoon (rain forecast!) you haven't found the
> > > time, I will see if I can locate the source of these new problems.
> > >
> > > With best regards
> > >
> > > Paul
> > >
> > > On 7 October 2015 at 19:51, Dominique d'Humières  
> > > wrote:
> > >> This patch also fixes pr57117 comment 2, the original test and the test 
> > >> in comment 3 now give an ICE
> > >>
> > >> pr57117.f90:82:0:
> > >>
> > >>allocate(z(9), source=reshape(x, (/ 9 /)))
> > >> 1
> > >> internal compiler error: Segmentation fault: 11
> > >>
> > >> and pr67044.
> > >>
> > >> Thanks,
> > >>
> > >> Dominique
> > >>
> > >
> > >
> > >
> > > --
> > > Outside of a dog, a book is a man's best friend. Inside of a dog it's
> > > too dark to read.
> > >
> > > Groucho Marx
> > 
> > 
> > 
> 
> 


-- 
Andre Vehreschild * Email: vehre ad gmx dot de 


pr66927_3.clog
Description: Binary data
diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index b726998..f6e980d 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -3809,7 +3809,7 @@ gfc_trans_scalarized_loop_boundary (gfc_loopinfo * loop, stmtblock_t * body)
 
 static void
 evaluate_bound (stmtblock_t *block, tree *bounds, gfc_expr ** values,
-		tree desc, int dim, bool lbound)
+		tree desc, int dim, bool lbound, bool deferred)
 {
   gfc_se se;
   gfc_expr * input_val = values[dim];
@@ -3824,6 +3824,17 @@ evaluate_bound (stmtblock_t *block, tree *bounds, gfc_expr ** values,
   gfc_add_block_to_block (block, );
   *output = se.expr;
 }
+  else if (deferred)
+{
+  /* The gfc_conv_array_lbound () routine returns a constant zero for
+	 deferred length arrays, which in the scalarizer wrecks havoc, when
+	 copying to a (newly allocated) one-based array.
+	 Keep returning the actual result in sync for both bounds.  */
+  *output = lbound ? gfc_conv_descriptor_lbound_get (desc,
+			 gfc_rank_cst[dim]):
+			 gfc_conv_descriptor_ubound_get (desc,
+			 gfc_rank_cst[dim]);
+}
   else
 {
   /* No specific bound specified so use the bound of the array.  */
@@ -3864,14 +3875,18 @@ gfc_conv_section_startstride (stmtblock_t * block, gfc_ss * ss, int dim)
   desc = info->descriptor;
   stride = ar->stride[dim];
 
+
   /* Calculate the start of the range.  For vector subscripts this will
  be the range of the vector.  */
-  evaluate_bound (block, info->start, ar->start, desc, dim, true);
+  evaluate_bound (block, info->start, ar->start, desc, dim, true,
+		  ar->as->type == AS_DEFERRED);
 
   /* Similarly calculate the end.  Although this is not used in the
  scalarizer, it is needed when checking bounds and where the end
  is an expression with side-effects.  */
-  evaluate_bound (block, info->end, ar->end, desc, dim, false);
+  evaluate_bound (block, info->end, ar->end, desc, dim, false,
+		  ar->as->type == AS_DEFERRED);
+
 
   /* Calculate the stride.  */
   if (stride == NULL)
@@ -6965,7 +6980,8 @@ gfc_conv_expr_descriptor (gfc_se *se, gfc_expr *expr)
 
 	  gcc_assert (n == codim - 1);
 	  evaluate_bound (, info->start, ar->start,
-			  info->descriptor, n + ndim, true);
+			  info->descriptor, n + ndim, true,
+			  ar->as->type == AS_DEFERRED);
 	  loop.from[n + loop.dimen] = info->start[n + ndim];
 	}
   else


Re: Move signbit folds to match.pd

2015-10-26 Thread Richard Biener
On Mon, Oct 26, 2015 at 10:52 AM, Richard Sandiford
 wrote:
> Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi.
> OK to install?

Ok.

Thanks,
Richard.

> Thanks,
> Richard
>
>
> gcc/
> * builtins.c (fold_builtin_signbit): Delete.
> (fold_builtin_2): Handle constant signbit arguments here.
> * match.pd: Add rules previously handled by fold_builtin_signbit.
>
> gcc/testsuite/
> PR tree-optimization/68097
> * gcc.dg/torture/builtin-nonneg-1.c: Skip at -O0.  Add
> --param max-ssa-name-query-depth=3 to dg-options.
>
> diff --git a/gcc/builtins.c b/gcc/builtins.c
> index e5a00ee..ae7e7ef 100644
> --- a/gcc/builtins.c
> +++ b/gcc/builtins.c
> @@ -162,7 +162,6 @@ static tree fold_builtin_memchr (location_t, tree, tree, 
> tree, tree);
>  static tree fold_builtin_memcmp (location_t, tree, tree, tree);
>  static tree fold_builtin_strcmp (location_t, tree, tree);
>  static tree fold_builtin_strncmp (location_t, tree, tree, tree);
> -static tree fold_builtin_signbit (location_t, tree, tree);
>  static tree fold_builtin_isascii (location_t, tree);
>  static tree fold_builtin_toascii (location_t, tree);
>  static tree fold_builtin_isdigit (location_t, tree);
> @@ -7782,40 +7781,6 @@ fold_builtin_strncmp (location_t loc, tree arg1, tree 
> arg2, tree len)
>return NULL_TREE;
>  }
>
> -/* Fold function call to builtin signbit, signbitf or signbitl with argument
> -   ARG.  Return NULL_TREE if no simplification can be made.  */
> -
> -static tree
> -fold_builtin_signbit (location_t loc, tree arg, tree type)
> -{
> -  if (!validate_arg (arg, REAL_TYPE))
> -return NULL_TREE;
> -
> -  /* If ARG is a compile-time constant, determine the result.  */
> -  if (TREE_CODE (arg) == REAL_CST
> -  && !TREE_OVERFLOW (arg))
> -{
> -  REAL_VALUE_TYPE c;
> -
> -  c = TREE_REAL_CST (arg);
> -  return (REAL_VALUE_NEGATIVE (c)
> - ? build_one_cst (type)
> - : build_zero_cst (type));
> -}
> -
> -  /* If ARG is non-negative, the result is always zero.  */
> -  if (tree_expr_nonnegative_p (arg))
> -return omit_one_operand_loc (loc, type, integer_zero_node, arg);
> -
> -  /* If ARG's format doesn't have signed zeros, return "arg < 0.0".  */
> -  if (!HONOR_SIGNED_ZEROS (arg))
> -return fold_convert (type,
> -fold_build2_loc (loc, LT_EXPR, boolean_type_node, 
> arg,
> -   build_real (TREE_TYPE (arg), dconst0)));
> -
> -  return NULL_TREE;
> -}
> -
>  /* Fold function call to builtin copysign, copysignf or copysignl with
> arguments ARG1 and ARG2.  Return NULL_TREE if no simplification can
> be made.  */
> @@ -9124,7 +9089,11 @@ fold_builtin_1 (location_t loc, tree fndecl, tree arg0)
>return fold_builtin_bitop (fndecl, arg0);
>
>  CASE_FLT_FN (BUILT_IN_SIGNBIT):
> -  return fold_builtin_signbit (loc, arg0, type);
> +  if (TREE_CODE (arg0) == REAL_CST && !TREE_OVERFLOW (arg0))
> +   return (REAL_VALUE_NEGATIVE (TREE_REAL_CST (arg0))
> +   ? build_one_cst (type)
> +   : build_zero_cst (type));
> +  break;
>
>  CASE_FLT_FN (BUILT_IN_SIGNIFICAND):
>return fold_builtin_significand (loc, arg0, type);
> diff --git a/gcc/match.pd b/gcc/match.pd
> index 303889b..e50f5bb 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -102,6 +102,7 @@ DEFINE_MATH_FN (COPYSIGN)
>  DEFINE_MATH_FN (CABS)
>  DEFINE_MATH_FN (TRUNC)
>  DEFINE_MATH_FN (NEARBYINT)
> +DEFINE_MATH_FN (SIGNBIT)
>
>  DEFINE_INT_AND_FLOAT_ROUND_FN (FLOOR)
>  DEFINE_INT_AND_FLOAT_ROUND_FN (CEIL)
> @@ -2924,3 +2925,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>(if (INTEGRAL_TYPE_P (TREE_TYPE (@0)))
> (op @0 (ext @1 @2)
>
> +(simplify
> + /* signbit(x) -> 0 if x is nonnegative.  */
> + (SIGNBIT tree_expr_nonnegative_p@0)
> + { integer_zero_node; })
> +
> +(simplify
> + /* signbit(x) -> x<0 if x doesn't have signed zeros.  */
> + (SIGNBIT @0)
> + (if (!HONOR_SIGNED_ZEROS (@0))
> +  (convert (lt @0 { build_real (TREE_TYPE (@0), dconst0); }
> diff --git a/gcc/testsuite/gcc.dg/torture/builtin-nonneg-1.c 
> b/gcc/testsuite/gcc.dg/torture/builtin-nonneg-1.c
> index 8a3286a..46f6fa6 100644
> --- a/gcc/testsuite/gcc.dg/torture/builtin-nonneg-1.c
> +++ b/gcc/testsuite/gcc.dg/torture/builtin-nonneg-1.c
> @@ -6,7 +6,11 @@
> Written by Kaveh Ghazi, 2004-03-10.  */
>
>  /* { dg-do link } */
> -/* { dg-options "-ffast-math" } */
> +/* This test needs more recursion than the default.  PR 68097 is about
> +   adding proper range information for reals, so that no recursion
> +   would be necessary.  */
> +/* { dg-options "-ffast-math --param max-ssa-name-query-depth=3" } */
> +/* { dg-skip-if "" { *-*-* } { "-O0" } { "" } } */
>
>  #define PROTOTYPE_RTYPE(FN,RTYPE) extern RTYPE FN(double); \
>extern RTYPE FN##f(float); \
>


Re: [patch] Extend former fold_widened_comparison to all integral types

2015-10-26 Thread Eric Botcazou
> I think excluding enums had sth to do with C++ -f[no-]strict-enums
> (whatever is the default).  Just tried to figure where the check
> came from ... both calls are keyed on INTEGER_TYPE...

Here's the relevant block of code from the C++ front-end:

  /* The middle-end currently assumes that types with TYPE_PRECISION
 narrower than their underlying type are suitably zero or sign
 extended to fill their mode.  Similarly, it assumes that the front
 end assures that a value of a particular type must be within
 TYPE_MIN_VALUE and TYPE_MAX_VALUE.

 We used to set these fields based on bmin and bmax, but that led
 to invalid assumptions like optimizing away bounds checking.  So
 now we just set the TYPE_PRECISION, TYPE_MIN_VALUE, and
 TYPE_MAX_VALUE to the values for the mode above and only restrict
 the ENUM_UNDERLYING_TYPE for the benefit of diagnostics.  */
  ENUM_UNDERLYING_TYPE (enumtype)
= build_distinct_type_copy (underlying_type);
  TYPE_PRECISION (ENUM_UNDERLYING_TYPE (enumtype)) = precision;
  set_min_and_max_values_for_integral_type
(ENUM_UNDERLYING_TYPE (enumtype), precision, sgn);

  /* If -fstrict-enums, still constrain TYPE_MIN/MAX_VALUE.  */
  if (flag_strict_enums)
set_min_and_max_values_for_integral_type (enumtype, precision, sgn);

So the compiler should still not optimize if -fno-strict-enums AFAICS.

-- 
Eric Botcazou


Re: Split constant handling out of fold_builtin_fma

2015-10-26 Thread Richard Biener
On Mon, Oct 26, 2015 at 10:57 AM, Richard Sandiford
 wrote:
> Just makes an upcoming patch a bit clearer.
>
> Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi.
> OK to install?

Ok.

Thanks,
Richard.

> Thanks,
> Richard
>
>
> gcc/
> * builtins.c (fold_builtin_fma): Remove constant handling.
> (fold_builtin_3): Handle constant fma arguments here.
>
> diff --git a/gcc/builtins.c b/gcc/builtins.c
> index a03dffc..6cd8879 100644
> --- a/gcc/builtins.c
> +++ b/gcc/builtins.c
> @@ -7881,18 +7881,13 @@ fold_fma (location_t loc ATTRIBUTE_UNUSED,
>  static tree
>  fold_builtin_fma (location_t loc, tree arg0, tree arg1, tree arg2, tree type)
>  {
> +  /* ??? Only expand to FMA_EXPR if it's directly supported.  */
>if (validate_arg (arg0, REAL_TYPE)
>&& validate_arg (arg1, REAL_TYPE)
> -  && validate_arg (arg2, REAL_TYPE))
> -{
> -  tree tem = fold_fma (loc, type, arg0, arg1, arg2);
> -  if (tem)
> -   return tem;
> +  && validate_arg (arg2, REAL_TYPE)
> +  && optab_handler (fma_optab, TYPE_MODE (type)) != CODE_FOR_nothing)
> +return fold_build3_loc (loc, FMA_EXPR, type, arg0, arg1, arg2);
>
> -  /* ??? Only expand to FMA_EXPR if it's directly supported.  */
> -  if (optab_handler (fma_optab, TYPE_MODE (type)) != CODE_FOR_nothing)
> -return fold_build3_loc (loc, FMA_EXPR, type, arg0, arg1, arg2);
> -}
>return NULL_TREE;
>  }
>
> @@ -9307,8 +9302,9 @@ fold_builtin_3 (location_t loc, tree fndecl,
>return fold_builtin_sincos (loc, arg0, arg1, arg2);
>
>  CASE_FLT_FN (BUILT_IN_FMA):
> +  if (tree tem = fold_fma (loc, type, arg0, arg1, arg2))
> +   return tem;
>return fold_builtin_fma (loc, arg0, arg1, arg2, type);
> -break;
>
>  CASE_FLT_FN (BUILT_IN_REMQUO):
>if (validate_arg (arg0, REAL_TYPE)
>


Re: [PATCH 5/9] ENABLE_CHECKING refactoring: pool allocators

2015-10-26 Thread Mikhail Maltsev
On 10/26/2015 12:47 PM, Richard Biener wrote:
> I committed the attached to fix build with the valgrind annotations active.
> 
> Richard.
> 
Doh! Sorry for breakage.

-- 
Regards,
Mikhail Maltsev


[comitted] Add make_restrict_var_constraints

2015-10-26 Thread Tom de Vries

Hi,

this no-functional-changes patch factors a new function 
make_restrict_var_constraints out of intra_create_variable_infos.


Bootstrapped and reg-tested on x86_64.

Committed as trivial.

Thanks,
- Tom
Add make_restrict_var_constraints

2015-10-26  Tom de Vries  

	* tree-ssa-structalias.c (make_restrict_var_constraints): New function,
	factored out of ...
	(intra_create_variable_infos): ... here.
---
 gcc/tree-ssa-structalias.c | 24 
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/gcc/tree-ssa-structalias.c b/gcc/tree-ssa-structalias.c
index 1e1ae95..63a3d02 100644
--- a/gcc/tree-ssa-structalias.c
+++ b/gcc/tree-ssa-structalias.c
@@ -5844,6 +5844,21 @@ debug_solution_for_var (unsigned int var)
   dump_solution_for_var (stderr, var);
 }
 
+/* Register the constraints for restrict var VI.  */
+
+static void
+make_restrict_var_constraints (varinfo_t vi)
+{
+  for (; vi; vi = vi_next (vi))
+if (vi->may_have_pointers)
+  {
+	if (vi->only_restrict_pointers)
+	  make_constraint_from_global_restrict (vi, "GLOBAL_RESTRICT");
+	else
+	  make_copy_constraint (vi, nonlocal_id);
+  }
+}
+
 /* Create varinfo structures for all of the variables in the
function for intraprocedural mode.  */
 
@@ -5882,14 +5897,7 @@ intra_create_variable_infos (struct function *fn)
 	  vi->is_restrict_var = 1;
 	  insert_vi_for_tree (heapvar, vi);
 	  make_constraint_from (p, vi->id);
-	  for (; vi; vi = vi_next (vi))
-	if (vi->may_have_pointers)
-	  {
-		if (vi->only_restrict_pointers)
-		  make_constraint_from_global_restrict (vi, "GLOBAL_RESTRICT");
-		else
-		  make_copy_constraint (vi, nonlocal_id);
-	  }
+	  make_restrict_var_constraints (vi);
 	  continue;
 	}
 
-- 
1.9.1



Re: Move ldexp, scalbn and scalbln folds to match.pd

2015-10-26 Thread Richard Biener
On Mon, Oct 26, 2015 at 11:08 AM, Richard Sandiford
 wrote:
> Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi.
> OK to install?

Ok.

Thanks,
Richard.

> Thanks,
> Richard
>
>
> gcc/
> * builtins.c (fold_builtin_load_exponent): Rename to...
> (fold_const_builtin_load_exponent): ...this and only handle
> constant arguments.
> (fold_builtin_2): Update accordingly.
> * match.pd: Add rules previously handled by 
> fold_builtin_load_exponent.
>
> gcc/testsuite/
> * gcc.dg/torture/builtin-ldexp-1.c: Skip at -O9,
>
> diff --git a/gcc/builtins.c b/gcc/builtins.c
> index 260b66d..248c009 100644
> --- a/gcc/builtins.c
> +++ b/gcc/builtins.c
> @@ -8060,20 +8060,11 @@ fold_builtin_frexp (location_t loc, tree arg0, tree 
> arg1, tree rettype)
> check the mode of the TYPE parameter in certain cases.  */
>
>  static tree
> -fold_builtin_load_exponent (location_t loc, tree arg0, tree arg1,
> -   tree type, bool ldexp)
> +fold_const_builtin_load_exponent (tree arg0, tree arg1,
> + tree type, bool ldexp)
>  {
>if (validate_arg (arg0, REAL_TYPE) && validate_arg (arg1, INTEGER_TYPE))
>  {
> -  STRIP_NOPS (arg0);
> -  STRIP_NOPS (arg1);
> -
> -  /* If arg0 is 0, Inf or NaN, or if arg1 is 0, then return arg0.  */
> -  if (real_zerop (arg0) || integer_zerop (arg1)
> - || (TREE_CODE (arg0) == REAL_CST
> - && !real_isfinite (_REAL_CST (arg0
> -   return omit_one_operand_loc (loc, type, arg0, arg1);
> -
>/* If both arguments are constant, then try to evaluate it.  */
>if ((ldexp || REAL_MODE_FORMAT (TYPE_MODE (type))->b == 2)
>   && TREE_CODE (arg0) == REAL_CST && !TREE_OVERFLOW (arg0)
> @@ -9126,11 +9117,12 @@ fold_builtin_2 (location_t loc, tree fndecl, tree 
> arg0, tree arg1)
>  break;
>
>  CASE_FLT_FN (BUILT_IN_LDEXP):
> -  return fold_builtin_load_exponent (loc, arg0, arg1, type, 
> /*ldexp=*/true);
> +  return fold_const_builtin_load_exponent (arg0, arg1, type,
> +  /*ldexp=*/true);
>  CASE_FLT_FN (BUILT_IN_SCALBN):
>  CASE_FLT_FN (BUILT_IN_SCALBLN):
> -  return fold_builtin_load_exponent (loc, arg0, arg1,
> -type, /*ldexp=*/false);
> +  return fold_const_builtin_load_exponent (arg0, arg1, type,
> +  /*ldexp=*/false);
>
>  CASE_FLT_FN (BUILT_IN_FREXP):
>return fold_builtin_frexp (loc, arg0, arg1, type);
> diff --git a/gcc/match.pd b/gcc/match.pd
> index f2e7d64..b15f42f 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -105,6 +105,9 @@ DEFINE_MATH_FN (NEARBYINT)
>  DEFINE_MATH_FN (SIGNBIT)
>  DEFINE_MATH_FN (FMIN)
>  DEFINE_MATH_FN (FMAX)
> +DEFINE_MATH_FN (LDEXP)
> +DEFINE_MATH_FN (SCALBN)
> +DEFINE_MATH_FN (SCALBLN)
>
>  DEFINE_INT_AND_FLOAT_ROUND_FN (FLOOR)
>  DEFINE_INT_AND_FLOAT_ROUND_FN (CEIL)
> @@ -2580,6 +2583,21 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>   (COPYSIGN @0 tree_expr_nonnegative_p@1)
>   (abs @0))
>
> +(for scale (LDEXP SCALBN SCALBLN)
> + /* ldexp(0, x) -> 0.  */
> + (simplify
> +  (scale real_zerop@0 @1)
> +  @0)
> + /* ldexp(x, 0) -> x.  */
> + (simplify
> +  (scale @0 integer_zerop@1)
> +  @0)
> + /* ldexp(x, y) -> x if x is +-Inf or NaN.  */
> + (simplify
> +  (scale REAL_CST@0 @1)
> +  (if (!real_isfinite (TREE_REAL_CST_PTR (@0)))
> +   @0)))
> +
>  /* Canonicalization of sequences of math builtins.  These rules represent
> IL simplifications but are not necessarily optimizations.
>
> diff --git a/gcc/testsuite/gcc.dg/torture/builtin-ldexp-1.c 
> b/gcc/testsuite/gcc.dg/torture/builtin-ldexp-1.c
> index 94560a8..6412274 100644
> --- a/gcc/testsuite/gcc.dg/torture/builtin-ldexp-1.c
> +++ b/gcc/testsuite/gcc.dg/torture/builtin-ldexp-1.c
> @@ -7,6 +7,7 @@
>
>  /* { dg-do link } */
>  /* { dg-options "-fno-finite-math-only" { target sh*-*-* } } */
> +/* { dg-skip-if "" { *-*-* } { "-O0" } { "" } } */
>
>  extern void link_error(int);
>
>


Re: [PATCH] Fix VEC_COND_EXPR types when vectorizing conditional expressions

2015-10-26 Thread Richard Biener
On Mon, Oct 26, 2015 at 12:12 PM, Alan Hayward  wrote:
> VEC_COND_EXPRs have been changed to use boolean vectors for the first
> argument.
> This changes the vectorizing conditional expressions to use this new
> format,
> fixing the compiler failures for the 65947-*.c tests.

Ok.

Richard.

>
> 2015-10-26  Alan Hayward 
>
> gcc/
> PR tree-optimization/65947
> * tree-vect-loop.c (vect_create_epilog_for_reduction):
> Fix VEC_COND_EXPR types.
>
>
> Cheers,
> Alan.
>
>
>


Re: [PATCH][auto-inc-dec.c] Account for cost of move operation in FORM_PRE_ADD and FORM_POST_ADD cases

2015-10-26 Thread Bernd Schmidt

On 10/26/2015 12:12 PM, Bernd Schmidt wrote:


But isn't that balanced by the fact that it doesn't seem to take into
account the gain of removing the inc_insn either? So I think this can't
be right.


Argh, misread the code. The patch is OK with the change I suggested.


Bernd


Re: Handle OBJ_TYPE_REF in operand_equal_p

2015-10-26 Thread Richard Biener
On Sat, Oct 24, 2015 at 7:31 PM, Jan Hubicka  wrote:
> Hello,
> this patch adds OBJ_TYPE_REF that is the only code handled by ipa-icf-gimple
> but not bu operand_equal_p.  I tried to make the following testcase:
>
> /* { dg-do compile } */
> /* { dg-options "-O2 -fdump-tree-pre" } */
> struct foo {
>   virtual int test ();
> };
>
> int ret (struct foo *f, int v)
> {
>return v ? f->test() : f->test();
> }
> /* { dg-final { scan-tree-dump-not "if " "pre"} } */
>
> But we fail to tailmerge the code:
>   :
>   if (v_3(D) != 0)
> goto ;
>   else
> goto ;
>
>   :
>   _6 = f_5(D)->_vptr.foo;
>   _7 = *_6;
>   _9 = OBJ_TYPE_REF(_7;(struct foo)f_5(D)->0) (f_5(D)); [tail call]
>   goto ;
>
>   :
>   _10 = f_5(D)->_vptr.foo;
>   _11 = *_10;
>   _13 = OBJ_TYPE_REF(_11;(struct foo)f_5(D)->0) (f_5(D)); [tail call]
>
> This is because the OBJ_TYPE_REF are not equal without unifing _7 with _11
> and _6 with _10 that we don't do, because we don't have head merging.
>
> We ought to be able to do so once tail merge is witched to ipa-icf-gimple
> and ipa-icf-gimple to operand_equal_p.  Otherwsie i think we are hitting to
> limitation of tree-ssa-sccvn that may want similar matching somewhere.
>
> Once I have bit of time I will work on removing of OBJ_TYPE_REF wrappers
> produced by objective-C in gimplification and then all the
> virtual_method_call_p calls can go. The naive approach of simply not building
> them does not work, perhaps we want to have separate OBJC tree code, since 
> they
> do not really represent virtual calls after all, but I got stuck on adding new
> tree codes to objc becuase handling of tree.def between C/C++/obj-C/obj-C++
> FEs is very convoluted.
>
> Bootstrapped/regtested x86_64-linx, OK?
>
> Honza
>
>
> * fold-const.c (operand_equal_p): Handle OBJ_TYPE_REF
>
> Index: fold-const.c
> ===
> --- fold-const.c(revision 229278)
> +++ fold-const.c(working copy)
> @@ -3085,6 +3082,27 @@ operand_equal_p (const_tree arg0, const_
> case DOT_PROD_EXPR:
>   return OP_SAME (0) && OP_SAME (1) && OP_SAME (2);
>
> +   case OBJ_TYPE_REF:
> + /* OBJ_TYPE_REF is just a wrapper around OBJ_TYP_REF_EXPR.  */
> + if (!operand_equal_p (OBJ_TYPE_REF_EXPR (arg0),
> +   OBJ_TYPE_REF_EXPR (arg1), flags))
> +   return false;
> +
> + /* Objective-C frontend produce ill formed OBJ_TYPE_REF which
> +probably should be dropped before reaching middle-end.  */
> + if (!virtual_method_call_p (arg0) || !virtual_method_call_p (arg1))
> +   return false;

So what kind of brokeness is this?

> + /* Match the type information stored in the wrapper.  */
> +
> + flags &= ~(OEP_CONSTANT_ADDRESS_OF|OEP_ADDRESS_OF);
> + return (tree_to_uhwi (OBJ_TYPE_REF_TOKEN (arg0))
> + == tree_to_uhwi (OBJ_TYPE_REF_TOKEN (arg1))

Err, please use tree_int_cst_eq ()

> + && types_same_for_odr (obj_type_ref_class (arg0),
> +obj_type_ref_class (arg1))

Why do you need this check?  The args of OBJ_TYPE_REF should be fully
specifying the object, no?

> + && operand_equal_p (OBJ_TYPE_REF_OBJECT (arg0),
> + OBJ_TYPE_REF_OBJECT (arg1),
> + flags));
> default:
>   return 0;
> }


Re: [PATCH, PR68062] Fix uniform vector operation lowering

2015-10-26 Thread Ilya Enkovich
On 26 Oct 10:09, Richard Biener wrote:
> On Sat, Oct 24, 2015 at 12:29 AM, Ilya Enkovich  
> wrote:
> > 2015-10-24 0:32 GMT+03:00 Jeff Law :
> >> On 10/23/2015 09:26 AM, Ilya Enkovich wrote:
> >>>
> >>> Hi,
> >>>
> >>> This patch checks optab exists before using it vector vector statement
> >>> lowering.  It fixes compilation of test from PR68062 with -funsigned-char
> >>> option added (doesn't fix original testcase).  Bootstrapped for
> >>> x86_64-unknown-linux-gnu.  OK for trunk if no regressions?
> >>>
> >>> Thanks,
> >>> Ilya
> >>> --
> >>> gcc/
> >>>
> >>> 2015-10-23  Ilya Enkovich  
> >>>
> >>> * tree-vect-generic.c (expand_vector_operations_1): Check
> >>> optab exists before use it.
> >>>
> >>> gcc/testsuite/
> >>>
> >>> 2015-10-23  Ilya Enkovich  
> >>>
> >>> * g++.dg/pr68062.C: New test.
> >>
> >> OK.
> >>
> >> Just curious, what was the tree code for which we couldn't find a suitable
> >> optab?
> >
> > Those are various comparison codes.
> 
> Yeah, sorry for missing that check.  Btw, I was curious to see that we miss
> a way to query from optab_tag the "kind" (normal, conversion, etc.) so code
> can decide what optab_handler function to call (optab_handler or
> convert_optab_handler).  So the code I added errs on the "simplistic" side
> and hopes that matching lhs and rhs1 type always gets us a non-convert 
> optab...

So probably better fix is

diff --git a/gcc/tree-vect-generic.c b/gcc/tree-vect-generic.c
index d1fc0ba..73c5cc5 100644
--- a/gcc/tree-vect-generic.c
+++ b/gcc/tree-vect-generic.c
@@ -1533,7 +1533,8 @@ expand_vector_operations_1 (gimple_stmt_iterator *gsi)
   && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (TREE_TYPE (srhs1)))
 {
   op = optab_for_tree_code (code, TREE_TYPE (type), optab_scalar);
-  if (optab_handler (op, TYPE_MODE (TREE_TYPE (type))) != CODE_FOR_nothing)
+  if (op >= FIRST_NORM_OPTAB && op <= LAST_NORM_OPTAB
+ && optab_handler (op, TYPE_MODE (TREE_TYPE (type))) != 
CODE_FOR_nothing)
{
  tree slhs = make_ssa_name (TREE_TYPE (srhs1));
  gimple *repl = gimple_build_assign (slhs, code, srhs1, srhs2);

?

Ilya

> 
> Richard.
> 
> > Ilya
> >
> >>
> >> jeff
> >>


Move signbit folds to match.pd

2015-10-26 Thread Richard Sandiford
Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi.
OK to install?

Thanks,
Richard


gcc/
* builtins.c (fold_builtin_signbit): Delete.
(fold_builtin_2): Handle constant signbit arguments here.
* match.pd: Add rules previously handled by fold_builtin_signbit.

gcc/testsuite/
PR tree-optimization/68097
* gcc.dg/torture/builtin-nonneg-1.c: Skip at -O0.  Add
--param max-ssa-name-query-depth=3 to dg-options.

diff --git a/gcc/builtins.c b/gcc/builtins.c
index e5a00ee..ae7e7ef 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -162,7 +162,6 @@ static tree fold_builtin_memchr (location_t, tree, tree, 
tree, tree);
 static tree fold_builtin_memcmp (location_t, tree, tree, tree);
 static tree fold_builtin_strcmp (location_t, tree, tree);
 static tree fold_builtin_strncmp (location_t, tree, tree, tree);
-static tree fold_builtin_signbit (location_t, tree, tree);
 static tree fold_builtin_isascii (location_t, tree);
 static tree fold_builtin_toascii (location_t, tree);
 static tree fold_builtin_isdigit (location_t, tree);
@@ -7782,40 +7781,6 @@ fold_builtin_strncmp (location_t loc, tree arg1, tree 
arg2, tree len)
   return NULL_TREE;
 }
 
-/* Fold function call to builtin signbit, signbitf or signbitl with argument
-   ARG.  Return NULL_TREE if no simplification can be made.  */
-
-static tree
-fold_builtin_signbit (location_t loc, tree arg, tree type)
-{
-  if (!validate_arg (arg, REAL_TYPE))
-return NULL_TREE;
-
-  /* If ARG is a compile-time constant, determine the result.  */
-  if (TREE_CODE (arg) == REAL_CST
-  && !TREE_OVERFLOW (arg))
-{
-  REAL_VALUE_TYPE c;
-
-  c = TREE_REAL_CST (arg);
-  return (REAL_VALUE_NEGATIVE (c)
- ? build_one_cst (type)
- : build_zero_cst (type));
-}
-
-  /* If ARG is non-negative, the result is always zero.  */
-  if (tree_expr_nonnegative_p (arg))
-return omit_one_operand_loc (loc, type, integer_zero_node, arg);
-
-  /* If ARG's format doesn't have signed zeros, return "arg < 0.0".  */
-  if (!HONOR_SIGNED_ZEROS (arg))
-return fold_convert (type,
-fold_build2_loc (loc, LT_EXPR, boolean_type_node, arg,
-   build_real (TREE_TYPE (arg), dconst0)));
-
-  return NULL_TREE;
-}
-
 /* Fold function call to builtin copysign, copysignf or copysignl with
arguments ARG1 and ARG2.  Return NULL_TREE if no simplification can
be made.  */
@@ -9124,7 +9089,11 @@ fold_builtin_1 (location_t loc, tree fndecl, tree arg0)
   return fold_builtin_bitop (fndecl, arg0);
 
 CASE_FLT_FN (BUILT_IN_SIGNBIT):
-  return fold_builtin_signbit (loc, arg0, type);
+  if (TREE_CODE (arg0) == REAL_CST && !TREE_OVERFLOW (arg0))
+   return (REAL_VALUE_NEGATIVE (TREE_REAL_CST (arg0))
+   ? build_one_cst (type)
+   : build_zero_cst (type));
+  break;
 
 CASE_FLT_FN (BUILT_IN_SIGNIFICAND):
   return fold_builtin_significand (loc, arg0, type);
diff --git a/gcc/match.pd b/gcc/match.pd
index 303889b..e50f5bb 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -102,6 +102,7 @@ DEFINE_MATH_FN (COPYSIGN)
 DEFINE_MATH_FN (CABS)
 DEFINE_MATH_FN (TRUNC)
 DEFINE_MATH_FN (NEARBYINT)
+DEFINE_MATH_FN (SIGNBIT)
 
 DEFINE_INT_AND_FLOAT_ROUND_FN (FLOOR)
 DEFINE_INT_AND_FLOAT_ROUND_FN (CEIL)
@@ -2924,3 +2925,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)))
(op @0 (ext @1 @2)
 
+(simplify
+ /* signbit(x) -> 0 if x is nonnegative.  */
+ (SIGNBIT tree_expr_nonnegative_p@0)
+ { integer_zero_node; })
+
+(simplify
+ /* signbit(x) -> x<0 if x doesn't have signed zeros.  */
+ (SIGNBIT @0)
+ (if (!HONOR_SIGNED_ZEROS (@0))
+  (convert (lt @0 { build_real (TREE_TYPE (@0), dconst0); }
diff --git a/gcc/testsuite/gcc.dg/torture/builtin-nonneg-1.c 
b/gcc/testsuite/gcc.dg/torture/builtin-nonneg-1.c
index 8a3286a..46f6fa6 100644
--- a/gcc/testsuite/gcc.dg/torture/builtin-nonneg-1.c
+++ b/gcc/testsuite/gcc.dg/torture/builtin-nonneg-1.c
@@ -6,7 +6,11 @@
Written by Kaveh Ghazi, 2004-03-10.  */
 
 /* { dg-do link } */
-/* { dg-options "-ffast-math" } */
+/* This test needs more recursion than the default.  PR 68097 is about
+   adding proper range information for reals, so that no recursion
+   would be necessary.  */
+/* { dg-options "-ffast-math --param max-ssa-name-query-depth=3" } */
+/* { dg-skip-if "" { *-*-* } { "-O0" } { "" } } */
 
 #define PROTOTYPE_RTYPE(FN,RTYPE) extern RTYPE FN(double); \
   extern RTYPE FN##f(float); \



Re: [patch] Extend former fold_widened_comparison to all integral types

2015-10-26 Thread Richard Biener
On Mon, Oct 26, 2015 at 9:39 AM, Eric Botcazou  wrote:
> Hi,
>
> this patch extends the simplification formerly done in fold_widened_comparison
> and now in match.pd to all integral types instead of just integer types, and
> comes with an Ada testcase for the enumeral type case.
>
> The patch introduces a failure in the C testsuite:
>
> FAIL: gcc.dg/atomic-noinline.c execution test
>
> because the testcase is broken:
>
>   /* The fake external function should return 10.  */
>   if (__atomic_is_lock_free (4, 0) != 10)
> abort ();
>
> __atomic_is_lock_free returns a boolean so it cannot return 10...
>
> Tested on x86_64-suse-linux, OK for the mainline?

I think excluding enums had sth to do with C++ -f[no-]strict-enums
(whatever is the default).  Just tried to figure where the check
came from ... both calls are keyed on INTEGER_TYPE...

OTOH if testing passes then the patch is obviously ok.

Thanks,
Richard.

>
> 2015-10-26  Eric Botcazou  
>
> * match.pd (fold_widened_comparison): Apply simplifications to
> all integral types.
>
>
> 2015-10-26  Eric Botcazou  
>
> * gcc.dg/atomic-noinline.c: Fix test on __atomic_is_lock_free.
> * gcc.dg/atomic-noinline-aux.c: Fix its return type.
> * gnat.dg/opt51.adb: New test.
> * gnat.dg/opt51_pkg.ads: New helper.
>
>
> --
> Eric Botcazou


Move min(max...) and max(min...) folds to match.pd

2015-10-26 Thread Richard Sandiford
This handles both integer and floating-point arguments.  It's needed
for the follow-on patch to move fmin and fmax to match.pd.

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

Thanks,
Richard


gcc/
* fold-const.c (fold_minmax): Delete.
(fold_binary_loc): Don't call it.
* match.pd: Add rules previously handled by fold_minmax.

diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index ffad732..e8ff1de 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -8073,49 +8073,6 @@ fold_truth_andor (location_t loc, enum tree_code code, 
tree type,
   return NULL_TREE;
 }
 
-/* Fold a binary expression of code CODE and type TYPE with operands
-   OP0 and OP1, containing either a MIN-MAX or a MAX-MIN combination.
-   Return the folded expression if folding is successful.  Otherwise,
-   return NULL_TREE.  */
-
-static tree
-fold_minmax (location_t loc, enum tree_code code, tree type, tree op0, tree 
op1)
-{
-  enum tree_code compl_code;
-
-  if (code == MIN_EXPR)
-compl_code = MAX_EXPR;
-  else if (code == MAX_EXPR)
-compl_code = MIN_EXPR;
-  else
-gcc_unreachable ();
-
-  /* MIN (MAX (a, b), b) == b.  */
-  if (TREE_CODE (op0) == compl_code
-  && operand_equal_p (TREE_OPERAND (op0, 1), op1, 0))
-return omit_one_operand_loc (loc, type, op1, TREE_OPERAND (op0, 0));
-
-  /* MIN (MAX (b, a), b) == b.  */
-  if (TREE_CODE (op0) == compl_code
-  && operand_equal_p (TREE_OPERAND (op0, 0), op1, 0)
-  && reorder_operands_p (TREE_OPERAND (op0, 1), op1))
-return omit_one_operand_loc (loc, type, op1, TREE_OPERAND (op0, 1));
-
-  /* MIN (a, MAX (a, b)) == a.  */
-  if (TREE_CODE (op1) == compl_code
-  && operand_equal_p (op0, TREE_OPERAND (op1, 0), 0)
-  && reorder_operands_p (op0, TREE_OPERAND (op1, 1)))
-return omit_one_operand_loc (loc, type, op0, TREE_OPERAND (op1, 1));
-
-  /* MIN (a, MAX (b, a)) == a.  */
-  if (TREE_CODE (op1) == compl_code
-  && operand_equal_p (op0, TREE_OPERAND (op1, 1), 0)
-  && reorder_operands_p (op0, TREE_OPERAND (op1, 0)))
-return omit_one_operand_loc (loc, type, op0, TREE_OPERAND (op1, 0));
-
-  return NULL_TREE;
-}
-
 /* Helper that tries to canonicalize the comparison ARG0 CODE ARG1
by changing CODE to reduce the magnitude of constants involved in
ARG0 of the comparison.
@@ -10426,15 +10383,7 @@ fold_binary_loc (location_t loc,
   return NULL_TREE;
 
 case MIN_EXPR:
-  tem = fold_minmax (loc, MIN_EXPR, type, arg0, arg1);
-  if (tem)
-   return tem;
-  goto associate;
-
 case MAX_EXPR:
-  tem = fold_minmax (loc, MAX_EXPR, type, arg0, arg1);
-  if (tem)
-   return tem;
   goto associate;
 
 case TRUTH_ANDIF_EXPR:
diff --git a/gcc/match.pd b/gcc/match.pd
index e02379f..338644c 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -1176,6 +1176,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  (simplify
   (minmax @0 @0)
   @0))
+/* min(max(x,y),y) -> y.  */
+(simplify
+ (min:c (max:c @0 @1) @1)
+ @1)
+/* max(min(x,y),y) -> y.  */
+(simplify
+ (max:c (min:c @0 @1) @1)
+ @1)
 (simplify
  (min @0 @1)
  (if (INTEGRAL_TYPE_P (type)



Move ldexp, scalbn and scalbln folds to match.pd

2015-10-26 Thread Richard Sandiford
Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi.
OK to install?

Thanks,
Richard


gcc/
* builtins.c (fold_builtin_load_exponent): Rename to...
(fold_const_builtin_load_exponent): ...this and only handle
constant arguments.
(fold_builtin_2): Update accordingly.
* match.pd: Add rules previously handled by fold_builtin_load_exponent.

gcc/testsuite/
* gcc.dg/torture/builtin-ldexp-1.c: Skip at -O9,

diff --git a/gcc/builtins.c b/gcc/builtins.c
index 260b66d..248c009 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -8060,20 +8060,11 @@ fold_builtin_frexp (location_t loc, tree arg0, tree 
arg1, tree rettype)
check the mode of the TYPE parameter in certain cases.  */
 
 static tree
-fold_builtin_load_exponent (location_t loc, tree arg0, tree arg1,
-   tree type, bool ldexp)
+fold_const_builtin_load_exponent (tree arg0, tree arg1,
+ tree type, bool ldexp)
 {
   if (validate_arg (arg0, REAL_TYPE) && validate_arg (arg1, INTEGER_TYPE))
 {
-  STRIP_NOPS (arg0);
-  STRIP_NOPS (arg1);
-
-  /* If arg0 is 0, Inf or NaN, or if arg1 is 0, then return arg0.  */
-  if (real_zerop (arg0) || integer_zerop (arg1)
- || (TREE_CODE (arg0) == REAL_CST
- && !real_isfinite (_REAL_CST (arg0
-   return omit_one_operand_loc (loc, type, arg0, arg1);
-
   /* If both arguments are constant, then try to evaluate it.  */
   if ((ldexp || REAL_MODE_FORMAT (TYPE_MODE (type))->b == 2)
  && TREE_CODE (arg0) == REAL_CST && !TREE_OVERFLOW (arg0)
@@ -9126,11 +9117,12 @@ fold_builtin_2 (location_t loc, tree fndecl, tree arg0, 
tree arg1)
 break;
 
 CASE_FLT_FN (BUILT_IN_LDEXP):
-  return fold_builtin_load_exponent (loc, arg0, arg1, type, 
/*ldexp=*/true);
+  return fold_const_builtin_load_exponent (arg0, arg1, type,
+  /*ldexp=*/true);
 CASE_FLT_FN (BUILT_IN_SCALBN):
 CASE_FLT_FN (BUILT_IN_SCALBLN):
-  return fold_builtin_load_exponent (loc, arg0, arg1,
-type, /*ldexp=*/false);
+  return fold_const_builtin_load_exponent (arg0, arg1, type,
+  /*ldexp=*/false);
 
 CASE_FLT_FN (BUILT_IN_FREXP):
   return fold_builtin_frexp (loc, arg0, arg1, type);
diff --git a/gcc/match.pd b/gcc/match.pd
index f2e7d64..b15f42f 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -105,6 +105,9 @@ DEFINE_MATH_FN (NEARBYINT)
 DEFINE_MATH_FN (SIGNBIT)
 DEFINE_MATH_FN (FMIN)
 DEFINE_MATH_FN (FMAX)
+DEFINE_MATH_FN (LDEXP)
+DEFINE_MATH_FN (SCALBN)
+DEFINE_MATH_FN (SCALBLN)
 
 DEFINE_INT_AND_FLOAT_ROUND_FN (FLOOR)
 DEFINE_INT_AND_FLOAT_ROUND_FN (CEIL)
@@ -2580,6 +2583,21 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  (COPYSIGN @0 tree_expr_nonnegative_p@1)
  (abs @0))
 
+(for scale (LDEXP SCALBN SCALBLN)
+ /* ldexp(0, x) -> 0.  */
+ (simplify
+  (scale real_zerop@0 @1)
+  @0)
+ /* ldexp(x, 0) -> x.  */
+ (simplify
+  (scale @0 integer_zerop@1)
+  @0)
+ /* ldexp(x, y) -> x if x is +-Inf or NaN.  */
+ (simplify
+  (scale REAL_CST@0 @1)
+  (if (!real_isfinite (TREE_REAL_CST_PTR (@0)))
+   @0)))
+
 /* Canonicalization of sequences of math builtins.  These rules represent
IL simplifications but are not necessarily optimizations.
 
diff --git a/gcc/testsuite/gcc.dg/torture/builtin-ldexp-1.c 
b/gcc/testsuite/gcc.dg/torture/builtin-ldexp-1.c
index 94560a8..6412274 100644
--- a/gcc/testsuite/gcc.dg/torture/builtin-ldexp-1.c
+++ b/gcc/testsuite/gcc.dg/torture/builtin-ldexp-1.c
@@ -7,6 +7,7 @@
 
 /* { dg-do link } */
 /* { dg-options "-fno-finite-math-only" { target sh*-*-* } } */
+/* { dg-skip-if "" { *-*-* } { "-O0" } { "" } } */
 
 extern void link_error(int);
 



Re: [OpenACC 5/11] C++ FE changes

2015-10-26 Thread Jakub Jelinek
On Sat, Oct 24, 2015 at 02:11:41PM -0700, Cesar Philippidis wrote:
> @@ -29582,6 +29592,144 @@ cp_parser_oacc_data_clause_deviceptr (cp_parser 
> *parser, tree list)
>return list;
>  }
>  
> +/* OpenACC 2.0:
> +   auto
> +   independent
> +   nohost
> +   seq */
> +
> +static tree
> +cp_parser_oacc_simple_clause (cp_parser *ARG_UNUSED (parser),
> +   enum omp_clause_code code,
> +   tree list, location_t location)
> +{
> +  check_no_duplicate_clause (list, code, omp_clause_code_name[code], 
> location);
> +  tree c = build_omp_clause (location, code);
> +  OMP_CLAUSE_CHAIN (c) = list;
> +  return c;

Here the PARSER argument is unconditionally unused, I'd use what is used
elsewhere, i.e. cp_parser * /* parser */,

> +   idx = 1;
> +   if (ops[idx] != NULL)
> + {
> +   cp_parser_error (parser, "too many % arguements");

Typo, arguments.

> --- a/gcc/cp/semantics.c
> +++ b/gcc/cp/semantics.c
> @@ -5911,6 +5911,31 @@ finish_omp_clauses (tree clauses, bool allow_fields, 
> bool declare_simd)
>   bitmap_set_bit (_head, DECL_UID (t));
> goto handle_field_decl;
>  
> + case OMP_CLAUSE_GANG:
> + case OMP_CLAUSE_VECTOR:
> + case OMP_CLAUSE_WORKER:
> +   /* Operand 0 is the num: or length: argument.  */
> +   t = OMP_CLAUSE_OPERAND (c, 0);
> +   if (t == NULL_TREE)
> + break;
> +
> +   if (!processing_template_decl)
> + t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
> +   OMP_CLAUSE_OPERAND (c, 0) = t;
> +
> +   if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_GANG)
> + break;

I think it would be better to do the Operand 1 stuff first for
case OMP_CLAUSE_GANG: only, and then have /* FALLTHRU */ into
case OMP_CLAUSE_{VECTOR,WORKER}: which would handle the first argument.

You should add testing that the operand has INTEGRAL_TYPE_P type
(except that for processing_template_decl it can be
type_dependent_expression_p instead of INTEGRAL_TYPE_P).

Also, the if (t == NULL_TREE) stuff looks fishy, because e.g. right now
if you have OMP_CLAUSE_GANG gang (static: expr) or similar,
you wouldn't wrap the expr into cleanup point.
So, instead it should be
  if (t)
{
  if (t == error_mark_node)
remove = true;
  else if (!type_dependent_expression_p (t)
   && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
{
  error_at (OMP_CLAUSE_LOCATION (c), ...);
  remove = true;
}
  else
{
  t = mark_rvalue_use (t);
  if (!processing_template_decl)
t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
  OMP_CLAUSE_OPERAND (c, 0) = t;
}
}
or so.  Also, can the expressions be arbitrary integers, or just
non-negative, or positive?  If it is INTEGER_CST, that is something that
could be checked here too.

> else if (!type_dependent_expression_p (t)
>  && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
>   {
> -   error ("num_threads expression must be integral");
> +  switch (OMP_CLAUSE_CODE (c))
> + {
> + case OMP_CLAUSE_NUM_TASKS:
> +   error ("% expression must be integral"); break;
> + case OMP_CLAUSE_NUM_TEAMS:
> +   error ("% expression must be integral"); break;
> + case OMP_CLAUSE_NUM_THREADS:
> +   error ("% expression must be integral"); break;
> + case OMP_CLAUSE_NUM_GANGS:
> +   error ("% expression must be integral"); break;
> + case OMP_CLAUSE_NUM_WORKERS:
> +   error ("% expression must be integral");
> +   break;
> + case OMP_CLAUSE_VECTOR_LENGTH:
> +   error ("% expression must be integral");
> +   break;

When touching these, can you please use error_at (OMP_CLAUSE_LOCATION (c),
instead of error ( ?

> + default:
> +   error ("invalid argument");

What invalid argument?  I'd say that is clearly gcc_unreachable (); case.

But, I think it would be better to just use
  error_at (OMP_CLAUSE_LOCATION (c), "%qs expression must be integral",
omp_clause_code_name[c]);

> -   warning_at (OMP_CLAUSE_LOCATION (c), 0,
> -   "% value must be positive");
> +   switch (OMP_CLAUSE_CODE (c))
> + {
> + case OMP_CLAUSE_NUM_TASKS:
> +   warning_at (OMP_CLAUSE_LOCATION (c), 0,
> +   "% value must be positive");
> +   break;
> + case OMP_CLAUSE_NUM_TEAMS:
> +   warning_at (OMP_CLAUSE_LOCATION (c), 0,
> +   "% value must be positive");
> +   break;

[Ada] SPARK_Mode on synchronized units and entry declarations

2015-10-26 Thread Arnaud Charlet
This patch implements the following semantic rules:

   The SPARK_Mode aspect can be used in the following places in the code:

   * on a library-level subprogram spec or body (which now includes entry
 declarations)

   * on a library-level task spec or body

   * on a library-level protected spec or body


-- Source --


--  synchronized_spark_mode.ads

package Synchronized_SPARK_Mode is
   protected type Prot_Typ with SPARK_Mode is
  entry Prot_Ent with SPARK_Mode => Off;
   end Prot_Typ;

   task Task_Typ;
   pragma SPARK_Mode;
end Synchronized_SPARK_Mode;

--  synchronized_spark_mode.adb

package body Synchronized_SPARK_Mode is
   protected body Prot_Typ with SPARK_Mode => Off is
  entry Prot_Ent when True is
 pragma SPARK_Mode;  --  Error
  begin
 null;
  end Prot_Ent;
   end Prot_Typ;

   task body Task_Typ with SPARK_Mode => Off is
   begin
  null;
   end Task_Typ;
end Synchronized_SPARK_Mode;

-
-- Compilation --
-

$ gcc -c synchronized_spark_mode.adb
synchronized_spark_mode.adb:4:10: cannot change SPARK_Mode from Off to On
synchronized_spark_mode.adb:4:10: SPARK_Mode was set to Off at line 2

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

2015-10-26  Hristian Kirtchev  

* contracts.adb (Analyze_Subprogram_Body_Contract): Use
Unique_Defining_Entity instead of Corresponding_Spec_Of.
* einfo.adb SPARK_Pragma and SPARK_Aux_Pragma are now Node40 and
Node41 respectively.
(SPARK_Aux_Pragma): Update the assertion and node querry.
(SPARK_Aux_Pragma_Inherited): Update the assertion and node query.
(SPARK_Pragma): Update the assertion and node query.
(SPARK_Pragma_Inherited): Update the assertion and node query.
(Set_SPARK_Aux_Pragma): Update the assertion and node setting.
(Set_SPARK_Aux_Pragma_Inherited): Update the assertion and node setting.
(Set_SPARK_Pragma): Update the assertion and node setting.
(Set_SPARK_Pragma_Inherited): Update the assertion and node setting.
(Write_Field32_Name): Remove the output for SPARK_Pragma.
(Write_Field33_Name): Remove the output for SPARK_Aux_Pragma.
(Write_Field40_Name): Add output for SPARK_Pragma.
(Write_Field41_Name): Add output for SPARK_Aux_Pragma.
* einfo.ads Rewrite the documentation on attributes
SPARK_Pragma, SPARK_Aux_Pragma, SPARK_Pragma_Inherited and
SPARK_Aux_Pragma_Inherited. Update their uses in nodes.
* exp_ch4.adb (Create_Anonymous_Master): Use
Unique_Defining_Entity instead of Corresponding_Spec_Of.
* exp_ch9.adb (Expand_Entry_Declaration): Mark the barrier
function as such.
(Expand_N_Task_Body): Mark the task body as such.
(Expand_N_Task_Type_Declaration): Mark the task body as such.
* exp_unst.adb (Visit_Node): Use Unique_Defining_Entity instead
of Corresponding_Spec_Of.
* sem_attr.adb (Analyze_Attribute_Old_Result): Use
Unique_Defining_Entity instead of Corresponding_Spec_Of.
* sem_ch6.adb (Analyze_Subprogram_Body_Helper): Entry barrier
functions do not inherit the SPARK_Mode from the context.
(Build_Subprogram_Declaration): The matching spec is now marked
as a source construct to mimic the original stand alone body.
* sem_ch7.adb (Analyze_Package_Body_Helper): Code cleanup.
* sem_ch9.adb Add with and use clauses for Contracts.
(Analyze_Entry_Body): An entry body freezes the contract of
the nearest enclosing package body. The entry body now inherits
the SPARK_Mode from the context.
(Analyze_Entry_Declaration): A protected entry declaration now inherits
the SPARK_Mode from the context.
(Analyze_Protected_Body): A protected body freezes
the contract of the nearest enclosing package body. Set the
Etype of a protected body as this is neede for proper aspect
analysis. Protected bodies can now carry meaningful aspects and
those are now analyzed.
(Analyze_Protected_Type_Declaration): A protected type now inherits the
SPARK_Mode from the context.
(Analyze_Task_Body): A task body freezes the contract of the
nearest enclosing package body. Set the Etype of a task body
as this is needed for proper aspect analysis. A task body
now inherits the SPARK_Mode from the context.  Task bodies
can now carry meaningful aspects and those are now analyzed.
(Analyze_Task_Type_Declaration): A task type declaration now
inherits the SPARK_Mode of from the context.
* sem_ch10.adb (Analyze_Protected_Body_Stub): Protected body
stubs can now carry meaningful aspects.
(Analyze_Task_Body_Stub): Task body stubs can now carry meaningful
aspects.
* 

Re: Allow more complex call replacements in gimple-fold.c

2015-10-26 Thread Richard Biener
On Mon, Oct 26, 2015 at 11:30 AM, Richard Sandiford
 wrote:
> Richard Biener  writes:
>> On Mon, Oct 26, 2015 at 10:41 AM, Richard Sandiford
>>  wrote:
>>> An upcoming patch adds a match.pd rule that folds pow(pow(x,y),z)
>>> to pow(x,y*z).  This fold can reuse the existing pow gimple statement
>>> and simply replace the operands with x and y*z.  However, the y*z
>>> itself requires a separate gimple statement and the code wasn't
>>> prepared to handle that.
>>>
>>> Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi.
>>> OK to install?
>>
>> Hmm, I put the assert there because of the !inplace case but I see the
>> is_tree_code case alredy behaves the same.
>>
>> I think the intent of fold_stmt_inplace (and thus the 'inplace' case)
>> was that no additional stmts are inserted (and obviously the
>> stmt itself being not replaced, so gsi_stmt () is the same before and
>> after).
>>
>> So I think both the is_gimple_assign && is_tree_code and the
>> case you are amending need a
>>
>>   if (inplace && !gimple_seq_empty_p (*seq))
>>return false;
>
> OK.  I was wondering about that, but the comment isn't clear whether
> inserting extra statements before the original statement is OK, as long
> as the final statement has the same form.
>
> If this hasn't caused problems for tree codes, do you think that means
> that callers don't care about extra statements matter in practice,
> that there simply aren't many fold patterns like this, or that most
> cases where this kind of fold hits are caught earlier?  Just worried
> about introducing a pessimisation...

There are not many passes restricting folding to inplace anymore.  Maybe
it's again time to re-evaluate some of them.

>
> Should we simply have that check before:
>
>   if (gcond *cond_stmt = dyn_cast  (stmt))
>
> so that it's common to all cases?

Yeah, that makes sense.

Thanks,
Richard.

> Thanks,
> Richard
>


Re: [PATCH][auto-inc-dec.c] Account for cost of move operation in FORM_PRE_ADD and FORM_POST_ADD cases

2015-10-26 Thread Kyrill Tkachov


On 26/10/15 11:28, Bernd Schmidt wrote:

On 10/26/2015 12:12 PM, Bernd Schmidt wrote:


But isn't that balanced by the fact that it doesn't seem to take into
account the gain of removing the inc_insn either? So I think this can't
be right.


Argh, misread the code. The patch is OK with the change I suggested.



Thanks!
Here's what I committed with r229344.

Kyrill

2015-10-26  Kyrylo Tkachov  

* auto-inc-dec.c (insert_move_insn_before): Delete.
(attempt_change): Remember to cost the simple move in the
FORM_PRE_ADD and FORM_POST_ADD cases.



Bernd



commit cc7c4748eac1f9d59ceb5393132c098aba99765d
Author: Kyrylo Tkachov 
Date:   Fri Oct 16 13:46:51 2015 +0100

[auto-inc-dec.c] Account for cost of move operation in FORM_PRE_ADD and FORM_POST_ADD cases

diff --git a/gcc/auto-inc-dec.c b/gcc/auto-inc-dec.c
index e003b13..9f7c8e0 100644
--- a/gcc/auto-inc-dec.c
+++ b/gcc/auto-inc-dec.c
@@ -439,24 +439,6 @@ move_dead_notes (rtx_insn *to_insn, rtx_insn *from_insn, rtx pattern)
 }
 }
 
-
-/* Create a mov insn DEST_REG <- SRC_REG and insert it before
-   NEXT_INSN.  */
-
-static rtx_insn *
-insert_move_insn_before (rtx_insn *next_insn, rtx dest_reg, rtx src_reg)
-{
-  rtx_insn *insns;
-
-  start_sequence ();
-  emit_move_insn (dest_reg, src_reg);
-  insns = get_insns ();
-  end_sequence ();
-  emit_insn_before (insns, next_insn);
-  return insns;
-}
-
-
 /* Change mem_insn.mem_loc so that uses NEW_ADDR which has an
increment of INC_REG.  To have reached this point, the change is a
legitimate one from a dataflow point of view.  The only questions
@@ -490,8 +472,21 @@ attempt_change (rtx new_addr, rtx inc_reg)
 
   old_cost = (set_src_cost (mem, mode, speed)
 	  + set_rtx_cost (PATTERN (inc_insn.insn), speed));
+
   new_cost = set_src_cost (mem_tmp, mode, speed);
 
+  /* In the FORM_PRE_ADD and FORM_POST_ADD cases we emit an extra move
+ whose cost we should account for.  */
+  if (inc_insn.form == FORM_PRE_ADD
+  || inc_insn.form == FORM_POST_ADD)
+{
+  start_sequence ();
+  emit_move_insn (inc_insn.reg_res, inc_insn.reg0);
+  mov_insn = get_insns ();
+  end_sequence ();
+  new_cost += seq_cost (mov_insn, speed);
+}
+
   /* The first item of business is to see if this is profitable.  */
   if (old_cost < new_cost)
 {
@@ -522,8 +517,8 @@ attempt_change (rtx new_addr, rtx inc_reg)
   /* Replace the addition with a move.  Do it at the location of
 	 the addition since the operand of the addition may change
 	 before the memory reference.  */
-  mov_insn = insert_move_insn_before (inc_insn.insn,
-	  inc_insn.reg_res, inc_insn.reg0);
+  gcc_assert (mov_insn);
+  emit_insn_before (mov_insn, inc_insn.insn);
   move_dead_notes (mov_insn, inc_insn.insn, inc_insn.reg0);
 
   regno = REGNO (inc_insn.reg_res);
@@ -548,8 +543,8 @@ attempt_change (rtx new_addr, rtx inc_reg)
   break;
 
 case FORM_POST_ADD:
-  mov_insn = insert_move_insn_before (mem_insn.insn,
-	  inc_insn.reg_res, inc_insn.reg0);
+  gcc_assert (mov_insn);
+  emit_insn_before (mov_insn, mem_insn.insn);
   move_dead_notes (mov_insn, inc_insn.insn, inc_insn.reg0);
 
   /* Do not move anything to the mov insn because the instruction


[Ada] Overloaded indexing operations of a derived type

2015-10-26 Thread Arnaud Charlet
This patch fixes the handling of overloaded indexing operations that are
inherited by a type derived from one that carries an indexing aspect.

Source:

---
with Ada.Text_Io; use Ada.Text_Io;
with References;
procedure Main is
  A : aliased References.Iterated;

begin
  A (1) := 42;
  Put_Line ("A (1)" & References.Object_T'Image (A (1)));
  Put_Line ("A (1, 1)" & References.Object_T'Image (A (1, 1)));
end Main;
---
package body References is
  function Find (I : aliased in out Indexed; Key : Index) return Reference_T
  is
  begin
return (Object => I.Rep (Key)'Access);
  end Find;

  function Find (I : aliased in out Indexed; Key1, Key2 : Index)
return Reference_T
  is
  begin
return (Object => I.Rep (Key1)'Access);
  end Find;

  function Find (I : aliased in out Iterated; C : Cursor) return Reference_T
  is
  begin
return (Object => I.Rep (C.I)'Access);
  end Find;

  function Has_Element (Position : Cursor) return Boolean is
  begin
return Position.Has_Element;
  end Has_Element;

  function First (Object : Iterator) return Cursor is
Has_Elements : constant Boolean := Object.First <= Object.Last;
  begin
if Has_Elements then
  return (Has_Element => True, I => Object.First);
else
  return (Has_Element => False);
end if;
  end First;

  function Next (Object : Iterator; Position : Cursor) return Cursor is
  begin
if Position.Has_Element and then Position.I /= Index'Last then
  return (Has_Element => True, I => Position.I + 1);
else
  return (Has_Element => False);
end if;
  end Next;

  function Last (Object : Iterator) return Cursor is
Has_Elements : constant Boolean := Object.First <= Object.Last;
  begin
if Has_Elements then
  return (Has_Element => True, I => Object.Last);
else
  return (Has_Element => False);
end if;
  end Last;

  function Previous (Object : Iterator; Position : Cursor) return Cursor is
  begin
if Position.Has_Element and then Position.I /= Index'First then
  return (Has_Element => True, I => Position.I - 1);
else
  return (Has_Element => False);
end if;
  end Previous;

  function Iterate (Container : Iterated)
 return Iterators.Reversible_Iterator'Class
  is
  begin
return Iterator'(First => Container.Rep'First, Last => Container.Rep'Last);
  end Iterate;
end References;
---
with Ada.Iterator_Interfaces;

package References is
  type Object_T is new Integer;

  type Reference_T (Object : not null access Object_T) is private
with Implicit_Dereference => Object;

  type Index is range 1 .. 2;

  type Array_T is array (Index) of aliased Object_T;

  type Cursor is private;

  type Indexed is tagged
record
  Rep : Array_T;
end record
with Variable_Indexing => Find;

  function Find (I : aliased in out Indexed; Key : Index) return Reference_T;
  function Find (I : aliased in out Indexed; Key1, Key2 : Index)
return Reference_T;

  function Has_Element (Position : Cursor) return Boolean;

  package Iterators is new Ada.Iterator_Interfaces (Cursor, Has_Element);

  type Iterator is new Iterators.Reversible_Iterator with
record
  First : Index;
  Last  : Index;
end record;

  function First (Object : Iterator) return Cursor;
  function Next (Object : Iterator; Position : Cursor) return Cursor;
  function Last (Object : Iterator) return Cursor;
  function Previous (Object : Iterator; Position : Cursor) return Cursor;

  type Iterated is new Indexed with null record with
Default_Iterator  => Iterate,
Iterator_Element  => Object_T;

  function Find (I : aliased in out Iterated; C : Cursor) return Reference_T;

  function Iterate
  (Container : Iterated)
   return Iterators.Reversible_Iterator'Class;

private
  type Reference_T (Object : not null access Object_T) is null record;

  type Cursor (Has_Element : Boolean := False) is
record
  case Has_Element is
when True =>
  I : Index;
when False =>
  null;
  end case;
end record;
end References;
---

Command:

   gnatmake -q main
   main

---
Output:

   A (1) 42
   A (1, 1) 42

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

2015-10-26  Ed Schonberg  

* exp_util.ads, exp_util.adb (Find_Primitive_Operations): New
subprogram to retrieve by name the possibly overloaded set of
primitive operations of a type.
* sem_ch4.adb (Try_Container_Indexing): Use
Find_Primitive_Operations to handle overloaded indexing operations
of a derived type.

Index: exp_util.adb
===
--- exp_util.adb(revision 229313)
+++ exp_util.adb(working copy)
@@ -2707,6 +2707,50 @@
   end if;
end Find_Optional_Prim_Op;
 
+   ---
+   -- Find_Primitive_Operations --
+   ---
+
+   function Find_Primitive_Operations
+ (T: Entity_Id;
+  Name : 

Re: Possible patch for PR fortran/66056

2015-10-26 Thread FX
> I ran "make && make install && make check-fortran" at the top level on 
> x86_64-pc-linux-gnu.  (I always do that before I post a patch and again 
> before I actually check anything in.  I sometimes forget to include files 
> when I finally commit, but I'm always confident that the ones I remember are 
> good :)

OK to commit.

FX

Allow more complex call replacements in gimple-fold.c

2015-10-26 Thread Richard Sandiford
An upcoming patch adds a match.pd rule that folds pow(pow(x,y),z)
to pow(x,y*z).  This fold can reuse the existing pow gimple statement
and simply replace the operands with x and y*z.  However, the y*z
itself requires a separate gimple statement and the code wasn't
prepared to handle that.

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

Thanks,
Richard


gcc/
* gimple-fold.c (replace_stmt_with_simplification): Allow calls
to have nonempty sequences.

diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c
index 1869c09..4b9b782 100644
--- a/gcc/gimple-fold.c
+++ b/gcc/gimple-fold.c
@@ -3365,7 +3365,14 @@ replace_stmt_with_simplification (gimple_stmt_iterator 
*gsi,
}
   if (i < 3)
gcc_assert (ops[i] == NULL_TREE);
-  gcc_assert (gimple_seq_empty_p (*seq));
+  if (dump_file && (dump_flags & TDF_DETAILS))
+   {
+ fprintf (dump_file, "gimple_simplified to ");
+ if (!gimple_seq_empty_p (*seq))
+   print_gimple_seq (dump_file, *seq, 0, TDF_SLIM);
+ print_gimple_stmt (dump_file, gsi_stmt (*gsi), 0, TDF_SLIM);
+   }
+  gsi_insert_seq_before (gsi, *seq, GSI_SAME_STMT);
   return true;
 }
   else if (!inplace)



Re: [PATCH 5/9] ENABLE_CHECKING refactoring: pool allocators

2015-10-26 Thread Richard Biener
On Mon, Oct 26, 2015 at 2:18 AM, Mikhail Maltsev  wrote:
> On 10/21/2015 01:57 PM, Richard Biener wrote:
>> Ugh (stupid templates).
>>
>> @@ -387,10 +389,10 @@ base_pool_allocator ::allocate ()
>>block = m_virgin_free_list;
>>header = (allocation_pool_list*) allocation_object::get_data (block);
>>header->next = NULL;
>> -#ifdef ENABLE_CHECKING
>> +
>>/* Mark the element to be free.  */
>> -  ((allocation_object*) block)->id = 0;
>> -#endif
>> +  if (flag_checking)
>> +   ((allocation_object*) block)->id = 0;
>>
>> just set id to zero unconditionally.  That'll be faster than checking
>> flag_checking.
>
> I fixed this and other issues, and committed the attached patch.

I committed the attached to fix build with the valgrind annotations active.

Richard.

2015-10-26  Richard Biener  

* alloc-pool.h (base_pool_allocator): Use placement new.
(base_pool_allocator::remove): Likewise.  Compute size outside of
flag_checking.


> --
> Regards,
> Mikhail Maltsev


p
Description: Binary data


Re: [OpenACC 4/11] C FE changes

2015-10-26 Thread Jakub Jelinek
On Sat, Oct 24, 2015 at 02:10:26PM -0700, Cesar Philippidis wrote:
> +static tree
> +c_parser_oacc_shape_clause (c_parser *parser, omp_clause_code kind,
> + const char *str, tree list)
> +{
> +  const char *id = "num";
> +  tree ops[2] = { NULL_TREE, NULL_TREE }, c;
> +  location_t loc = c_parser_peek_token (parser)->location;
> +
> +  if (kind == OMP_CLAUSE_VECTOR)
> +id = "length";
> +
> +  if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
> +{
> +  c_parser_consume_token (parser);
> +
> +  do
> + {
> +   c_token *next = c_parser_peek_token (parser);
> +   int idx = 0;
> +
> +   /* Gang static argument.  */
> +   if (kind == OMP_CLAUSE_GANG
> +   && c_parser_next_token_is_keyword (parser, RID_STATIC))
> + {
> +   c_parser_consume_token (parser);
> +
> +   if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
> + goto cleanup_error;
> +
> +   idx = 1;
> +   if (ops[idx] != NULL_TREE )

Spurious space before ).

> + {
> +   c_parser_error (parser, "too many % arguements");

Typo, arguments.

> +static tree
> +c_parser_oacc_simple_clause (c_parser *parser ATTRIBUTE_UNUSED,
> +  enum omp_clause_code code, tree list)

Please remove the useless ATTRIBUTE_UNUSED, you are using that parameter
unconditionally in c_parser_peek_token (parser).

> +{
> +  check_no_duplicate_clause (list, code, omp_clause_code_name[code]);
> +
> +  tree c = build_omp_clause (c_parser_peek_token (parser)->location, code);
> +  OMP_CLAUSE_CHAIN (c) = list;
> +
> +  return c;
> +}
> +

> +int main ()
> +{
> +  int i;
> +  int v, w;
> +  int length, num;

Can you please initialize the v/w/length/num variables?

> +  #pragma acc kernels
> +#pragma acc loop gang(16, 24) /* { dg-error "unexpected argument" } */
> +  for (i = 0; i < 10; i++)

Missing indentation of the acc loop line.

Ok for trunk with those changes fixed.

Jakub


Re: [PATCH, PR68062] Fix uniform vector operation lowering

2015-10-26 Thread Richard Biener
On Mon, Oct 26, 2015 at 10:35 AM, Ilya Enkovich  wrote:
> On 26 Oct 10:09, Richard Biener wrote:
>> On Sat, Oct 24, 2015 at 12:29 AM, Ilya Enkovich  
>> wrote:
>> > 2015-10-24 0:32 GMT+03:00 Jeff Law :
>> >> On 10/23/2015 09:26 AM, Ilya Enkovich wrote:
>> >>>
>> >>> Hi,
>> >>>
>> >>> This patch checks optab exists before using it vector vector statement
>> >>> lowering.  It fixes compilation of test from PR68062 with -funsigned-char
>> >>> option added (doesn't fix original testcase).  Bootstrapped for
>> >>> x86_64-unknown-linux-gnu.  OK for trunk if no regressions?
>> >>>
>> >>> Thanks,
>> >>> Ilya
>> >>> --
>> >>> gcc/
>> >>>
>> >>> 2015-10-23  Ilya Enkovich  
>> >>>
>> >>> * tree-vect-generic.c (expand_vector_operations_1): Check
>> >>> optab exists before use it.
>> >>>
>> >>> gcc/testsuite/
>> >>>
>> >>> 2015-10-23  Ilya Enkovich  
>> >>>
>> >>> * g++.dg/pr68062.C: New test.
>> >>
>> >> OK.
>> >>
>> >> Just curious, what was the tree code for which we couldn't find a suitable
>> >> optab?
>> >
>> > Those are various comparison codes.
>>
>> Yeah, sorry for missing that check.  Btw, I was curious to see that we miss
>> a way to query from optab_tag the "kind" (normal, conversion, etc.) so code
>> can decide what optab_handler function to call (optab_handler or
>> convert_optab_handler).  So the code I added errs on the "simplistic" side
>> and hopes that matching lhs and rhs1 type always gets us a non-convert 
>> optab...
>
> So probably better fix is
>
> diff --git a/gcc/tree-vect-generic.c b/gcc/tree-vect-generic.c
> index d1fc0ba..73c5cc5 100644
> --- a/gcc/tree-vect-generic.c
> +++ b/gcc/tree-vect-generic.c
> @@ -1533,7 +1533,8 @@ expand_vector_operations_1 (gimple_stmt_iterator *gsi)
>&& TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (TREE_TYPE (srhs1)))
>  {
>op = optab_for_tree_code (code, TREE_TYPE (type), optab_scalar);
> -  if (optab_handler (op, TYPE_MODE (TREE_TYPE (type))) != 
> CODE_FOR_nothing)
> +  if (op >= FIRST_NORM_OPTAB && op <= LAST_NORM_OPTAB
> + && optab_handler (op, TYPE_MODE (TREE_TYPE (type))) != 
> CODE_FOR_nothing)
> {
>   tree slhs = make_ssa_name (TREE_TYPE (srhs1));
>   gimple *repl = gimple_build_assign (slhs, code, srhs1, srhs2);
>
> ?

Ah, didn't know we have those constants - yes, that's a better fix.
After all we want
optab_handler to return sth sensible for it.

Thanks,
Richard.

> Ilya
>
>>
>> Richard.
>>
>> > Ilya
>> >
>> >>
>> >> jeff
>> >>


Re: Allow more complex call replacements in gimple-fold.c

2015-10-26 Thread Richard Biener
On Mon, Oct 26, 2015 at 10:41 AM, Richard Sandiford
 wrote:
> An upcoming patch adds a match.pd rule that folds pow(pow(x,y),z)
> to pow(x,y*z).  This fold can reuse the existing pow gimple statement
> and simply replace the operands with x and y*z.  However, the y*z
> itself requires a separate gimple statement and the code wasn't
> prepared to handle that.
>
> Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi.
> OK to install?

Hmm, I put the assert there because of the !inplace case but I see the
is_tree_code case alredy behaves the same.

I think the intent of fold_stmt_inplace (and thus the 'inplace' case)
was that no additional stmts are inserted (and obviously the
stmt itself being not replaced, so gsi_stmt () is the same before and
after).

So I think both the is_gimple_assign && is_tree_code and the
case you are amending need a

  if (inplace && !gimple_seq_empty_p (*seq))
   return false;

Thanks,
Richard.

> Thanks,
> Richard
>
>
> gcc/
> * gimple-fold.c (replace_stmt_with_simplification): Allow calls
> to have nonempty sequences.
>
> diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c
> index 1869c09..4b9b782 100644
> --- a/gcc/gimple-fold.c
> +++ b/gcc/gimple-fold.c
> @@ -3365,7 +3365,14 @@ replace_stmt_with_simplification (gimple_stmt_iterator 
> *gsi,
> }
>if (i < 3)
> gcc_assert (ops[i] == NULL_TREE);
> -  gcc_assert (gimple_seq_empty_p (*seq));
> +  if (dump_file && (dump_flags & TDF_DETAILS))
> +   {
> + fprintf (dump_file, "gimple_simplified to ");
> + if (!gimple_seq_empty_p (*seq))
> +   print_gimple_seq (dump_file, *seq, 0, TDF_SLIM);
> + print_gimple_stmt (dump_file, gsi_stmt (*gsi), 0, TDF_SLIM);
> +   }
> +  gsi_insert_seq_before (gsi, *seq, GSI_SAME_STMT);
>return true;
>  }
>else if (!inplace)
>


Re: [PATCH 1/2] s/390: Implement "target" attribute.

2015-10-26 Thread Dominik Vogt
On Fri, Sep 25, 2015 at 02:59:41PM +0100, Dominik Vogt wrote:
> The following set of two patches implements the function
> __attribute__ ((target("..."))) and the corresponding #pragma GCC
> target("...") on S/390.  It comes with certain limitations:
> 
>  * It is not possible to change any options that affect the ABI or
>the definition of target macros by using the attribute (vx,
>htm, zarch and others).  Some of them are still supported but
>unable to change the definition of the corresponding target macros.
>In these cases, the pragma has to be used.  One reason for this
>is that it is not possible to change the definition of the target
>macros with the attribute, but the implementation of some features
>relies on them.
> 
>  * Even with the pragma it is not possible to switch between zarch
>and esa architecture because internal data typed would have to be
>changed at Gcc run time.
> 
> The second patch contains a long term change in the interface with
> the assembler.  Currently, the compiler wrapper passes the same
> -march= and -mtune= options to the compiler and the assembler.
> The patch makes this obsolete by emitting ".machine" and
> ".machinemode" dirctives to the top of the assembly language file.
> The old way ist still supported but may be removed once the
> ".machine" feature is supported by all as versions in the field.
> 
> The second patch depends on the first one, and both require the
> (latest) change proposed in this thread:
> https://gcc.gnu.org/ml/gcc-patches/2015-09/msg01546.html

Version 3 of the patch:

 * Adapted to current HEAD.
 * Uses the B_VX and B_HTM flags in stead of the suggested B_GROUP.
 * Vector builtins depend on the VX flag instead of ZVECTOR.
 * Removed a dead error message in s390_expand_builtin.
 * Improved comment in s390.exp.

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt
IBM Germany
gcc/ChangeLog

* config/s390/s390.opt (s390_arch_string): Remove.
(s390_tune_string): Likewise.
(s390_cost_pointer): Add Variable.
(s390_arch_specified): Add TargetVariable.
(s390_tune_specified): Likewise.
(s390_tune_flags): Likewise.
(s390_arch_flags): Save option.
(march=): Likewise.
(mbackchain): Likewise.
(mdebug): Likewise.
(mesa): Likewise.
(mhard-dfp): Likewise.
(mhard-float): Likewise.
(mlong-double-128): Likewise.
(mlong-double-64): Likewise.
(mhtm): Likewise.
(mvx): Likewise.
(mpacked-stack): Likewise.
(msmall-exec): Likewise.
(msoft-float): Likewise.
(mstack-guard=): Likewise.
(mstack-size=): Likewise.
(mtune=): Likewise.
(mmvcle): Likewise.
(mzvector): Likewise.
(mzarch): Likewise.
(mbranch-cost=): Likewise.
(mwarn-dynamicstack): Likewise.
(mwarn-framesize=): Likewise.
(mwarn-dynamicstack): Allow mno-warn-dynamicstack.
(mwarn-framesize=): Convert to UInteger (negative values are rejected
now).
* config/s390/s390-c.c (s390_cpu_cpp_builtins_internal): Split setting
macros changeable through the GCC target pragma into a separate
function.
(s390_cpu_cpp_builtins): Likewise.
(s390_pragma_target_parse): New function, implement GCC target pragma
if enabled.
(s390_register_target_pragmas): Register s390_pragma_target_parse if
available.
* common/config/s390/s390-common.c (s390_handle_option):
Export.
Move setting s390_arch_flags to s390.c.
Remove s390_tune_flags.
Allow 0 as argument to -mstack-size (switch to default value).
Allow 0 as argument to -mstack-guard (switch off).
Remove now unnecessary explicit parsing code for -mwarn-framesize.
* config/s390/s390-protos.h (s390_handle_option): Export.
(s390_valid_target_attribute_tree): Export.
(s390_reset_previous_fndecl): Export.
* config/s390/s390-builtins.def: Use new macro B_GROUP to mark the start
and end of HTM and VX builtins.
(s390_asm_output_function_prefix): Declare hook.
(s390_asm_declare_function_size): Likewise.
* config/s390/s390-builtins.h (B_GROUP): Use macro.
* config/s390/s390-opts.h: Add comment about processor_type usage.
* config/s390/s390.h (TARGET_CPU_IEEE_FLOAT_P): New macro.
(TARGET_CPU_ZARCH_P): Likewise.
(TARGET_CPU_LONG_DISPLACEMENT_P): Likewise
(TARGET_CPU_EXTIMM_P): Likewise
(TARGET_CPU_DFP_P): Likewise
(TARGET_CPU_Z10_P): Likewise
(TARGET_CPU_Z196_P): Likewise
(TARGET_CPU_ZEC12_P): Likewise
(TARGET_CPU_HTM_P): Likewise
(TARGET_CPU_Z13_P): Likewise
(TARGET_CPU_VX_P): Likewise
(TARGET_HARD_FLOAT_P): Likewise
(TARGET_LONG_DISPLACEMENT_P): Likewise
(TARGET_EXTIMM_P): Likewise
(TARGET_DFP_P): Likewise

Re: Move expN folds to match.pd

2015-10-26 Thread Marc Glisse

On Mon, 26 Oct 2015, Richard Sandiford wrote:


+  /* expN(logN(x)) -> x.  */
+  (simplify
+   (exps (logs @0))
+   @0))


We are not very consistent about it, but wasn't there an idea that we 
should use non_lvalue in most such places?


--
Marc Glisse


[PATCH][auto-inc-dec.c] Account for cost of move operation in FORM_PRE_ADD and FORM_POST_ADD cases

2015-10-26 Thread Kyrill Tkachov

Hi all,

The auto_inc_dec pass can handle 4 types of sequences, described in the comment 
at the start of auto-inc-dec.c.
In two of those: FORM_PRE_ADD and FORM_POST_ADD the resulting sequence is a 
move followed by a POST_INC or PRE_INC
memory operation.
In the FORM_POST_ADD case the pass transforms:
   *a
   ...
   b <- a + c

into

   b <- a
   ...
   *(b += c) post


However, the code in attempt_change that compares the costs of the before and 
after sequences
has an oversight. When calculating the cost of the new sequence it doesn't take 
into account the cost of the
b <- a move. This patch fixes the calculation by calling seq_cost on the result 
of the emit_move_insn call
we do to emit that move.

With this patch I've seen less aggressive generation of POST_INC memory 
instructions on arm, but the post_inc
tests we have in the arm testsuite still pass, so I don't think this kills the 
usage of those instructions on
arm, just tames them somewhat.

No regressions on SPEC2000 on Cortex-A15.
SPECINT 2006 improves by a bit.

Bootstrapped and tested on arm, aarch64.
Ok for trunk?

Thanks,
Kyrill



2015-10-26  Kyrylo Tkachov  

* auto-inc-dec.c (insert_move_insn_before): Delete.
(attempt_change): Remember to cost the simple move in the
FORM_PRE_ADD and FORM_POST_ADD cases.
commit 569d1d9b789a38bf4305991d96cbb03d1665e311
Author: Kyrylo Tkachov 
Date:   Fri Oct 16 13:46:51 2015 +0100

[auto-inc-dec.c] Account for cost of move operation in FORM_PRE_ADD and FORM_POST_ADD cases

diff --git a/gcc/auto-inc-dec.c b/gcc/auto-inc-dec.c
index 3b9a1f3..af3f8b3 100644
--- a/gcc/auto-inc-dec.c
+++ b/gcc/auto-inc-dec.c
@@ -438,24 +438,6 @@ move_dead_notes (rtx_insn *to_insn, rtx_insn *from_insn, rtx pattern)
 }
 }
 
-
-/* Create a mov insn DEST_REG <- SRC_REG and insert it before
-   NEXT_INSN.  */
-
-static rtx_insn *
-insert_move_insn_before (rtx_insn *next_insn, rtx dest_reg, rtx src_reg)
-{
-  rtx_insn *insns;
-
-  start_sequence ();
-  emit_move_insn (dest_reg, src_reg);
-  insns = get_insns ();
-  end_sequence ();
-  emit_insn_before (insns, next_insn);
-  return insns;
-}
-
-
 /* Change mem_insn.mem_loc so that uses NEW_ADDR which has an
increment of INC_REG.  To have reached this point, the change is a
legitimate one from a dataflow point of view.  The only questions
@@ -489,7 +471,23 @@ attempt_change (rtx new_addr, rtx inc_reg)
 
   old_cost = (set_src_cost (mem, mode, speed)
 	  + set_rtx_cost (PATTERN (inc_insn.insn), speed));
-  new_cost = set_src_cost (mem_tmp, mode, speed);
+
+  int new_mem_cost = set_src_cost (mem_tmp, mode, speed);
+  int new_mov_cost = 0;
+
+  /* In the FORM_PRE_ADD and FORM_POST_ADD cases we emit an extra move
+ whose cost we should account for.  */
+  if (inc_insn.form == FORM_PRE_ADD
+  || inc_insn.form == FORM_POST_ADD)
+{
+  start_sequence ();
+  emit_move_insn (inc_insn.reg_res, inc_insn.reg0);
+  mov_insn = get_insns ();
+  end_sequence ();
+  new_mov_cost = seq_cost (mov_insn, speed);
+}
+
+  new_cost = new_mem_cost + new_mov_cost;
 
   /* The first item of business is to see if this is profitable.  */
   if (old_cost < new_cost)
@@ -521,8 +519,8 @@ attempt_change (rtx new_addr, rtx inc_reg)
   /* Replace the addition with a move.  Do it at the location of
 	 the addition since the operand of the addition may change
 	 before the memory reference.  */
-  mov_insn = insert_move_insn_before (inc_insn.insn,
-	  inc_insn.reg_res, inc_insn.reg0);
+  gcc_assert (mov_insn);
+  emit_insn_before (mov_insn, inc_insn.insn);
   move_dead_notes (mov_insn, inc_insn.insn, inc_insn.reg0);
 
   regno = REGNO (inc_insn.reg_res);
@@ -547,8 +545,8 @@ attempt_change (rtx new_addr, rtx inc_reg)
   break;
 
 case FORM_POST_ADD:
-  mov_insn = insert_move_insn_before (mem_insn.insn,
-	  inc_insn.reg_res, inc_insn.reg0);
+  gcc_assert (mov_insn);
+  emit_insn_before (mov_insn, mem_insn.insn);
   move_dead_notes (mov_insn, inc_insn.insn, inc_insn.reg0);
 
   /* Do not move anything to the mov insn because the instruction


Re: Move fmin and fmax folds to match.pd

2015-10-26 Thread Richard Biener
On Mon, Oct 26, 2015 at 11:02 AM, Richard Sandiford
 wrote:
> Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi.
> OK to install?

Ok.

Thanks,
Richard.

> Thanks,
> Richard
>
>
> gcc/
> * builtins.c (fold_builtin_fmin_fmax): Delete.
> (fold_builtin_2): Handle constant fmin and fmax arguments here.
> * match.pd: Add rules previously handled by fold_builtin_fmin_fmax.
>
> diff --git a/gcc/builtins.c b/gcc/builtins.c
> index 6cd8879..86eac5c 100644
> --- a/gcc/builtins.c
> +++ b/gcc/builtins.c
> @@ -7891,51 +7891,6 @@ fold_builtin_fma (location_t loc, tree arg0, tree 
> arg1, tree arg2, tree type)
>return NULL_TREE;
>  }
>
> -/* Fold a call to builtin fmin or fmax.  */
> -
> -static tree
> -fold_builtin_fmin_fmax (location_t loc, tree arg0, tree arg1,
> -   tree type, bool max)
> -{
> -  if (validate_arg (arg0, REAL_TYPE) && validate_arg (arg1, REAL_TYPE))
> -{
> -  /* Calculate the result when the argument is a constant.  */
> -  tree res = do_mpfr_arg2 (arg0, arg1, type, (max ? mpfr_max : 
> mpfr_min));
> -
> -  if (res)
> -   return res;
> -
> -  /* If either argument is NaN, return the other one.  Avoid the
> -transformation if we get (and honor) a signalling NaN.  Using
> -omit_one_operand() ensures we create a non-lvalue.  */
> -  if (TREE_CODE (arg0) == REAL_CST
> - && real_isnan (_REAL_CST (arg0))
> - && (! HONOR_SNANS (arg0)
> - || ! TREE_REAL_CST (arg0).signalling))
> -   return omit_one_operand_loc (loc, type, arg1, arg0);
> -  if (TREE_CODE (arg1) == REAL_CST
> - && real_isnan (_REAL_CST (arg1))
> - && (! HONOR_SNANS (arg1)
> - || ! TREE_REAL_CST (arg1).signalling))
> -   return omit_one_operand_loc (loc, type, arg0, arg1);
> -
> -  /* Transform fmin/fmax(x,x) -> x.  */
> -  if (operand_equal_p (arg0, arg1, OEP_PURE_SAME))
> -   return omit_one_operand_loc (loc, type, arg0, arg1);
> -
> -  /* Convert fmin/fmax to MIN_EXPR/MAX_EXPR.  C99 requires these
> -functions to return the numeric arg if the other one is NaN.
> -These tree codes don't honor that, so only transform if
> --ffinite-math-only is set.  C99 doesn't require -0.0 to be
> -handled, so we don't have to worry about it either.  */
> -  if (flag_finite_math_only)
> -   return fold_build2_loc (loc, (max ? MAX_EXPR : MIN_EXPR), type,
> -   fold_convert_loc (loc, type, arg0),
> -   fold_convert_loc (loc, type, arg1));
> -}
> -  return NULL_TREE;
> -}
> -
>  /* Fold a call to builtin carg(a+bi) -> atan2(b,a).  */
>
>  static tree
> @@ -9241,10 +9196,14 @@ fold_builtin_2 (location_t loc, tree fndecl, tree 
> arg0, tree arg1)
>break;
>
>  CASE_FLT_FN (BUILT_IN_FMIN):
> -  return fold_builtin_fmin_fmax (loc, arg0, arg1, type, /*max=*/false);
> +  if (validate_arg (arg0, REAL_TYPE) && validate_arg (arg1, REAL_TYPE))
> +   return do_mpfr_arg2 (arg0, arg1, type, mpfr_min);
> +  break;
>
>  CASE_FLT_FN (BUILT_IN_FMAX):
> -  return fold_builtin_fmin_fmax (loc, arg0, arg1, type, /*max=*/true);
> +  if (validate_arg (arg0, REAL_TYPE) && validate_arg (arg1, REAL_TYPE))
> +   return do_mpfr_arg2 (arg0, arg1, type, mpfr_max);
> +  break;
>
>  case BUILT_IN_ISGREATER:
>return fold_builtin_unordered_cmp (loc, fndecl,
> diff --git a/gcc/match.pd b/gcc/match.pd
> index 338644c..f2e7d64 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -103,6 +103,8 @@ DEFINE_MATH_FN (CABS)
>  DEFINE_MATH_FN (TRUNC)
>  DEFINE_MATH_FN (NEARBYINT)
>  DEFINE_MATH_FN (SIGNBIT)
> +DEFINE_MATH_FN (FMIN)
> +DEFINE_MATH_FN (FMAX)
>
>  DEFINE_INT_AND_FLOAT_ROUND_FN (FLOOR)
>  DEFINE_INT_AND_FLOAT_ROUND_FN (CEIL)
> @@ -1170,9 +1172,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>   (minus (convert @1) (convert @2)))
>
>
> -/* Simplifications of MIN_EXPR and MAX_EXPR.  */
> +/* Simplifications of MIN_EXPR, MAX_EXPR, fmin() and fmax().  */
>
> -(for minmax (min max)
> +(for minmax (min max FMIN FMAX)
>   (simplify
>(minmax @0 @0)
>@0))
> @@ -1196,7 +1198,26 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>&& TYPE_MAX_VALUE (type)
>&& operand_equal_p (@1, TYPE_MAX_VALUE (type), OEP_ONLY_CONST))
>@1))
> -
> +(for minmax (FMIN FMAX)
> + /* If either argument is NaN, return the other one.  Avoid the
> +transformation if we get (and honor) a signalling NaN.  */
> + (simplify
> +  (minmax:c @0 REAL_CST@1)
> +  (if (real_isnan (TREE_REAL_CST_PTR (@1))
> +   && (!HONOR_SNANS (@1) || !TREE_REAL_CST (@1).signalling))
> +   @0)))
> +/* Convert fmin/fmax to MIN_EXPR/MAX_EXPR.  C99 requires these
> +   functions to return the numeric arg if the other one is NaN.
> +   MIN and MAX don't honor that, so only transform if -ffinite-math-only
> +   is set.  C99 doesn't require -0.0 to be handled, so we 

Re: Rename logb and significand folds

2015-10-26 Thread Richard Biener
On Mon, Oct 26, 2015 at 11:05 AM, Richard Sandiford
 wrote:
> fold_builtin_logb and fold_builtin_significand now only handle
> constant arguments, so this patch renames them to fold_const...,
> to match fold_const_builtin_pow.  The idea is to differentiate
> constant-only folds so that they can be moved to a const_binop-like
> function in future.
>
> The functions also had some unnecessary calls to STRIP_NOPS, which
> I think are left over from code that has already moved to match.pd.
>
> Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi.
> OK to install?

Ok.

Thanks,
Richard.

> Thanks,
> Richard
>
>
> gcc/
> * builtins.c (fold_builtin_logb): Rename to...
> (fold_const_builtin_logb): ...this and remove STRIP_NOPS call.
> (fold_builtin_significand): Rename to...
> (fold_const_builtin_significand): ...this and remove STRIP_NOPS call.
> (fold_builtin_1): Update accordingly.
>
> diff --git a/gcc/builtins.c b/gcc/builtins.c
> index 86eac5c..260b66d 100644
> --- a/gcc/builtins.c
> +++ b/gcc/builtins.c
> @@ -7916,13 +7916,11 @@ fold_builtin_carg (location_t loc, tree arg, tree 
> type)
>  /* Fold a call to builtin logb/ilogb.  */
>
>  static tree
> -fold_builtin_logb (location_t loc, tree arg, tree rettype)
> +fold_const_builtin_logb (location_t loc, tree arg, tree rettype)
>  {
>if (! validate_arg (arg, REAL_TYPE))
>  return NULL_TREE;
>
> -  STRIP_NOPS (arg);
> -
>if (TREE_CODE (arg) == REAL_CST && ! TREE_OVERFLOW (arg))
>  {
>const REAL_VALUE_TYPE *const value = TREE_REAL_CST_PTR (arg);
> @@ -7967,13 +7965,11 @@ fold_builtin_logb (location_t loc, tree arg, tree 
> rettype)
>  /* Fold a call to builtin significand, if radix == 2.  */
>
>  static tree
> -fold_builtin_significand (location_t loc, tree arg, tree rettype)
> +fold_const_builtin_significand (location_t loc, tree arg, tree rettype)
>  {
>if (! validate_arg (arg, REAL_TYPE))
>  return NULL_TREE;
>
> -  STRIP_NOPS (arg);
> -
>if (TREE_CODE (arg) == REAL_CST && ! TREE_OVERFLOW (arg))
>  {
>const REAL_VALUE_TYPE *const value = TREE_REAL_CST_PTR (arg);
> @@ -9002,11 +8998,11 @@ fold_builtin_1 (location_t loc, tree fndecl, tree 
> arg0)
>break;
>
>  CASE_FLT_FN (BUILT_IN_SIGNIFICAND):
> -  return fold_builtin_significand (loc, arg0, type);
> +  return fold_const_builtin_significand (loc, arg0, type);
>
>  CASE_FLT_FN (BUILT_IN_ILOGB):
>  CASE_FLT_FN (BUILT_IN_LOGB):
> -  return fold_builtin_logb (loc, arg0, type);
> +  return fold_const_builtin_logb (loc, arg0, type);
>
>  case BUILT_IN_ISASCII:
>return fold_builtin_isascii (loc, arg0);
>


[Committed] Add vars in intra_create_variables_info

2015-10-26 Thread Tom de Vries

Hi,

this no-functional-changes patch adds some vars in 
intra_create_variables_info.


Bootstrapped and reg-tested on x86_64.

Committed as trivial.

Thanks,
- Tom
Add vars in intra_create_variables_info

2015-10-26  Tom de Vries  

	* tree-ssa-structalias.c (intra_create_variable_infos): Add
	restrict_pointer_p and recursive_restrict_p variables.
---
 gcc/tree-ssa-structalias.c | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/gcc/tree-ssa-structalias.c b/gcc/tree-ssa-structalias.c
index c5a7e2a..1e1ae95 100644
--- a/gcc/tree-ssa-structalias.c
+++ b/gcc/tree-ssa-structalias.c
@@ -5857,6 +5857,11 @@ intra_create_variable_infos (struct function *fn)
  passed-by-reference argument.  */
   for (t = DECL_ARGUMENTS (fn->decl); t; t = DECL_CHAIN (t))
 {
+  bool restrict_pointer_p = (POINTER_TYPE_P (TREE_TYPE (t))
+ && TYPE_RESTRICT (TREE_TYPE (t)));
+  bool recursive_restrict_p
+	= (restrict_pointer_p
+	   && !type_contains_placeholder_p (TREE_TYPE (TREE_TYPE (t;
   varinfo_t p = lookup_vi_for_tree (t);
   if (p == NULL)
 	{
@@ -5868,9 +5873,7 @@ intra_create_variable_infos (struct function *fn)
 	 the pointed-to object.  Note that this ends up handling
 	 out-of-bound references conservatively by aggregating them
 	 in the first/last subfield of the object.  */
-  if (POINTER_TYPE_P (TREE_TYPE (t))
-	  && TYPE_RESTRICT (TREE_TYPE (t))
-	  && !type_contains_placeholder_p (TREE_TYPE (TREE_TYPE (t
+  if (recursive_restrict_p)
 	{
 	  varinfo_t vi;
 	  tree heapvar = build_fake_var_decl (TREE_TYPE (TREE_TYPE (t)));
@@ -5890,8 +5893,7 @@ intra_create_variable_infos (struct function *fn)
 	  continue;
 	}
 
-  if (POINTER_TYPE_P (TREE_TYPE (t))
-	  && TYPE_RESTRICT (TREE_TYPE (t)))
+  if (restrict_pointer_p)
 	make_constraint_from_global_restrict (p, "PARM_RESTRICT");
   else
 	{
-- 
1.9.1



Re: [PATCH] c/67882 - improve -Warray-bounds for invalid offsetof

2015-10-26 Thread Jakub Jelinek
On Mon, Oct 26, 2015 at 12:40:18PM +0100, Bernd Schmidt wrote:
> On 10/23/2015 10:40 PM, Martin Sebor wrote:
> >
> >The original code deliberately avoids diagnosing the case of last
> >array members with bounds greater than 1 (see the comment about
> >"a poor man's flexible array member" added with a fix for bug
> >41935) and I didn't want to change that.
> 
> Jakub added that, Cc'd. Do you recall why this was done?

Because the amount of code that uses this (including GCC itself) is just too
huge, so everywhere in the middle-end we also special case last array members of
structs.  While C99+ has flexible array members, e.g. C++ does not, so users
are left with using struct { ... type fld[1]; };
or similar to stand for the flexible array members, even when they want to
be able to use ->fld[3] etc.

Jakub


Re: Move cexp simplifications to match.pd

2015-10-26 Thread Richard Biener
On Fri, Oct 23, 2015 at 5:03 PM, Richard Sandiford
 wrote:
> This required reinstating support for captures in the result
> of a simplification.  That part (genmatch.c) is by Richard B.
>
> Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi.
> OK to install?
>
> Thanks,
> Richard
>
>
> gcc/
> 2015-10-20  Richard Sandiford  
> Richard Biener  
>
> * genmatch.c (dt_simplify::gen): Skip captures that are
> part of the result.
> (parser::parse_expr): Allow captures in results too.
> * builtins.c (fold_builtin_cexp): Delete.
> (fold_builtin_1): Handle constant cexp arguments here.
> * match.pd: Fold cexp(x+yi) to exp(x) * cexpi(y).
>
> diff --git a/gcc/builtins.c b/gcc/builtins.c
> index 02bf9f6..e5e65ba 100644
> --- a/gcc/builtins.c
> +++ b/gcc/builtins.c
> @@ -7577,74 +7577,6 @@ fold_builtin_sincos (location_t loc,
>  build1 (REALPART_EXPR, type, call)));
>  }
>
> -/* Fold function call to builtin cexp, cexpf, or cexpl.  Return
> -   NULL_TREE if no simplification can be made.  */
> -
> -static tree
> -fold_builtin_cexp (location_t loc, tree arg0, tree type)
> -{
> -  tree rtype;
> -  tree realp, imagp, ifn;
> -  tree res;
> -
> -  if (!validate_arg (arg0, COMPLEX_TYPE)
> -  || TREE_CODE (TREE_TYPE (TREE_TYPE (arg0))) != REAL_TYPE)
> -return NULL_TREE;
> -
> -  /* Calculate the result when the argument is a constant.  */
> -  if ((res = do_mpc_arg1 (arg0, type, mpc_exp)))
> -return res;
> -
> -  rtype = TREE_TYPE (TREE_TYPE (arg0));
> -
> -  /* In case we can figure out the real part of arg0 and it is constant zero
> - fold to cexpi.  */
> -  if (!targetm.libc_has_function (function_c99_math_complex))
> -return NULL_TREE;
> -  ifn = mathfn_built_in (rtype, BUILT_IN_CEXPI);
> -  if (!ifn)
> -return NULL_TREE;
> -
> -  if ((realp = fold_unary_loc (loc, REALPART_EXPR, rtype, arg0))
> -  && real_zerop (realp))
> -{
> -  tree narg = fold_build1_loc (loc, IMAGPART_EXPR, rtype, arg0);
> -  return build_call_expr_loc (loc, ifn, 1, narg);
> -}
> -
> -  /* In case we can easily decompose real and imaginary parts split cexp
> - to exp (r) * cexpi (i).  */
> -  if (flag_unsafe_math_optimizations
> -  && realp)
> -{
> -  tree rfn, rcall, icall;
> -
> -  rfn = mathfn_built_in (rtype, BUILT_IN_EXP);
> -  if (!rfn)
> -   return NULL_TREE;
> -
> -  imagp = fold_unary_loc (loc, IMAGPART_EXPR, rtype, arg0);
> -  if (!imagp)
> -   return NULL_TREE;
> -
> -  icall = build_call_expr_loc (loc, ifn, 1, imagp);
> -  icall = builtin_save_expr (icall);
> -  rcall = build_call_expr_loc (loc, rfn, 1, realp);
> -  rcall = builtin_save_expr (rcall);
> -  return fold_build2_loc (loc, COMPLEX_EXPR, type,
> - fold_build2_loc (loc, MULT_EXPR, rtype,
> -  rcall,
> -  fold_build1_loc (loc, REALPART_EXPR,
> -   rtype, icall)),
> - fold_build2_loc (loc, MULT_EXPR, rtype,
> -  rcall,
> -  fold_build1_loc (loc, IMAGPART_EXPR,
> -   rtype, icall)));
> -}
> -
> -  return NULL_TREE;
> -}
> -
>  /* Fold function call to builtin trunc, truncf or truncl with argument ARG.
> Return NULL_TREE if no simplification can be made.  */
>
> @@ -9589,7 +9521,10 @@ fold_builtin_1 (location_t loc, tree fndecl, tree arg0)
>break;
>
>  CASE_FLT_FN (BUILT_IN_CEXP):
> -  return fold_builtin_cexp (loc, arg0, type);
> +  if (validate_arg (arg0, COMPLEX_TYPE)
> + && TREE_CODE (TREE_TYPE (TREE_TYPE (arg0))) == REAL_TYPE)
> +   return do_mpc_arg1 (arg0, type, mpc_exp);
> +  break;
>
>  CASE_FLT_FN (BUILT_IN_CEXPI):
>if (validate_arg (arg0, REAL_TYPE))
> diff --git a/gcc/genmatch.c b/gcc/genmatch.c
> index b05760e..b5a0fff 100644
> --- a/gcc/genmatch.c
> +++ b/gcc/genmatch.c
> @@ -3163,7 +3163,11 @@ dt_simplify::gen (FILE *f, int indent, bool gimple)
>   s->capture_max + 1, indexes[0]->get_name (opname));
>
>for (int i = 1; i <= s->capture_max; ++i)
> -   fprintf (f, ", %s", indexes[i]->get_name (opname));
> +   {
> + if (!indexes[i])
> +   break;
> + fprintf (f, ", %s", indexes[i]->get_name (opname));
> +   }
>fprintf (f, " };\n");
>  }
>
> @@ -3831,7 +3835,7 @@ parser::parse_expr ()
>
>if (token->type == CPP_ATSIGN
>&& !(token->flags & PREV_WHITE))
> -op = parse_capture (e, !parsing_match_operand);
> +op = parse_capture (e, false);
>else if (force_capture)
>  {
>unsigned num = capture_ids->elements ();
> diff --git a/gcc/match.pd b/gcc/match.pd
> index 

Re: [gomp4] Adjust UNQUE ifn

2015-10-26 Thread Thomas Schwinge
Hi Nathan!

On Sun, 25 Oct 2015 10:01:55 -0400, Nathan Sidwell  wrote:
> I've applied this patch to gomp4 branch.  It's the reworking of IFN_UNIQUE 
> suggested by Richard & Jakub.

> 
> 1) IFN_UNIQUE is a ctrl-altering call, and thus ends up at the end of a BB.
> 2) tracer only needs to check that stmt (and it'a already looking at it for 
> other reasons)
> 3) IFN_UNIQUE is no longer ECF_LEAF
> 4) Inserted a data dependency chain to the had & tail call sequence.  The 2nd 
> param is the result of  the previous call in the chain.

> --- gcc/internal-fn.c (revision 229276)
> +++ gcc/internal-fn.c (working copy)
> @@ -1962,8 +1962,9 @@ static void
>  expand_UNIQUE (gcall *stmt)
>  {
>rtx pattern = NULL_RTX;
> +  int code = TREE_INT_CST_LOW (gimple_call_arg (stmt, 0));
>  
> -  switch (TREE_INT_CST_LOW (gimple_call_arg (stmt, 0)))
> +  switch (code)
>  {
>  default:
>gcc_unreachable ();
> @@ -1975,21 +1976,34 @@ expand_UNIQUE (gcall *stmt)
>break;
>  
>  case IFN_UNIQUE_OACC_FORK:
> +case IFN_UNIQUE_OACC_JOIN:
> +  {
> + tree lhs = gimple_call_lhs (stmt);
> + rtx target = const0_rtx;
> +
> + if (lhs)
> +   target = expand_expr (lhs, NULL_RTX, VOIDmode, EXPAND_WRITE);
> +
> + rtx data_dep = expand_normal (gimple_call_arg (stmt, 1));
> + rtx axis = expand_normal (gimple_call_arg (stmt, 2));
> +
> + if (code == IFN_UNIQUE_OACC_FORK)
> +   {
>  #ifdef HAVE_oacc_fork
> -  pattern = expand_normal (gimple_call_arg (stmt, 1));
> -  pattern = gen_oacc_fork (pattern);
> + pattern = gen_oacc_fork (target, data_dep, axis);
>  #else
> -  gcc_unreachable ();
> + gcc_unreachable ();
>  #endif
> -  break;
> -
> -case IFN_UNIQUE_OACC_JOIN:
> +   }
> + else
> +   {
>  #ifdef HAVE_oacc_join
> -  pattern = expand_normal (gimple_call_arg (stmt, 1));
> -  pattern = gen_oacc_join (pattern);
> + pattern = gen_oacc_join (target, data_dep, axis);
>  #else
> -  gcc_unreachable ();
> + gcc_unreachable ();
>  #endif
> +   }
> +  }
>break;
>  }

[...]/source-gcc/gcc/internal-fn.c: In function 'void 
expand_UNIQUE(gcall*)':
[...]/source-gcc/gcc/internal-fn.c:1982:6: error: variable 'target' set but 
not used [-Werror=unused-but-set-variable]
  rtx target = const0_rtx;
  ^
[...]/source-gcc/gcc/internal-fn.c:1987:6: error: unused variable 
'data_dep' [-Werror=unused-variable]
  rtx data_dep = expand_normal (gimple_call_arg (stmt, 1));
  ^
[...]/source-gcc/gcc/internal-fn.c:1988:6: error: unused variable 'axis' 
[-Werror=unused-variable]
  rtx axis = expand_normal (gimple_call_arg (stmt, 2));
  ^


Grüße
 Thomas


signature.asc
Description: PGP signature


[patch] Extend former fold_widened_comparison to all integral types

2015-10-26 Thread Eric Botcazou
Hi,

this patch extends the simplification formerly done in fold_widened_comparison 
and now in match.pd to all integral types instead of just integer types, and
comes with an Ada testcase for the enumeral type case.

The patch introduces a failure in the C testsuite:

FAIL: gcc.dg/atomic-noinline.c execution test

because the testcase is broken:

  /* The fake external function should return 10.  */
  if (__atomic_is_lock_free (4, 0) != 10)
abort ();

__atomic_is_lock_free returns a boolean so it cannot return 10...

Tested on x86_64-suse-linux, OK for the mainline?


2015-10-26  Eric Botcazou  

* match.pd (fold_widened_comparison): Apply simplifications to
all integral types.


2015-10-26  Eric Botcazou  

* gcc.dg/atomic-noinline.c: Fix test on __atomic_is_lock_free.
* gcc.dg/atomic-noinline-aux.c: Fix its return type.
* gnat.dg/opt51.adb: New test.
* gnat.dg/opt51_pkg.ads: New helper.


-- 
Eric BotcazouIndex: match.pd
===
--- match.pd	(revision 229283)
+++ match.pd	(working copy)
@@ -2067,12 +2067,11 @@ (define_operator_list RINT BUILT_IN_RINT
 		  && (TYPE_UNSIGNED (TREE_TYPE (@00))
 		  == TYPE_UNSIGNED (TREE_TYPE (@10
 	  || (TREE_CODE (@10) == INTEGER_CST
-		  && (TREE_CODE (TREE_TYPE (@00)) == INTEGER_TYPE
-		  || TREE_CODE (TREE_TYPE (@00)) == BOOLEAN_TYPE)
+		  && INTEGRAL_TYPE_P (TREE_TYPE (@00))
 		  && int_fits_type_p (@10, TREE_TYPE (@00)
   (cmp @00 (convert @10))
   (if (TREE_CODE (@10) == INTEGER_CST
-	   && TREE_CODE (TREE_TYPE (@00)) == INTEGER_TYPE
+	   && INTEGRAL_TYPE_P (TREE_TYPE (@00))
 	   && !int_fits_type_p (@10, TREE_TYPE (@00)))
(with
 	{
Index: testsuite/gcc.dg/atomic-noinline-aux.c
===
--- testsuite/gcc.dg/atomic-noinline-aux.c	(revision 229283)
+++ testsuite/gcc.dg/atomic-noinline-aux.c	(working copy)
@@ -64,7 +64,7 @@ __atomic_fetch_nand_1 (unsigned char *p,
   return ret;
 }
 
-int __atomic_is_lock_free (int i, void *p)
+bool __atomic_is_lock_free (int i, void *p)
 {
-  return 10;
+  return true;
 }
Index: testsuite/gcc.dg/atomic-noinline.c
===
--- testsuite/gcc.dg/atomic-noinline.c	(revision 229283)
+++ testsuite/gcc.dg/atomic-noinline.c	(working copy)
@@ -46,10 +46,9 @@ main ()
   if (cs != 1)
 abort ();
 
-  /* The fake external function should return 10.  */
-  if (__atomic_is_lock_free (4, 0) != 10)
+  if (!__atomic_is_lock_free (4, 0))
 abort ();
-   
+
   /* PR 51040 was caused by arithmetic code not patching up nand_fetch properly
  when used an an external function.  Look for proper return value here.  */
   ac = 0x3C;
@@ -59,6 +58,3 @@ main ()
 
   return 0;
 }
-
-
-
-- { dg-do compile }
-- { dg-options "-O2 -fdump-tree-optimized" }

with Opt51_Pkg; use Opt51_Pkg;

procedure Opt51 (E: Enum; F : out Float) is
begin
  case (E) is
when One =>
  F := 1.0;
when Two =>
  F := 2.0;
when Three =>
  F := 3.0;
when others =>
  raise Program_Error;
  end case;
end;

-- { dg-final { scan-tree-dump-not "check_PE_Explicit_Raise" "optimized" } }
package Opt51_Pkg is

  type Enum is (One, Two, Three);

end Opt51_Pkg;


Re: [patch] Extend former fold_widened_comparison to all integral types

2015-10-26 Thread Andrew Pinski
On Mon, Oct 26, 2015 at 4:39 PM, Eric Botcazou  wrote:
> Hi,
>
> this patch extends the simplification formerly done in fold_widened_comparison
> and now in match.pd to all integral types instead of just integer types, and
> comes with an Ada testcase for the enumeral type case.
>
> The patch introduces a failure in the C testsuite:
>
> FAIL: gcc.dg/atomic-noinline.c execution test
>
> because the testcase is broken:
>
>   /* The fake external function should return 10.  */
>   if (__atomic_is_lock_free (4, 0) != 10)
> abort ();
>
> __atomic_is_lock_free returns a boolean so it cannot return 10...
>
> Tested on x86_64-suse-linux, OK for the mainline?


Maybe you should count how many times __atomic_is_lock_free is called
instead of the current patch to the testsuite.

Thanks,
Andrew

>
>
> 2015-10-26  Eric Botcazou  
>
> * match.pd (fold_widened_comparison): Apply simplifications to
> all integral types.
>
>
> 2015-10-26  Eric Botcazou  
>
> * gcc.dg/atomic-noinline.c: Fix test on __atomic_is_lock_free.
> * gcc.dg/atomic-noinline-aux.c: Fix its return type.
> * gnat.dg/opt51.adb: New test.
> * gnat.dg/opt51_pkg.ads: New helper.
>
>
> --
> Eric Botcazou


Re: Possible patch for PR fortran/66056

2015-10-26 Thread Louis Krupp
A patch with ChangeLog diffs is attached.

I ran "make && make install && make check-fortran" at the top level on 
x86_64-pc-linux-gnu.  (I always do that before I post a patch and again before 
I actually check anything in.  I sometimes forget to include files when I 
finally commit, but I'm always confident that the ones I remember are good :)

Louis

 On Mon, 26 Oct 2015 01:51:04 -0700 FX wrote  
 > > The problem:  Statement labels within a type declaration are put in the 
 > > statement label tree belonging to the type declaration's namespace's 
 > > (instead of the current namespace).  When the line is otherwise empty and 
 > > an error is issued, gfc_free_st_label tries to delete the label from the 
 > > label tree belonging to the current namespace and then frees the label 
 > > structure, leaving an invalid statement label pointer in the type 
 > > declaration's namespace's label tree.  When that namespace is cleaned up, 
 > > bad things can happen. 
 >  
 > Seems OK. 
 > Please post patches with full ChangeLog entry, stating how they were tested 
 > (“bootstraped and regtested on x86_64-linux”, for example). And of course, 
 > do an actual full regression-test :) 
 >  
 > If that was done, then OK to commit. 
 >  
 > Thanks, 
 > FX

Index: gcc/fortran/ChangeLog
===
--- gcc/fortran/ChangeLog   (revision 229307)
+++ gcc/fortran/ChangeLog   (working copy)
@@ -1,3 +1,14 @@
+2015-10-26  Louis Krupp  
+
+   PR fortran/66056
+   * fortran.h: Include namespace pointer in statement label
+   structure.
+   * symbol.c (gfc_get_st_label): Store pointer to namespace
+   that owns the statement label tree in each label.
+   (gfc_free_st_label): Use namespace owning statement label
+   tree when deleting statement label.
+   * io.c: Initialize format_asterisk with NULL namespace pointer.
+
 2015-01-25  Paul Thomas  
 
PR fortran/67171
Index: gcc/fortran/gfortran.h
===
--- gcc/fortran/gfortran.h  (revision 229307)
+++ gcc/fortran/gfortran.h  (working copy)
@@ -1291,6 +1291,8 @@ typedef struct gfc_st_label
   tree backend_decl;
 
   locus where;
+
+  gfc_namespace *ns;
 }
 gfc_st_label;
 
Index: gcc/fortran/io.c
===
--- gcc/fortran/io.c(revision 229307)
+++ gcc/fortran/io.c(working copy)
@@ -28,7 +28,7 @@ along with GCC; see the file COPYING3.  If not see
 
 gfc_st_label
 format_asterisk = {0, NULL, NULL, -1, ST_LABEL_FORMAT, ST_LABEL_FORMAT, NULL,
-  0, {NULL, NULL}};
+  0, {NULL, NULL}, NULL};
 
 typedef struct
 {
Index: gcc/fortran/symbol.c
===
--- gcc/fortran/symbol.c(revision 229307)
+++ gcc/fortran/symbol.c(working copy)
@@ -2195,7 +2195,7 @@ gfc_free_st_label (gfc_st_label *label)
   if (label == NULL)
 return;
 
-  gfc_delete_bbt (_current_ns->st_labels, label, compare_st_labels);
+  gfc_delete_bbt (>ns->st_labels, label, compare_st_labels);
 
   if (label->format != NULL)
 gfc_free_expr (label->format);
@@ -2260,6 +2260,7 @@ gfc_get_st_label (int labelno)
   lp->value = labelno;
   lp->defined = ST_LABEL_UNKNOWN;
   lp->referenced = ST_LABEL_UNKNOWN;
+  lp->ns = ns;
 
   gfc_insert_bbt (>st_labels, lp, compare_st_labels);
 
Index: gcc/testsuite/ChangeLog
===
--- gcc/testsuite/ChangeLog (revision 229307)
+++ gcc/testsuite/ChangeLog (working copy)
@@ -1,3 +1,8 @@
+2015-10-26  Louis Krupp  
+
+   PR fortran/66056
+   * gfortran.dg/empty_label_typedecl.f90: New test
+
 2015-01-25  Paul Thomas  
 
PR fortran/67171
Index: gcc/testsuite/gfortran.dg/empty_label_typedecl.f90
===
--- gcc/testsuite/gfortran.dg/empty_label_typedecl.f90  (revision 0)
+++ gcc/testsuite/gfortran.dg/empty_label_typedecl.f90  (working copy)
@@ -0,0 +1,8 @@
+! { dg-do compile }
+! { dg-options "-Werror" }
+subroutine s
+  type t
+  1 ! { dg-error "empty statement" }
+  end type
+end subroutine
+! { dg-excess-errors "warnings being treated as errors" }


Re: Possible patch for PR fortran/66056

2015-10-26 Thread FX
> The problem:  Statement labels within a type declaration are put in the 
> statement label tree belonging to the type declaration's namespace's (instead 
> of the current namespace).  When the line is otherwise empty and an error is 
> issued, gfc_free_st_label tries to delete the label from the label tree 
> belonging to the current namespace and then frees the label structure, 
> leaving an invalid statement label pointer in the type declaration's 
> namespace's label tree.  When that namespace is cleaned up, bad things can 
> happen.

Seems OK.
Please post patches with full ChangeLog entry, stating how they were tested 
(“bootstraped and regtested on x86_64-linux”, for example). And of course, do 
an actual full regression-test :)

If that was done, then OK to commit.

Thanks,
FX

Re: [PATCH] PR fortran/36192 -- Check for valid BT_INTEGER

2015-10-26 Thread FX
> 2015-10-25  Steven G. Kargl  
> 
>   PR fortran/36192
>   * array.c (gfc_ref_dimen_size): Check for BT_INTEGER before calling
>   mpz_set.
> 
> 
> 2015-10-25  Steven G. Kargl  
> 
>   PR fortran/36192
>   * gfortran.dg/pr36192.f90: New test.

OK. But I don’t understand why the testcase’s dg-error pattern has this form: a 
regex “or” (|) of two identical strings?

FX

Re: [PATCH] tree-scalar-evolution.c: Handle LSHIFT by constant

2015-10-26 Thread Richard Biener
On Fri, Oct 23, 2015 at 5:15 PM, Alan Lawrence  wrote:
> On 19/10/15 12:49, Richard Biener wrote:
>
>> Err, you should always do the shift in the type of rhs1.  You should also
>> avoid the chrec_convert of rhs2 above for shifts.
>
> Err, yes, indeed.  Needed to keep the chrec_convert before the
> chrec_fold_multiply, and the rest followed.  How's this?
>
> Bootstrapped+check-gcc,g++ on x86, ARM, AArch64.
>
> gcc/ChangeLog (as before):
>
> PR tree-optimization/65963
> * tree-scalar-evolution.c (interpret_rhs_expr): Handle some 
> LSHIFT_EXPRs
> as equivalent MULT_EXPRs.
>
> gcc/testsuite/ChangeLog:
>
> * gcc.dg/vect/vect-strided-shift-1.c: New.
> ---
>  gcc/testsuite/gcc.dg/vect/vect-strided-shift-1.c | 33 
> 
>  gcc/tree-scalar-evolution.c  | 15 +++
>  2 files changed, 48 insertions(+)
>  create mode 100644 gcc/testsuite/gcc.dg/vect/vect-strided-shift-1.c
>
> diff --git a/gcc/testsuite/gcc.dg/vect/vect-strided-shift-1.c 
> b/gcc/testsuite/gcc.dg/vect/vect-strided-shift-1.c
> new file mode 100644
> index 000..b1ce2ec
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/vect/vect-strided-shift-1.c
> @@ -0,0 +1,33 @@
> +/* PR tree-optimization/65963.  */
> +#include "tree-vect.h"
> +
> +#define N 512
> +
> +int in[2*N], out[N];
> +
> +__attribute__ ((noinline)) void
> +loop (void)
> +{
> +  for (int i = 0; i < N; i++)
> +out[i] = in[i << 1] + 7;
> +}
> +
> +int
> +main (int argc, char **argv)
> +{
> +  check_vect ();
> +  for (int i = 0; i < 2*N; i++)
> +{
> +  in[i] = i;
> +  __asm__ volatile ("" : : : "memory");
> +}
> +  loop ();
> +  __asm__ volatile ("" : : : "memory");
> +  for (int i = 0; i < N; i++)
> +{
> +  if (out[i] != i*2 + 7)
> +   abort ();
> +}
> +  return 0;
> +}
> +/* { dg-final { scan-tree-dump-times "vectorized 1 loops in function" 1 
> "vect" { target { vect_strided2 } } } } */
> diff --git a/gcc/tree-scalar-evolution.c b/gcc/tree-scalar-evolution.c
> index 0753bf3..129682f 100644
> --- a/gcc/tree-scalar-evolution.c
> +++ b/gcc/tree-scalar-evolution.c
> @@ -1840,6 +1840,21 @@ interpret_rhs_expr (struct loop *loop, gimple *at_stmt,
>res = chrec_fold_multiply (type, chrec1, chrec2);
>break;
>
> +case LSHIFT_EXPR:
> +  /* Handle A< +  chrec1 = analyze_scalar_evolution (loop, rhs1);
> +  chrec2 = analyze_scalar_evolution (loop, rhs2);
> +  chrec1 = chrec_convert (type, chrec1, at_stmt);
> +  chrec1 = instantiate_parameters (loop, chrec1);
> +  chrec2 = instantiate_parameters (loop, chrec2);
> +  chrec2 = fold_build2 (LSHIFT_EXPR, TREE_TYPE (rhs1),
> +   build_int_cst (TREE_TYPE (rhs1), 1),

'type' instead of TREE_TYPE (rhs1)

> +   chrec2);
> +  chrec2 = chrec_convert (type, chrec2, at_stmt);

so you can remove this chrec_convert.

Ok with that change.

Richard.

> +  res = chrec_fold_multiply (type, chrec1, chrec2);
> +  break;
> +
>  CASE_CONVERT:
>/* In case we have a truncation of a widened operation that in
>   the truncated type has undefined overflow behavior analyze
> --
> 1.9.1
>


Re: [PATCH, PR68062] Fix uniform vector operation lowering

2015-10-26 Thread Richard Biener
On Sat, Oct 24, 2015 at 12:29 AM, Ilya Enkovich  wrote:
> 2015-10-24 0:32 GMT+03:00 Jeff Law :
>> On 10/23/2015 09:26 AM, Ilya Enkovich wrote:
>>>
>>> Hi,
>>>
>>> This patch checks optab exists before using it vector vector statement
>>> lowering.  It fixes compilation of test from PR68062 with -funsigned-char
>>> option added (doesn't fix original testcase).  Bootstrapped for
>>> x86_64-unknown-linux-gnu.  OK for trunk if no regressions?
>>>
>>> Thanks,
>>> Ilya
>>> --
>>> gcc/
>>>
>>> 2015-10-23  Ilya Enkovich  
>>>
>>> * tree-vect-generic.c (expand_vector_operations_1): Check
>>> optab exists before use it.
>>>
>>> gcc/testsuite/
>>>
>>> 2015-10-23  Ilya Enkovich  
>>>
>>> * g++.dg/pr68062.C: New test.
>>
>> OK.
>>
>> Just curious, what was the tree code for which we couldn't find a suitable
>> optab?
>
> Those are various comparison codes.

Yeah, sorry for missing that check.  Btw, I was curious to see that we miss
a way to query from optab_tag the "kind" (normal, conversion, etc.) so code
can decide what optab_handler function to call (optab_handler or
convert_optab_handler).  So the code I added errs on the "simplistic" side
and hopes that matching lhs and rhs1 type always gets us a non-convert optab...

Richard.

> Ilya
>
>>
>> jeff
>>


Re: RFC: PATCH to pointer_int_sum vs. pointer-arith-10.c

2015-10-26 Thread Richard Biener
On Sat, Oct 24, 2015 at 5:14 AM, Jason Merrill  wrote:
> On 10/21/2015 12:16 AM, Richard Biener wrote:
>>
>> On Tue, Oct 20, 2015 at 9:10 PM, Jason Merrill  wrote:
>>>
>>> I made this change on the delayed folding branch and then noticed that it
>>> broke pointer-arith-10.c, which you added to the testsuite.  The patch
>>> changes the -original dump from
>>>
>>>return (char *) ((sizetype) p + (sizetype) i);
>>>
>>> to
>>>
>>>return (char *) i + (sizetype) p;
>>>
>>> It's not clear to me why the former should be preferred.  Any thoughts?
>>
>>
>> We probably regressed for the former and the dump-scanning just didn't
>> notice.  We wanted to check for
>>
>>return p + (sizetype) i;
>>
>> at least GCC 4.4.7 produces that and 4.5.2 regressed.
>>
>> Some time ago we had a folding that explicitely swapped pointer-ness
>> of an integer op like the testcase was supposed to test.  But I remember
>> I removed this because it's incorrect (pointer arithmetic is more
>> constrained
>> than unsigned integer arithmetic):
>>
>> 2009-01-16  Richard Guenther  
>>
>>  PR tree-optimization/38835
>>  PR middle-end/36227
>>  * fold-const.c (fold_binary): Remove PTR + INT -> (INT)(PTR p+
>> INT)
>>  and INT + PTR -> (INT)(PTR p+ INT) folding.
>>  * tree-ssa-address.c (create_mem_ref): Properly use
>> POINTER_PLUS_EXPR.
>>
>> so I think the testcase should be simply removed.
>
>
> How about this change to the testcase?

Hmm, I'd say we want to test for the correctness issue as well, thus pleas also
add

/* { dg-final { scan-tree-dump-not "return p +" "original" } } */

as we do not want 'p + (sizetype)i' as that is incorrect.

Thanks,
Richard.

> Jason
>
>


Re: [OpenACC 5/11] C++ FE changes

2015-10-26 Thread Cesar Philippidis
On 10/26/2015 03:20 AM, Jakub Jelinek wrote:
> On Sat, Oct 24, 2015 at 02:11:41PM -0700, Cesar Philippidis wrote:

>> --- a/gcc/cp/semantics.c
>> +++ b/gcc/cp/semantics.c
>> @@ -5911,6 +5911,31 @@ finish_omp_clauses (tree clauses, bool allow_fields, 
>> bool declare_simd)
>>  bitmap_set_bit (_head, DECL_UID (t));
>>goto handle_field_decl;
>>  
>> +case OMP_CLAUSE_GANG:
>> +case OMP_CLAUSE_VECTOR:
>> +case OMP_CLAUSE_WORKER:
>> +  /* Operand 0 is the num: or length: argument.  */
>> +  t = OMP_CLAUSE_OPERAND (c, 0);
>> +  if (t == NULL_TREE)
>> +break;
>> +
>> +  if (!processing_template_decl)
>> +t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
>> +  OMP_CLAUSE_OPERAND (c, 0) = t;
>> +
>> +  if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_GANG)
>> +break;
> 
> I think it would be better to do the Operand 1 stuff first for
> case OMP_CLAUSE_GANG: only, and then have /* FALLTHRU */ into
> case OMP_CLAUSE_{VECTOR,WORKER}: which would handle the first argument.
> 
> You should add testing that the operand has INTEGRAL_TYPE_P type
> (except that for processing_template_decl it can be
> type_dependent_expression_p instead of INTEGRAL_TYPE_P).
>
> Also, the if (t == NULL_TREE) stuff looks fishy, because e.g. right now
> if you have OMP_CLAUSE_GANG gang (static: expr) or similar,
> you wouldn't wrap the expr into cleanup point.
> So, instead it should be
>   if (t)
> {
>   if (t == error_mark_node)
>   remove = true;
>   else if (!type_dependent_expression_p (t)
>&& !INTEGRAL_TYPE_P (TREE_TYPE (t)))
>   {
> error_at (OMP_CLAUSE_LOCATION (c), ...);
> remove = true;
> }
>   else
>   {
> t = mark_rvalue_use (t);
> if (!processing_template_decl)
>   t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
> OMP_CLAUSE_OPERAND (c, 0) = t;
>   }
> }
> or so.  Also, can the expressions be arbitrary integers, or just
> non-negative, or positive?  If it is INTEGER_CST, that is something that
> could be checked here too.

I ended up handling with with OMP_CLAUSE_NUM_*, since they all require
positive integer expressions. The only exception was OMP_CLAUSE_GANG
which has two optional arguments.

>>else if (!type_dependent_expression_p (t)
>> && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
>>  {
>> -  error ("num_threads expression must be integral");
>> + switch (OMP_CLAUSE_CODE (c))
>> +{
>> +case OMP_CLAUSE_NUM_TASKS:
>> +  error ("% expression must be integral"); break;
>> +case OMP_CLAUSE_NUM_TEAMS:
>> +  error ("% expression must be integral"); break;
>> +case OMP_CLAUSE_NUM_THREADS:
>> +  error ("% expression must be integral"); break;
>> +case OMP_CLAUSE_NUM_GANGS:
>> +  error ("% expression must be integral"); break;
>> +case OMP_CLAUSE_NUM_WORKERS:
>> +  error ("% expression must be integral");
>> +  break;
>> +case OMP_CLAUSE_VECTOR_LENGTH:
>> +  error ("% expression must be integral");
>> +  break;
> 
> When touching these, can you please use error_at (OMP_CLAUSE_LOCATION (c),
> instead of error ( ?

Done

>> +default:
>> +  error ("invalid argument");
> 
> What invalid argument?  I'd say that is clearly gcc_unreachable (); case.
> 
> But, I think it would be better to just use
>   error_at (OMP_CLAUSE_LOCATION (c), "%qs expression must be integral",
>   omp_clause_code_name[c]);

I used that generic message for all of those clauses except for _GANG,
_WORKER and _VECTOR. The gang clause, at the very least, needed it to
disambiguate the static and num arguments. If you want I can handle
_WORKER and _VECTOR with the generic message. I only included it because
those arguments are optional, whereas they are mandatory for the other
clauses.

Is this patch OK for trunk?

Cesar

2015-10-26  Cesar Philippidis  
	Thomas Schwinge  
	James Norris  
	Joseph Myers  
	Julian Brown  
	Nathan Sidwell 
	Bernd Schmidt  

	gcc/cp/
	* parser.c (cp_parser_omp_clause_name): Add auto, gang, seq,
	vector, worker.
	(cp_parser_oacc_simple_clause): New.
	(cp_parser_oacc_shape_clause): New.
	(cp_parser_oacc_all_clauses): Add auto, gang, seq, vector, worker.
	(OACC_LOOP_CLAUSE_MASK): Likewise.
	* semantics.c (finish_omp_clauses): Add auto, gang, seq, vector,
	worker. Unify the handling of teams, tasks and vector_length with
	the other loop shape clauses.

2015-10-26  Nathan Sidwell 
	Cesar Philippidis  

[MCORE] Hookize GO_IF_LEGITIMATE_ADDRESS

2015-10-26 Thread Anatoliy Sokolov

Hi.

This patch removes obsolete GO_IF_LEGITIMATE_ADDRESS macros from
the MCORE back end in the GCC and introduce equivalent
TARGET_LEGITIMATE_ADDRESS_P target hook.

Regression tested on mcore-unknown-elf. Only compile test run.

OK for trunk?

2015-08-24  Anatoly Sokolov  

* config/mcore/mcore.h (REG_OK_FOR_BASE_P, REG_OK_FOR_INDEX_P,
  BASE_REGISTER_RTX_P, INDEX_REGISTER_RTX_P,
  GO_IF_LEGITIMATE_ADDRESS): Remove macros.
* config/mcore/mcore.c (mcore_reg_ok_for_base_p,
  mcore_base_register_rtx_p, mcore_legitimate_index_p,
  mcore_legitimate_address_p): New functions.
  (TARGET_ADDR_SPACE_LEGITIMATE_ADDRESS_P): Define.

Index: gcc/config/mcore/mcore.c
===
--- gcc/config/mcore/mcore.c(revision 227044)
+++ gcc/config/mcore/mcore.c(working copy)
@@ -156,6 +156,8 @@
 static bool   mcore_warn_func_return(tree);
 static void   mcore_option_override(void);
 static bool   mcore_legitimate_constant_p   (machine_mode, rtx);
+static bool  mcore_legitimate_address_p(machine_mode, rtx, bool,
+addr_space_t);
 
 /* MCore specific attributes.  */

@@ -243,6 +245,8 @@

 #undef TARGET_LEGITIMATE_CONSTANT_P
 #define TARGET_LEGITIMATE_CONSTANT_P mcore_legitimate_constant_p
+#undef TARGET_ADDR_SPACE_LEGITIMATE_ADDRESS_P
+#define TARGET_ADDR_SPACE_LEGITIMATE_ADDRESS_P mcore_legitimate_address_p

 #undef TARGET_WARN_FUNC_RETURN
 #define TARGET_WARN_FUNC_RETURN mcore_warn_func_return
@@ -3196,3 +3200,74 @@
 {
   return GET_CODE (x) != CONST_DOUBLE;
 }
+
+/* Helper function for `mcore_legitimate_address_p'.  */
+
+static bool
+mcore_reg_ok_for_base_p (const_rtx reg, bool strict_p)
+{
+  if (strict_p)
+return REGNO_OK_FOR_BASE_P (REGNO (reg));
+  else
+return (REGNO (reg) <= 16 || !HARD_REGISTER_P (reg));
+}
+
+static bool
+mcore_base_register_rtx_p (const_rtx x, bool strict_p)
+{
+  return REG_P(x) && mcore_reg_ok_for_base_p (x, strict_p);
+}
+
+/*  A legitimate index for a QI is 0..15, for HI is 0..30, for SI is 0..60,
+and for DI is 0..56 because we use two SI loads, etc.  */
+
+static bool
+mcore_legitimate_index_p (machine_mode mode, const_rtx op)
+{
+  if (CONST_INT_P (op))
+{
+  if (GET_MODE_SIZE (mode) >= 4
+ && (((unsigned HOST_WIDE_INT) INTVAL (op)) % 4) == 0
+ &&  ((unsigned HOST_WIDE_INT) INTVAL (op))
+ <= (unsigned HOST_WIDE_INT) 64 - GET_MODE_SIZE (mode))
+   return true;
+  if (GET_MODE_SIZE (mode) == 2
+ && (((unsigned HOST_WIDE_INT) INTVAL (op)) % 2) == 0
+ &&  ((unsigned HOST_WIDE_INT) INTVAL (op)) <= 30)
+   return true;
+  if (GET_MODE_SIZE (mode) == 1
+ && ((unsigned HOST_WIDE_INT) INTVAL (op)) <= 15)
+   return true;
+  }
+  return false;
+}
+
+
+/* Worker function for TARGET_ADDR_SPACE_LEGITIMATE_ADDRESS_P.
+
+   Allow  REG
+ REG + disp  */
+
+static bool
+mcore_legitimate_address_p (machine_mode mode, rtx x, bool strict_p,
+   addr_space_t as)
+{
+  gcc_assert (ADDR_SPACE_GENERIC_P (as));
+
+  if (mcore_base_register_rtx_p (x, strict_p))
+return true;
+  else if (GET_CODE (x) == PLUS || GET_CODE (x) == LO_SUM)
+{
+  rtx xop0 = XEXP (x, 0);
+  rtx xop1 = XEXP (x, 1);
+  if (mcore_base_register_rtx_p (xop0, strict_p)
+ && mcore_legitimate_index_p (mode, xop1))
+   return true;
+  if (mcore_base_register_rtx_p (xop1, strict_p)
+ && mcore_legitimate_index_p (mode, xop0))
+   return true;
+}
+
+  return false;
+}
+
Index: gcc/config/mcore/mcore.h
===
--- gcc/config/mcore/mcore.h(revision 227044)
+++ gcc/config/mcore/mcore.h(working copy)
@@ -529,91 +529,6 @@
 /* Recognize any constant value that is a valid address.  */
 #define CONSTANT_ADDRESS_P(X)   (GET_CODE (X) == LABEL_REF)

-/* The macros REG_OK_FOR..._P assume that the arg is a REG rtx
-   and check its validity for a certain class.
-   We have two alternate definitions for each of them.
-   The usual definition accepts all pseudo regs; the other rejects
-   them unless they have been allocated suitable hard regs.
-   The symbol REG_OK_STRICT causes the latter definition to be used.  */
-#ifndef REG_OK_STRICT
-
-/* Nonzero if X is a hard reg that can be used as a base reg
-   or if it is a pseudo reg.  */
-#define REG_OK_FOR_BASE_P(X) \
-   (REGNO (X) <= 16 || REGNO (X) >= FIRST_PSEUDO_REGISTER)
-
-/* Nonzero if X is a hard reg that can be used as an index
-   or if it is a pseudo reg.  */
-#define REG_OK_FOR_INDEX_P(X)  0
-
-#else
-
-/* Nonzero if X is a hard reg that can be used as a base reg.  */
-#define REG_OK_FOR_BASE_P(X)   \
-   REGNO_OK_FOR_BASE_P (REGNO (X))
-
-/* Nonzero if X is a hard reg that can be used as an index.  */

Re: [gomp4] Adjust UNQUE ifn

2015-10-26 Thread Nathan Sidwell

On 10/26/15 07:36, Richard Biener wrote:


Looks better now.

+ {
  #ifdef HAVE_oacc_fork

(etc.)  can you use target-insn.def and targetm.have_oacc_fork () instead?



I've committed this to gomp4.  Will port and update the patches for trunk.

nathan
2015-10-26  Nathan Sidwell  

	* internal-fn.c (expand_UNIQUE, expand_GOACC_DIM_SIZE,
	expand_GOACC_DIM_POS): Use targetm to discover and generate insns.
	* target-insns.def (oacc_dim_pos, oacc_dim_size, oacc_fork,
	oacc_join, unique): Define insns.

Index: gcc/internal-fn.c
===
--- gcc/internal-fn.c	(revision 229365)
+++ gcc/internal-fn.c	(working copy)
@@ -1970,32 +1970,30 @@ expand_UNIQUE (gcall *stmt)
   gcc_unreachable ();
 
 case IFN_UNIQUE_UNSPEC:
-#ifdef HAVE_unique
-  pattern = gen_unique ();
-#endif
+  if (targetm.have_unique ())
+	pattern = targetm.gen_unique ();
   break;
 
 case IFN_UNIQUE_OACC_FORK:
 case IFN_UNIQUE_OACC_JOIN:
-  {
-#if defined (HAVE_oacc_fork) && defined (HAVE_oacc_join)
-	tree lhs = gimple_call_lhs (stmt);
-	rtx target = const0_rtx;
-
-	if (lhs)
-	  target = expand_expr (lhs, NULL_RTX, VOIDmode, EXPAND_WRITE);
-
-	rtx data_dep = expand_normal (gimple_call_arg (stmt, 1));
-	rtx axis = expand_normal (gimple_call_arg (stmt, 2));
-
-	if (code == IFN_UNIQUE_OACC_FORK)
-	  pattern = gen_oacc_fork (target, data_dep, axis);
-	else
-	  pattern = gen_oacc_join (target, data_dep, axis);
-#else
+  if (targetm.have_oacc_fork () && targetm.have_oacc_join ())
+	{
+	  tree lhs = gimple_call_lhs (stmt);
+	  rtx target = const0_rtx;
+
+	  if (lhs)
+	target = expand_expr (lhs, NULL_RTX, VOIDmode, EXPAND_WRITE);
+
+	  rtx data_dep = expand_normal (gimple_call_arg (stmt, 1));
+	  rtx axis = expand_normal (gimple_call_arg (stmt, 2));
+
+	  if (code == IFN_UNIQUE_OACC_FORK)
+	pattern = targetm.gen_oacc_fork (target, data_dep, axis);
+	  else
+	pattern = targetm.gen_oacc_join (target, data_dep, axis);
+	}
+  else
 	gcc_unreachable ();
-#endif
-  }
   break;
 }
 
@@ -2012,40 +2010,47 @@ expand_GOACC_DATA_END_WITH_ARG (gcall *s
   gcc_unreachable ();
 }
 
+/* GOACC_DIM_SIZE returns the size of the specified compute axis.  */
+
 static void
-expand_GOACC_DIM_SIZE (gcall *ARG_UNUSED (stmt))
+expand_GOACC_DIM_SIZE (gcall *stmt)
 {
-#ifdef HAVE_oacc_dim_size
-  tree lhs = gimple_call_lhs (stmt);
-
-  if (!lhs)
-return;
-  
-  rtx target = expand_expr (lhs, NULL_RTX, VOIDmode, EXPAND_WRITE);
-  rtx dim = expand_expr (gimple_call_arg (stmt, 0), NULL_RTX,
-			 VOIDmode, EXPAND_NORMAL);
-  emit_insn (gen_oacc_dim_size (target, dim));
-#else
-  gcc_unreachable ();
-#endif
+  if (targetm.have_oacc_dim_size ())
+{
+  tree lhs = gimple_call_lhs (stmt);
+
+  if (!lhs)
+	return;
+
+  rtx target = expand_expr (lhs, NULL_RTX, VOIDmode, EXPAND_WRITE);
+  rtx dim = expand_expr (gimple_call_arg (stmt, 0), NULL_RTX,
+			 VOIDmode, EXPAND_NORMAL);
+  emit_insn (targetm.gen_oacc_dim_size (target, dim));
+}
+  else
+gcc_unreachable ();
 }
 
+/* GOACC_DIM_POS returns the index of the executing thread along the
+   specified axis.  */
+
 static void
-expand_GOACC_DIM_POS (gcall *ARG_UNUSED (stmt))
+expand_GOACC_DIM_POS (gcall *stmt)
 {
-#ifdef HAVE_oacc_dim_pos
-  tree lhs = gimple_call_lhs (stmt);
-
-  if (!lhs)
-return;
-  
-  rtx target = expand_expr (lhs, NULL_RTX, VOIDmode, EXPAND_WRITE);
-  rtx dim = expand_expr (gimple_call_arg (stmt, 0), NULL_RTX,
-			 VOIDmode, EXPAND_NORMAL);
-  emit_insn (gen_oacc_dim_pos (target, dim));
-#else
-  gcc_unreachable ();
-#endif
+  if (targetm.have_oacc_dim_pos ())
+{
+  tree lhs = gimple_call_lhs (stmt);
+
+  if (!lhs)
+	return;
+
+  rtx target = expand_expr (lhs, NULL_RTX, VOIDmode, EXPAND_WRITE);
+  rtx dim = expand_expr (gimple_call_arg (stmt, 0), NULL_RTX,
+			 VOIDmode, EXPAND_NORMAL);
+  emit_insn (targetm.gen_oacc_dim_pos (target, dim));
+}
+  else
+gcc_unreachable ();
 }
 
 /* All the GOACC_REDUCTION variants  get expanded in oacc_device_lower.  */
Index: gcc/target-insns.def
===
--- gcc/target-insns.def	(revision 229364)
+++ gcc/target-insns.def	(working copy)
@@ -64,6 +64,10 @@ DEF_TARGET_INSN (memory_barrier, (void))
 DEF_TARGET_INSN (movstr, (rtx x0, rtx x1, rtx x2))
 DEF_TARGET_INSN (nonlocal_goto, (rtx x0, rtx x1, rtx x2, rtx x3))
 DEF_TARGET_INSN (nonlocal_goto_receiver, (void))
+DEF_TARGET_INSN (oacc_dim_pos, (rtx x0, rtx x1))
+DEF_TARGET_INSN (oacc_dim_size, (rtx x0, rtx x1))
+DEF_TARGET_INSN (oacc_fork, (rtx x0, rtx x1, rtx x2))
+DEF_TARGET_INSN (oacc_join, (rtx x0, rtx x1, rtx x2))
 DEF_TARGET_INSN (prefetch, (rtx x0, rtx x1, rtx x2))
 DEF_TARGET_INSN (probe_stack, (rtx x0))
 DEF_TARGET_INSN (probe_stack_address, (rtx x0))
@@ -89,5 +93,6 @@ DEF_TARGET_INSN (stack_protect_test, (rt
 DEF_TARGET_INSN (store_multiple, 

Re: [PATCH] rs6000: p8vector-builtin-8.c test requires int128

2015-10-26 Thread David Edelsohn
On Sun, Oct 25, 2015 at 8:59 PM, Segher Boessenkool
 wrote:
> For 32-bit targets p8vector_ok does not imply we have int128.
>
> Tested with -m32,-m32/-mpowerpc64,-m64; okay for trunk?
>
>
> Segher
>
>
> 2015-10-26  Segher Boessenkool  
>
> gcc/testsuite/
> * gcc.target/powerpc/p8vector-builtin-8.c: Add "target int128".

Okay.

Thanks, David


Re: [gomp4.1] Handle new form of #pragma omp declare target

2015-10-26 Thread Jakub Jelinek
On Mon, Oct 26, 2015 at 09:35:52PM +0300, Ilya Verbin wrote:
> On Fri, Jul 17, 2015 at 15:05:59 +0200, Jakub Jelinek wrote:
> > As the testcases show, #pragma omp declare target has now a new form (well,
> > two; with some issues on it pending), where it is used just as a single
> > declarative directive rather than a pair of them and allows marking
> > vars and functions by name as "omp declare target" vars/functions (which the
> > middle-end etc. already handles), but also "omp declare target link", which
> > is a deferred var, that is not initially mapped (on devices without shared
> > memory with host), but has to be mapped explicitly.
> 
> I don't quite understand how link should work.  OpenMP 4.5 says:
> 
> "The list items of a link clause are not mapped by the declare target 
> directive.
> Instead, their mapping is deferred until they are mapped by target data or
> target constructs. They are mapped only for such regions."
>
> But doesn't this mean that the example bellow should work identically
> with/without USE_LINK defined?  Or is there some difference on other 
> testcases?

On your testcase, the end result is pretty much the same, the variable is
not mapped initially to the device, and at the beginning of omp target it is
mapped to device, at the end of the region it is unmapped from the device
(without copying back).

But consider:

int a = 1, b = 1;
#pragma omp declare target link (a) to (b)
int
foo (void)
{
  return a++ + b++;
}
#pragma omp declare target to (foo)
int
main ()
{
  a = 2;
  b = 2;
  int res;
  #pragma omp target map (to: a, b) map (from: res)
  {
res = foo () + foo ();
  }
  // This assumes only non-shared address space, so would need to be guarded
  // for that.
  if (res != (2 + 1) + (3 + 2))
__builtin_abort ();
  return 0;
}

Without declare target link or to, you can't use the global variables
in orphaned accelerated routines (unless you e.g. take the address of the
mapped variable in the region and pass it around).
The to variables (non-deferred) are always mapped and are initialized with
the original initializer, refcount is infinity.  link (deferred) work more
like the normal mapping, referencing those vars when they aren't explicitly
(or implicitly) mapped is unspecified behavior, if it is e.g. mapped freshly
with to kind, it gets the current value of the host var rather than the
original one.  But, beyond the mapping the compiler needs to ensure that
all uses of the link global var (or perhaps just all uses of the link global
var outside of the target construct body where it is mapped, because you
could use there the pointer you got from GOMP_target) are replaced by
dereference of some artificial pointer, so a becomes *a_tmp and  becomes
&*a_tmp, and that the runtime library during registration of the tables is
told about the address of this artificial pointer.  During registration,
I'd expect it would stick an entry for this range into the table, with some
special flag or something similar, indicating that it is deferred mapping
and where the offloading device pointer is.  During mapping, it would map it
as any other not yet mapped object, but additionally would also set this
device pointer to the device address of the mapped object.  We also need to
ensure that when we drop the refcount of that mapping back to 0, we get it
back to the state where it is described as a range with registered deferred
mapping and where the device pointer is.

> > This patch only marks them with the new attribute, the actual middle-end
> > implementation needs to be implemented.
> > 
> > I believe OpenACC has something similar, but no idea if it is already
> > implemented.
> > 
> > Anyway, I think the implementation should be that in some pass running on
> > the ACCEL_COMPILER side (guarded by separate address space aka non-HSA)
> 
> HSA does not define ACCEL_COMPILER, because it uses only one compiler.

HSA is a non-issue here, as it has shared address space, therefore map
clause does nothing, declare target to or link clauses also don't do
anything.

> > we actually replace the variables with pointers to variables, then need
> > to somehow also mark those in the offloading tables, so that the library
> 
> I see 2 possible options: use the MSB of the size, or introduce the third 
> field
> for flags.

Well, it can be either recorded in the host variable tables (which contain
address and size pair, right), or in corresponding offloading device table
(which contains the pointer, something else?).

Jakub


C++ PATCH for DR 2179 (ambiguous partial specialization after instantiation)

2015-10-26 Thread Jason Merrill
While discussing issue 2179 at the meeting last week, I noticed that we 
were crashing when a partial specialization made a previous 
instantiation ambiguous.  Fixed thus.


Tested x86_64-pc-linux-gnu, applying to trunk.
commit cb0817f19d7f4ce9878922412c2c1b2d07eb66d7
Author: Jason Merrill 
Date:   Sun Oct 25 05:22:50 2015 -1000

	DR 2179
	* pt.c (process_partial_specialization): Handle error_mark_node
	from most_specialized_partial_spec.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index ffe02da..2745b40 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -4690,14 +4690,18 @@ process_partial_specialization (tree decl)
 	  : DECL_TEMPLATE_INSTANTIATION (instance))
 	{
 	  tree spec = most_specialized_partial_spec (instance, tf_none);
-	  if (spec && TREE_VALUE (spec) == tmpl)
-	{
-	  tree inst_decl = (DECL_P (instance)
-? instance : TYPE_NAME (instance));
-	  permerror (input_location,
-			 "partial specialization of %qD after instantiation "
-			 "of %qD", decl, inst_decl);
-	}
+	  tree inst_decl = (DECL_P (instance)
+			? instance : TYPE_NAME (instance));
+	  if (!spec)
+	/* OK */;
+	  else if (spec == error_mark_node)
+	permerror (input_location,
+		   "declaration of %qD ambiguates earlier template "
+		   "instantiation for %qD", decl, inst_decl);
+	  else if (TREE_VALUE (spec) == tmpl)
+	permerror (input_location,
+		   "partial specialization of %qD after instantiation "
+		   "of %qD", decl, inst_decl);
 	}
 }
 
diff --git a/gcc/testsuite/g++.dg/template/partial-specialization3.C b/gcc/testsuite/g++.dg/template/partial-specialization3.C
new file mode 100644
index 000..c5f83bd
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/partial-specialization3.C
@@ -0,0 +1,7 @@
+// DR 2179
+
+template  class A;
+template  struct A { void f(); };
+template  void g(T) { A().f(); }   // #1
+template struct A {};		// { dg-error "" }
+A f;   // #2


[Fortran, committed] Statement label on empty line in derived type declaration (PR 66056)

2015-10-26 Thread Louis Krupp
Revision 229390...

Louis



Re: [PATCH][wwwdocs] Mention arm target attributes and pragmas in GCC 6 changes

2015-10-26 Thread Gerald Pfeifer

On Mon, 26 Oct 2015, Kyrill Tkachov wrote:

Here's a patch to mention the new target attributes for arm, in the same
wording as for aarch64.


This looks good to me, thanks.

Gerald


Re: [PATCH] Add missing INCLUDE_DEFAULTS_MUSL_LOCAL

2015-10-26 Thread Doug Evans
On Fri, Oct 23, 2015 at 11:34 AM, Szabolcs Nagy  wrote:
> On 23/10/15 18:39, Doug Evans wrote:
>>
>> On Fri, Oct 23, 2015 at 10:08 AM, Bernd Schmidt 
>> wrote:
>>>
>>>
>>> On 10/21/2015 09:00 PM, Doug Evans wrote:


 I happened to notice local prefixes not working with musl.
 Fixes thusly.
>>>
>>>
>>>
 Index: config/linux.h
 ===
 --- config/linux.h(revision 229130)
 +++ config/linux.h(working copy)
 @@ -174,6 +174,7 @@
#define INCLUDE_DEFAULTS\
  {\
INCLUDE_DEFAULTS_MUSL_GPP\
 +INCLUDE_DEFAULTS_MUSL_LOCAL\
INCLUDE_DEFAULTS_MUSL_PREFIX\
INCLUDE_DEFAULTS_MUSL_CROSS\
INCLUDE_DEFAULTS_MUSL_TOOL\
>>>
>>>
>>>
>>> Looks pretty obvious given that the macro isn't otherwise used AFAICT.
>>> However, I have no idea whether the order is right, since the purpose of all
>>> this code here is apparently only to provide a different order than the
>>> default.
>>>
>>> So, someone who worked on the original musl patches should comment. I
>>> would also like to know precisely which ordering change over the default is
>>> required, and that it be documented. Ideally we'd come up with a solution
>>> that makes us not duplicate all this stuff in linux.h.
>>>
>>>
>>> Bernd
>>
>>
>> Crap, sorry for the resend. G gmail ...
>>
>> The only significant different AFAICT is that GCC_INCLUDE_DIR is moved
>> to later (last).
>> Why this is is briefly described in the intro comment:
>>
>> config/linux.h:
>>   /* musl avoids problematic includes by rearranging the include
>> directories.
>>   * Unfortunately, this is mostly duplicated from cppdefault.c */
>>
>> I've put LOCAL in the same place as the default (as defined by
>> cppdefault.c),
>> so one could separate the issues here ...
>>
>> 1) Where does LOCAL go for musl?
>
>
> LOCAL should go the same place as in cppdefault.c
> so the patch is ok.

Committed. Thanks.


Re: [PATCH] rs6000: Fix tests for xvmadd and xvnmsub

2015-10-26 Thread David Edelsohn
On Sun, Oct 25, 2015 at 8:59 PM, Segher Boessenkool
 wrote:
> The patterns involved can create vmadd resp. vnmsub instructions instead.
> This patch changes the testcases to allow those.
>
> Tested with -m32,-m32/-mpowerpc64,-m64; okay for trunk?
>
>
> Segher
>
>
> 2015-10-26  Segher Boessenkool  
>
> gcc/testsuite/
> * gcc.target/powerpc/vsx-builtin-2.c: Allow vmadd and vnmsub as well
> as xvmadd and xvnmsub.
> * gcc.target/powerpc/vsx-vector-2.c: Allow vmadd as well as xvmadd.

Okay.

thanks, David


  1   2   3   >