Re: [PATCH] Do not build libsanitizer also for powerpc*-*-linux*

2014-06-02 Thread Jakub Jelinek
On Tue, Jun 03, 2014 at 10:19:48AM +0400, Yury Gribov wrote:
> >I took that patch and applied it to the gcc sources,
> >but I still see the error on ppc:
> >...
> >[bergner@makalu-lp1 asan]$ 
> >LD_LIBRARY_PATH=:/home/bergner/gcc/build/gcc-fsf-mainline-asan-debug-3/gcc:/home/bergner/gcc/build/gcc-fsf-mainline-asan-debug-3/gcc/32:/home/bergner/gcc/build/gcc-fsf-mainline-asan-debug-3/powerpc64-linux/32/libsanitizer/asan/.libs::/home/bergner/gcc/build/gcc-fsf-mainline-asan-debug-3/gcc:/home/bergner/gcc/build/gcc-fsf-mainline-asan-debug-3/gcc/32:/home/bergner/gcc/build/gcc-fsf-mainline-asan-debug-3/powerpc64-linux/32/libsanitizer/asan/.libs:
> > ldd ./asan-interface-1.exe
> > linux-vdso32.so.1 =>  (0x0010)
> > libm.so.6 => /lib/power8/libm.so.6 (0x0ff0)
> > libasan.so.1 => 
> > /home/bergner/gcc/build/gcc-fsf-mainline-asan-debug-3/powerpc64-linux/32/libsanitizer/asan/.libs/libasan.so.1
> >  (0x0f93)
> 
> Now check indeed seems to be useful: libasan should be the first
> library in the list when -fsanitize=address flag is present. Are
> compiler specs for Power somehow special?

-fsanitize=address should insert -lasan quite early on the linker command
line, please try to cut'n'paste the command line from testsuite/g++/g++.log
and add -v to see what is passed to the linker.
Perhaps the linker reorders the libraries?
Or do you have LD_PRELOAD?

Jakub


Re: [PATCH] Do not build libsanitizer also for powerpc*-*-linux*

2014-06-02 Thread Yury Gribov

I took that patch and applied it to the gcc sources,
but I still see the error on ppc:
...
[bergner@makalu-lp1 asan]$ 
LD_LIBRARY_PATH=:/home/bergner/gcc/build/gcc-fsf-mainline-asan-debug-3/gcc:/home/bergner/gcc/build/gcc-fsf-mainline-asan-debug-3/gcc/32:/home/bergner/gcc/build/gcc-fsf-mainline-asan-debug-3/powerpc64-linux/32/libsanitizer/asan/.libs::/home/bergner/gcc/build/gcc-fsf-mainline-asan-debug-3/gcc:/home/bergner/gcc/build/gcc-fsf-mainline-asan-debug-3/gcc/32:/home/bergner/gcc/build/gcc-fsf-mainline-asan-debug-3/powerpc64-linux/32/libsanitizer/asan/.libs:
 ldd ./asan-interface-1.exe
linux-vdso32.so.1 =>  (0x0010)
libm.so.6 => /lib/power8/libm.so.6 (0x0ff0)
libasan.so.1 => 
/home/bergner/gcc/build/gcc-fsf-mainline-asan-debug-3/powerpc64-linux/32/libsanitizer/asan/.libs/libasan.so.1
 (0x0f93)


Now check indeed seems to be useful: libasan should be the first library 
in the list when -fsanitize=address flag is present. Are compiler specs 
for Power somehow special?


-Y


Re: [PATCH, Pointer Bounds Checker 13/x] Early versioning

2014-06-02 Thread Ilya Enkovich
2014-06-02 21:27 GMT+04:00 Jeff Law :
> On 06/02/14 04:48, Ilya Enkovich wrote:
>>>
>>> Hmm, so if I understand things correctly, src_fun has no loop
>>> structures attached, thus there's nothing to copy.  Presumably at
>>> some later point we build loop structures for the copy from scratch?
>>
>> I suppose it is just a simple bug with absent NULL pointer check.  Here is
>> original code:
>>
>>/* Duplicate the loop tree, if available and wanted.  */
>>if (loops_for_fn (src_cfun) != NULL
>>&& current_loops != NULL)
>>  {
>>copy_loops (id, entry_block_map->loop_father,
>>get_loop (src_cfun, 0));
>>/* Defer to cfgcleanup to update loop-father fields of
>> basic-blocks.  */
>>loops_state_set (LOOPS_NEED_FIXUP);
>>  }
>>
>>/* If the loop tree in the source function needed fixup, mark the
>>   destination loop tree for fixup, too.  */
>>if (loops_for_fn (src_cfun)->state & LOOPS_NEED_FIXUP)
>>  loops_state_set (LOOPS_NEED_FIXUP);
>>
>> As you may see we have check for absent loops structure in the first
>> if-statement and no check in the second one.  I hit segfault and added the
>> check.
>
> Downthread you indicated you're not in SSA form which might explain the
> inconsistency here.  If so, then we need to make sure that the loop & df
> structures do get set up properly later.

That is what init_data_structures pass will do for us as Richard pointed. Right?

Ilya

>
> Jeff


C++ PATCH for c++/61134 (variadic templates)

2014-06-02 Thread Jason Merrill
Here the problem was that Fixed was canonicalized to refer to 
the Fields from the New template, so the parameter pack in typename 
Fixed::name... is the Fields from New rather than the one from 
CreateMetric, and so using == to compare them breaks.  If we use 
template_args_equal instead, everything is fine.


Tested x86_64-pc-linux-gnu, applying to trunk.
commit adca28aaa03741586551ef6355c799e0fab967af
Author: Jason Merrill 
Date:   Mon Jun 2 21:35:52 2014 -0400

	PR c++/61134
	* pt.c (pack_deducible_p): Handle canonicalization.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index c0e0646..a55a06b 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -15765,7 +15765,7 @@ pack_deducible_p (tree parm, tree fn)
 	continue;
   for (packs = PACK_EXPANSION_PARAMETER_PACKS (type);
 	   packs; packs = TREE_CHAIN (packs))
-	if (TREE_VALUE (packs) == parm)
+	if (template_args_equal (TREE_VALUE (packs), parm))
 	  {
 	/* The template parameter pack is used in a function parameter
 	   pack.  If this is the end of the parameter list, the
diff --git a/gcc/testsuite/g++.dg/cpp0x/variadic158.C b/gcc/testsuite/g++.dg/cpp0x/variadic158.C
new file mode 100644
index 000..cc5c24d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/variadic158.C
@@ -0,0 +1,24 @@
+// PR c++/61134
+// { dg-do compile { target c++11 } }
+
+struct Base { };
+
+template 
+struct Fixed {
+  typedef const char* name;
+};
+
+template 
+void New(const char* name,
+ typename Fixed::name... field_names);
+
+template 
+void CreateMetric(const char* name,
+  typename Fixed::name... field_names,
+  const Base&) { }
+
+
+void Fn()
+{
+  CreateMetric("abcd", "def", Base());
+}


Re: [PATCH] Do not build libsanitizer also for powerpc*-*-linux*

2014-06-02 Thread Peter Bergner
On Mon, 2014-06-02 at 14:48 +0400, Konstantin Serebryany wrote:
> Committed as r210012, please don't forget to add llvm-commits to CC
> next time (I did not see the message)
> Thanks!

I took that patch and applied it to the gcc sources, but I still
see the error on ppc:

[bergner@makalu-lp1
asan]$ /home/bergner/gcc/build/gcc-fsf-mainline-asan-debug-3/gcc/xgcc
-B/home/bergner/gcc/build/gcc-fsf-mainline-asan-debug-3/gcc/ 
/home/bergner/gcc/gcc-fsf-mainline-asan/gcc/testsuite/c-c++-common/asan/asan-interface-1.c
   
-B/home/bergner/gcc/build/gcc-fsf-mainline-asan-debug-3/powerpc64-linux/32/libsanitizer/
  
-B/home/bergner/gcc/build/gcc-fsf-mainline-asan-debug-3/powerpc64-linux/32/libsanitizer/asan/
  
-L/home/bergner/gcc/build/gcc-fsf-mainline-asan-debug-3/powerpc64-linux/32/libsanitizer/asan/.libs
  -fsanitize=address -g 
-I/home/bergner/gcc/gcc-fsf-mainline-asan/gcc/testsuite/../../libsanitizer/include
 -fno-diagnostics-show-caret -fdiagnostics-color=never   -O0  -lm   -m32 -o 
./asan-interface-1.exe

[bergner@makalu-lp1 asan]$
LD_LIBRARY_PATH=:/home/bergner/gcc/build/gcc-fsf-mainline-asan-debug-3/gcc:/home/bergner/gcc/build/gcc-fsf-mainline-asan-debug-3/gcc/32:/home/bergner/gcc/build/gcc-fsf-mainline-asan-debug-3/powerpc64-linux/32/libsanitizer/asan/.libs::/home/bergner/gcc/build/gcc-fsf-mainline-asan-debug-3/gcc:/home/bergner/gcc/build/gcc-fsf-mainline-asan-debug-3/gcc/32:/home/bergner/gcc/build/gcc-fsf-mainline-asan-debug-3/powerpc64-linux/32/libsanitizer/asan/.libs:
 ./asan-interface-1.exe ==36082==ASan runtime does not come first in initial 
library list; you should either link runtime to your application or manually 
preload it with LD_PRELOAD.

[bergner@makalu-lp1 asan]$ 
LD_LIBRARY_PATH=:/home/bergner/gcc/build/gcc-fsf-mainline-asan-debug-3/gcc:/home/bergner/gcc/build/gcc-fsf-mainline-asan-debug-3/gcc/32:/home/bergner/gcc/build/gcc-fsf-mainline-asan-debug-3/powerpc64-linux/32/libsanitizer/asan/.libs::/home/bergner/gcc/build/gcc-fsf-mainline-asan-debug-3/gcc:/home/bergner/gcc/build/gcc-fsf-mainline-asan-debug-3/gcc/32:/home/bergner/gcc/build/gcc-fsf-mainline-asan-debug-3/powerpc64-linux/32/libsanitizer/asan/.libs:
 ldd ./asan-interface-1.exe 
linux-vdso32.so.1 =>  (0x0010)
libm.so.6 => /lib/power8/libm.so.6 (0x0ff0)
libasan.so.1 => 
/home/bergner/gcc/build/gcc-fsf-mainline-asan-debug-3/powerpc64-linux/32/libsanitizer/asan/.libs/libasan.so.1
 (0x0f93)
libc.so.6 => /lib/power8/libc.so.6 (0x0f74)
/lib/ld.so.1 (0x206b)
libpthread.so.0 => /lib/power8/libpthread.so.0 (0x0f6f)
libdl.so.2 => /lib/libdl.so.2 (0x0f6b)
libstdc++.so.6 => 
/home/bergner/gcc/build/gcc-fsf-mainline-asan-debug-3/powerpc64-linux/32/libstdc++-v3/src/.libs/libstdc++.so.6
 (0x0f52)
libgcc_s.so.1 => 
/home/bergner/gcc/build/gcc-fsf-mainline-asan-debug-3/gcc/32/libgcc_s.so.1 
(0x0f4c)

If I explicitly add a -lasan before the -lm on the compile, then
everything works fine.  Is this a test case error for not linking
-lasan before -lm or ???

Peter




C++ PATCH for c++/61046 (ICE with invalid designated initializer)

2014-06-02 Thread Jason Merrill
The code in reshape_init_class shouldn't assume that anything not an 
INTEGER_CST or FIELD_DECL is an IDENTIFIER_NODE.


Tested x86_64-pc-linux-gnu, applying to trunk.
commit 6a71aad5b83d18f742ee208dd249c7759e5cccb3
Author: Jason Merrill 
Date:   Mon Jun 2 21:51:08 2014 -0400

	PR c++/61046
	* decl.c (reshape_init_class): Handle un-folded
	constant-expressions.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index c61ad68..8dc5f1f 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -5294,19 +5294,18 @@ reshape_init_class (tree type, reshape_iter *d, bool first_initializer_p,
 	  if (d->cur->index == error_mark_node)
 	return error_mark_node;
 
-	  if (TREE_CODE (d->cur->index) == INTEGER_CST)
-	{
-	  if (complain & tf_error)
-		error ("%<[%E] =%> used in a GNU-style designated initializer"
-		   " for class %qT", d->cur->index, type);
-	  return error_mark_node;
-	}
-
 	  if (TREE_CODE (d->cur->index) == FIELD_DECL)
 	/* We already reshaped this.  */
 	gcc_assert (d->cur->index == field);
-	  else
+	  else if (TREE_CODE (d->cur->index) == IDENTIFIER_NODE)
 	field = lookup_field_1 (type, d->cur->index, /*want_type=*/false);
+	  else
+	{
+	  if (complain & tf_error)
+		error ("%<[%E] =%> used in a GNU-style designated initializer"
+		   " for class %qT", d->cur->index, type);
+	  return error_mark_node;
+	}
 
 	  if (!field || TREE_CODE (field) != FIELD_DECL)
 	{
diff --git a/gcc/testsuite/g++.dg/ext/desig7.C b/gcc/testsuite/g++.dg/ext/desig7.C
new file mode 100644
index 000..44358ec
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/desig7.C
@@ -0,0 +1,8 @@
+// PR c++/61046
+
+struct A
+{
+  int ary[4];
+};
+const int i = 0;
+A bar = { [i] = 0 }; // { dg-error "designated" }


Re: RFA: Remove "m" column from backends.html

2014-06-02 Thread Segher Boessenkool
On Mon, Jun 02, 2014 at 08:14:49PM +0100, Richard Sandiford wrote:
> As per the patch I just posted, all ports have moved over to the new
> way of defining constraints.  This patch removes the associated "m"
> column from backends.html.  (Note that the ports still listed with "m"
> have in fact been converted.)

> -m   Port does not use define_constants.

define_constant and define_constraint are different beasts; or was
this a typo originally?


Segher


RFA: PATCH to ctor_for_folding for c++/61020 (ICE with typeid)

2014-06-02 Thread Jason Merrill
The C++ front end wants to be able to build up objects of the various 
typeinfo derived classes (such as __si_class_type_info) without needing 
to see the full definition of the class.  As part of this we build a 
VAR_DECL for the vtable, but never define it because we don't actually 
have declarations of the virtual functions, we're only using it for 
external references.  ctor_for_folding was assuming that all vtables are 
defined, which broke on this case.


Tested x86_64-pc-linux-gnu.  OK for trunk?
commit e13e596c640374df15c0a25d5049d5e30d08dc6b
Author: Jason Merrill 
Date:   Mon Jun 2 20:27:24 2014 -0400

	PR c++/61020
	* varpool.c (ctor_for_folding): Handle uninitialized vtables.

diff --git a/gcc/testsuite/g++.dg/opt/typeinfo1.C b/gcc/testsuite/g++.dg/opt/typeinfo1.C
new file mode 100644
index 000..efac4cb
--- /dev/null
+++ b/gcc/testsuite/g++.dg/opt/typeinfo1.C
@@ -0,0 +1,27 @@
+// PR c++/61020
+// { dg-options "-O2" }
+// { dg-do run }
+
+#include 
+
+struct Base {
+  virtual ~Base() { }
+};
+
+struct Derived : public Base {
+};
+
+int compare(const Base& base)
+{
+  return typeid(base) == typeid(typeid(Derived));
+}
+
+int main()
+{
+  Base base;
+  Derived derived;
+
+  if (compare(base)) return 1;
+  if (compare(derived)) return 2;
+  return 0;
+}
diff --git a/gcc/varpool.c b/gcc/varpool.c
index 1697bb4..143cd3b 100644
--- a/gcc/varpool.c
+++ b/gcc/varpool.c
@@ -306,7 +306,16 @@ ctor_for_folding (tree decl)
   if (DECL_VIRTUAL_P (real_decl))
 {
   gcc_checking_assert (TREE_READONLY (real_decl));
-  return DECL_INITIAL (real_decl);
+  if (DECL_INITIAL (real_decl))
+	return DECL_INITIAL (real_decl);
+  else
+	{
+	  /* The C++ front end creates VAR_DECLs for vtables of typeinfo
+	 classes not defined in the current TU so that it can refer
+	 to them from typeinfo objects.  Avoid returning NULL_TREE.  */
+	  gcc_checking_assert (!COMPLETE_TYPE_P (DECL_CONTEXT (real_decl)));
+	  return error_mark_node;
+	}
 }
 
   /* If there is no constructor, we have nothing to do.  */


[C++ Patch, obvious] Avoid spurious -Wuninitialized warning

2014-06-02 Thread Paolo Carlini

Hi,

I noticed only today that the code I touched a few days ago can trigger 
a spurious -Wuninitialized warning, which I'm going to avoid with the below.


Thanks,
Paolo.


2014-06-02  Paolo Carlini  

* pt.c (tsubst_function_type): Initialize arg_types.
Index: pt.c
===
--- pt.c(revision 211157)
+++ pt.c(working copy)
@@ -11320,7 +11320,7 @@ tsubst_function_type (tree t,
  tree in_decl)
 {
   tree return_type;
-  tree arg_types;
+  tree arg_types = NULL_TREE;
   tree fntype;
 
   /* The TYPE_CONTEXT is not used for function/method types.  */


[PATCH/AARCH64v2 1/2] Factor out IF_THEN_ELSE case from aarch64_rtx_costs

2014-06-02 Thread Andrew Pinski
This factors out the IF_THEN_ELSE from aarch64_rtx_costs as that function was 
getting too large.

OK?  Build and tested for aarch64-elf with no regressions.

Thanks,
Andrew Pinski

ChangeLog:
* config/aarch64/aarch64.c (aarch64_if_then_else_costs): New function.
(aarch64_rtx_costs): Use aarch64_if_then_else_costs.


---
 gcc/config/aarch64/aarch64.c |  126 ++
 1 files changed, 66 insertions(+), 60 deletions(-)

diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index bb33304..77a6706 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -4849,6 +4849,70 @@ aarch64_rtx_arith_op_extract_p (rtx x, enum machine_mode 
mode)
   return false;
 }
 
+/* Calculate the cost of calculating (if_then_else (OP0) (OP1) (OP2)),
+   storing it in *COST.  Result is true if the total cost of the operation
+   has now been calculated.  */
+static bool
+aarch64_if_then_else_costs (rtx op0, rtx op1, rtx op2, int *cost, bool speed)
+{
+  if (GET_CODE (op1) == PC || GET_CODE (op2) == PC)
+{
+  /* Conditional branch.  */
+  if (GET_MODE_CLASS (GET_MODE (XEXP (op0, 0))) == MODE_CC)
+   return true;
+  else
+   {
+ if (GET_CODE (op0) == NE
+ || GET_CODE (op0) == EQ)
+   {
+ rtx inner = XEXP (op0, 0);
+ rtx comparator = XEXP (op0, 1);
+
+ if (comparator == const0_rtx)
+   {
+ /* TBZ/TBNZ/CBZ/CBNZ.  */
+ if (GET_CODE (inner) == ZERO_EXTRACT)
+   /* TBZ/TBNZ.  */
+   *cost += rtx_cost (XEXP (inner, 0), ZERO_EXTRACT,
+  0, speed);
+   else
+ /* CBZ/CBNZ.  */
+ *cost += rtx_cost (inner, GET_CODE (op0), 0, speed);
+
+   return true;
+ }
+   }
+ else if (GET_CODE (op0) == LT
+  || GET_CODE (op0) == GE)
+   {
+ rtx comparator = XEXP (op0, 1);
+
+ /* TBZ/TBNZ.  */
+ if (comparator == const0_rtx)
+   return true;
+   }
+   }
+}
+  else if (GET_MODE_CLASS (GET_MODE (XEXP (op0, 0))) == MODE_CC)
+{
+  /* It's a conditional operation based on the status flags,
+so it must be some flavor of CSEL.  */
+
+  /* CSNEG, CSINV, and CSINC are handled for free as part of CSEL.  */
+  if (GET_CODE (op1) == NEG
+  || GET_CODE (op1) == NOT
+  || (GET_CODE (op1) == PLUS && XEXP (op1, 1) == const1_rtx))
+   op1 = XEXP (op1, 0);
+
+  *cost += rtx_cost (op1, IF_THEN_ELSE, 1, speed);
+  *cost += rtx_cost (op2, IF_THEN_ELSE, 2, speed);
+  return true;
+}
+
+  /* We don't know what this is, cost all operands.  */
+  return false;
+}
+
 /* Calculate the cost of calculating X, storing it in *COST.  Result
is true if the total cost of the operation has now been calculated.  */
 static bool
@@ -5583,66 +5647,8 @@ cost_plus:
   return false;  /* All arguments need to be in registers.  */
 
 case IF_THEN_ELSE:
-  op2 = XEXP (x, 2);
-  op0 = XEXP (x, 0);
-  op1 = XEXP (x, 1);
-
-  if (GET_CODE (op1) == PC || GET_CODE (op2) == PC)
-{
-  /* Conditional branch.  */
-  if (GET_MODE_CLASS (GET_MODE (XEXP (op0, 0))) == MODE_CC)
-   return true;
- else
-   {
- if (GET_CODE (op0) == NE
- || GET_CODE (op0) == EQ)
-   {
- rtx inner = XEXP (op0, 0);
- rtx comparator = XEXP (op0, 1);
-
- if (comparator == const0_rtx)
-   {
- /* TBZ/TBNZ/CBZ/CBNZ.  */
- if (GET_CODE (inner) == ZERO_EXTRACT)
-   /* TBZ/TBNZ.  */
-   *cost += rtx_cost (XEXP (inner, 0), ZERO_EXTRACT,
-  0, speed);
- else
-   /* CBZ/CBNZ.  */
-   *cost += rtx_cost (inner, GET_CODE (op0), 0, speed);
-
- return true;
-   }
-   }
- else if (GET_CODE (op0) == LT
-  || GET_CODE (op0) == GE)
-   {
- rtx comparator = XEXP (op0, 1);
-
- /* TBZ/TBNZ.  */
- if (comparator == const0_rtx)
-   return true;
-   }
-   }
-}
-  else if (GET_MODE_CLASS (GET_MODE (XEXP (op0, 0))) == MODE_CC)
-{
-  /* It's a conditional operation based on the status flags,
- so it must be some flavor of CSEL.  */
-
-  /* CSNEG, CSINV, and CSINC are handled for free as part of CSEL.  */
-  if (GET_CODE (op1) == NEG
-  || GET_CODE (op1) == NOT
-  || (GET_CODE (op1) == PLUS && XEXP (op1, 1) == const1_rtx))
-op1 = XEXP (op1, 0);

[PATCH/AARCH64v2 2/2] Fix PR 61345: rtx_cost ICEing on simple code

2014-06-02 Thread Andrew Pinski
Hi,
  The problem here is aarch64_rtx_costs for IF_THEN_ELSE does not
handle the case where the first operand is a non comparison.  This
happens when the combine is combing a few RTLs and calling
set_src_cost to check the costs of the newly created rtl.

OK?  Built and tested on aarch64-elf with no regressions.

Thanks,
Andrew Pinski

ChangeLog:
* config/aarch64/aarch64.c (aarch64_if_then_else_costs): Allow non 
comparisons
for OP0.

testsuite/ChangeLog:
* gcc.c-torture/compile/20140528-1.c: New testcase.

---
 gcc/config/aarch64/aarch64.c |   36 ++---
 gcc/testsuite/gcc.c-torture/compile/20140528-1.c |9 +
 2 files changed, 33 insertions(+), 12 deletions(-)
 create mode 100644 gcc/testsuite/gcc.c-torture/compile/20140528-1.c

diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index 77a6706..ce4eb3c 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -4855,19 +4855,33 @@ aarch64_rtx_arith_op_extract_p (rtx x, enum 
machine_mode mode)
 static bool
 aarch64_if_then_else_costs (rtx op0, rtx op1, rtx op2, int *cost, bool speed)
 {
+  rtx inner;
+  rtx comparator;
+  enum rtx_code cmpcode;
+
+  if (COMPARISON_P (op0))
+{
+  inner = XEXP (op0, 0);
+  comparator = XEXP (op0, 1);
+  cmpcode = GET_CODE (op0);
+}
+  else
+{
+  inner = op0;
+  comparator = const0_rtx;
+  cmpcode = NE;
+}
+
   if (GET_CODE (op1) == PC || GET_CODE (op2) == PC)
 {
   /* Conditional branch.  */
-  if (GET_MODE_CLASS (GET_MODE (XEXP (op0, 0))) == MODE_CC)
+  if (GET_MODE_CLASS (GET_MODE (inner)) == MODE_CC)
return true;
   else
{
- if (GET_CODE (op0) == NE
- || GET_CODE (op0) == EQ)
+ if (cmpcode == NE
+ || cmpcode == EQ)
{
- rtx inner = XEXP (op0, 0);
- rtx comparator = XEXP (op0, 1);
-
  if (comparator == const0_rtx)
{
  /* TBZ/TBNZ/CBZ/CBNZ.  */
@@ -4877,23 +4891,21 @@ aarch64_if_then_else_costs (rtx op0, rtx op1, rtx op2, 
int *cost, bool speed)
   0, speed);
else
  /* CBZ/CBNZ.  */
- *cost += rtx_cost (inner, GET_CODE (op0), 0, speed);
+ *cost += rtx_cost (inner, cmpcode, 0, speed);
 
return true;
  }
}
- else if (GET_CODE (op0) == LT
-  || GET_CODE (op0) == GE)
+ else if (cmpcode == LT
+  || cmpcode == GE)
{
- rtx comparator = XEXP (op0, 1);
-
  /* TBZ/TBNZ.  */
  if (comparator == const0_rtx)
return true;
}
}
 }
-  else if (GET_MODE_CLASS (GET_MODE (XEXP (op0, 0))) == MODE_CC)
+  else if (GET_MODE_CLASS (GET_MODE (inner)) == MODE_CC)
 {
   /* It's a conditional operation based on the status flags,
 so it must be some flavor of CSEL.  */
diff --git a/gcc/testsuite/gcc.c-torture/compile/20140528-1.c 
b/gcc/testsuite/gcc.c-torture/compile/20140528-1.c
new file mode 100644
index 000..d227802
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/20140528-1.c
@@ -0,0 +1,9 @@
+unsigned f(unsigned flags, unsigned capabilities)
+{
+  unsigned gfp_mask;
+  unsigned gfp_notmask = 0;
+  gfp_mask = flags & ((1 << 25) - 1);
+  if (!(capabilities & 0x0001))
+gfp_mask |= 0x100u;
+  return (gfp_mask & ~gfp_notmask);
+}
-- 
1.7.2.5



Re: [PATCH] Simplify a VEC_SELECT fed by its own inverse

2014-06-02 Thread Andreas Schwab
Bill Schmidt  writes:

> Index: gcc/testsuite/gcc.target/powerpc/vsxcopy.c
> ===
> --- gcc/testsuite/gcc.target/powerpc/vsxcopy.c(revision 0)
> +++ gcc/testsuite/gcc.target/powerpc/vsxcopy.c(working copy)
> @@ -0,0 +1,15 @@
> +/* { dg-do compile { target { powerpc64*-*-* } } } */
> +/* { dg-require-effective-target powerpc_vsx_ok } */
> +/* { dg-options "-O1" } */
> +/* { dg-final { scan-assembler "lxvd2x" } } */
> +/* { dg-final { scan-assembler "stxvd2x" } } */
> +/* { dg-final { scan-assembler-not "xxpermdi" } } */

You need -mvsx if you want to see VSX insns.  Tested on
powerpc64-suse-linux and installed as obvious.

Andreas.

* gcc.target/powerpc/vsxcopy.c (dg-options): Add -mvsx.

diff --git a/gcc/testsuite/gcc.target/powerpc/vsxcopy.c 
b/gcc/testsuite/gcc.target/powerpc/vsxcopy.c
index fc1f0bd..fbe3c67 100644
--- a/gcc/testsuite/gcc.target/powerpc/vsxcopy.c
+++ b/gcc/testsuite/gcc.target/powerpc/vsxcopy.c
@@ -1,6 +1,6 @@
 /* { dg-do compile { target { powerpc64*-*-* } } } */
 /* { dg-require-effective-target powerpc_vsx_ok } */
-/* { dg-options "-O1" } */
+/* { dg-options "-O1 -mvsx" } */
 /* { dg-final { scan-assembler "lxvd2x" } } */
 /* { dg-final { scan-assembler "stxvd2x" } } */
 /* { dg-final { scan-assembler-not "xxpermdi" } } */
-- 
2.0.0

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


Re: [Ping for C++ frontend review] [PATCH] PR debug/57519

2014-06-02 Thread Jason Merrill
Applied, thanks.  I tweaked the testcase a little so it would actually 
fail without your change.


Jason


Re: [C PATCH] Warn if switch has boolean value (PR c/60439)

2014-06-02 Thread Jason Merrill

On 05/24/2014 04:00 AM, Marek Polacek wrote:

+ /* Warn if the condition has boolean value.  */
+ tree e = cond;
+ while (TREE_CODE (e) == COMPOUND_EXPR)
+   e = TREE_OPERAND (e, 1);
+
+ if (TREE_CODE (orig_type) == BOOLEAN_TYPE
+ || (truth_value_p (TREE_CODE (e))
+ && TREE_CODE (orig_type) != INTEGER_TYPE))
+   warning_at (input_location, OPT_Wswitch_bool,
+   "switch condition has boolean value");


For C++ it should be "type bool", not "boolean value".  And it should be 
enough to just check for BOOLEAN_TYPE, without looking through 
COMPOUND_EXPR.



2) Since the warning is now enabled even for the C++ FE, it's
   exercised during bootstrap.  Turned out that gengtype generates
   code like
   switch (TREE_CODE (...) == INTEGER_TYPE) { ... }
   that would mar the bootstrap - so I tweaked it to generate
   switch ((int) (TREE_CODE (...) == INTEGER_TYPE) { ... })
   instead.  Does that make sense?


Makes sense to me.

Jason



Re: [PATCH, i386]: Correctly handle maximum size of stringop algorithm in decide_alg

2014-06-02 Thread Uros Bizjak
On Mon, Jun 2, 2014 at 11:12 PM, Uros Bizjak  wrote:

> A problem was uncovered by -march=corei7 -mtune=intel -m32 with
> i386/memcpy-[23] testcase in decide_alg subroutine [1]. Although the
> max size of the transfer was known, the memcpy was not inlined, as
> expected by the testcase.
>
> The core of the problem can be seen in the definition of 32bit
> intel_memcpy stringop alg:
>
>   {libcall, {{11, loop, false}, {-1, rep_prefix_4_byte, false}}},
>
> Please note that the last algorithm sets its maximum size to -1,
> "unlimited". However, in decide_alg, the same number also signals that
> no algorithm sets its size, so expected_size is never calculated. In
> the loop that sets maximal size for user defined algorithm, it is
> assumed that "-1" belongs exclusively to libcall, which is not the
> case in the above intel_memcpy definition:
>
>   if (candidate != libcall && candidate && usable)
>   max = algs->size[i].max;
>
> When the last non-libcall algorithm sets its maximum to "-1" (aka
> "unlimited"), this value fails following test:
>
>   if (max > 1 && (unsigned HOST_WIDE_INT) max >= max_size
>
> and expected_size is never calculated.
>
> Attached patch fixes this oversight, so "-1" means unlimited size and
> "0" means that size was never set. The patch also considers these two
> special values when choosing a maximum size for dynamic check.
>
> 2014-06-02  Uros Bizjak  
>
> * config/i386/i386.c (decide_alg): Correctly handle maximum size of
> stringop algorithm.
>
> Patch was bootstrapped and regression tested on x86_64-pc-linux-gnu
> {,-m32}, also with
> RUNTESTFLAGS="--target_board=unix/-march=corei7/-mtune=intel\{,-m32\}",
> where it fixes both memcpy failures from [1].
>
> [1] https://gcc.gnu.org/ml/gcc-testresults/2014-06/msg00127.html
>
> Jan, can you please review the patch, to check if the logic is OK?

Whoops, wrong patch was attached. Now with the correct attachment.

Uros.
Index: ChangeLog
===
--- ChangeLog   (revision 211140)
+++ ChangeLog   (working copy)
@@ -1,3 +1,8 @@
+2014-06-02  Uros Bizjak  
+
+   * config/i386/i386.c (decide_alg): Correctly handle maximum size of
+   stringop algorithm.
+
 2014-06-02  Marcus Shawcroft  
 
* config/aarch64/aarch64.md (set_fpcr): Drop ISB after FPCR write.
Index: config/i386/i386.c
===
--- config/i386/i386.c  (revision 211140)
+++ config/i386/i386.c  (working copy)
@@ -23828,7 +23828,7 @@ decide_alg (HOST_WIDE_INT count, HOST_WIDE_INT exp
 {
   const struct stringop_algs * algs;
   bool optimize_for_speed;
-  int max = -1;
+  int max = 0;
   const struct processor_costs *cost;
   int i;
   bool any_alg_usable_p = false;
@@ -23866,7 +23866,7 @@ decide_alg (HOST_WIDE_INT count, HOST_WIDE_INT exp
   /* If expected size is not known but max size is small enough
  so inline version is a win, set expected size into
  the range.  */
-  if (max > 1 && (unsigned HOST_WIDE_INT) max >= max_size
+  if (((max > 1 && (unsigned HOST_WIDE_INT) max >= max_size) || max == -1)
   && expected_size == -1)
 expected_size = min_size / 2 + max_size / 2;
 
@@ -23955,7 +23955,7 @@ decide_alg (HOST_WIDE_INT count, HOST_WIDE_INT exp
 *dynamic_check = 128;
   return loop_1_byte;
 }
-  if (max == -1)
+  if (max <= 0)
max = 4096;
   alg = decide_alg (count, max / 2, min_size, max_size, memset,
zero_memset, dynamic_check, noalign);


[PATCH] Fix ICE due to memory corruption in SRA

2014-06-02 Thread Teresa Johnson
This patch fixes an ICE due to memory corruption discovered while building a
large application with FDO and LIPO on the google branch. I don't have a small
reproducer, but the same code appears on trunk, and I believe it could also
silently result in incorrect code generation.

The problem occurs if SRA is applied on a recursive call. In this case,
the redirect_callers vec below contains the recursive edge from node->node.
When rebuild_cgraph_edges is invoked, it will free the callee edges of node,
including the one recorded in redirect_callers. In the case I looked at,
after rebuilding the cgraph edges for node, the address recorded in
redirect_callers now pointed to a different cgraph edge, and we later
got an ICE because the (incorrect) callee that we tried to modify had
the wrong number of arguments.

To fix, I simply moved the collection of caller edges to after the cgraph
edge rebuilding.

Google ref b/15383777.

Bootstrapped and tested on x86_64-unknown-linux-gnu. Ok for trunk?

Thanks,
Teresa

2014-06-02  Teresa Johnson  

* tree-sra.c (modify_function): Record caller nodes after rebuild.

Index: tree-sra.c
===
--- tree-sra.c  (revision 211139)
+++ tree-sra.c  (working copy)
@@ -4925,12 +4925,15 @@ modify_function (struct cgraph_node *node, ipa_par
 {
   struct cgraph_node *new_node;
   bool cfg_changed;
-  vec redirect_callers = collect_callers_of_node (node);

   rebuild_cgraph_edges ();
   free_dominance_info (CDI_DOMINATORS);
   pop_cfun ();

+  /* This must be done after rebuilding cgraph edges for node above.
+ Otherwise any recursive calls to node that are recorded in
+ redirect_callers will be corrupted.  */
+  vec redirect_callers = collect_callers_of_node (node);
   new_node = cgraph_function_versioning (node, redirect_callers,
 NULL,
 NULL, false, NULL, NULL, "isra");
-- 
Teresa Johnson | Software Engineer | tejohn...@google.com | 408-460-2413


[PATCH, i386]: Correctly handle maximum size of stringop algorithm in decide_alg

2014-06-02 Thread Uros Bizjak
Hello!

A problem was uncovered by -march=corei7 -mtune=intel -m32 with
i386/memcpy-[23] testcase in decide_alg subroutine [1]. Although the
max size of the transfer was known, the memcpy was not inlined, as
expected by the testcase.

The core of the problem can be seen in the definition of 32bit
intel_memcpy stringop alg:

  {libcall, {{11, loop, false}, {-1, rep_prefix_4_byte, false}}},

Please note that the last algorithm sets its maximum size to -1,
"unlimited". However, in decide_alg, the same number also signals that
no algorithm sets its size, so expected_size is never calculated. In
the loop that sets maximal size for user defined algorithm, it is
assumed that "-1" belongs exclusively to libcall, which is not the
case in the above intel_memcpy definition:

  if (candidate != libcall && candidate && usable)
  max = algs->size[i].max;

When the last non-libcall algorithm sets its maximum to "-1" (aka
"unlimited"), this value fails following test:

  if (max > 1 && (unsigned HOST_WIDE_INT) max >= max_size

and expected_size is never calculated.

Attached patch fixes this oversight, so "-1" means unlimited size and
"0" means that size was never set. The patch also considers these two
special values when choosing a maximum size for dynamic check.

2014-06-02  Uros Bizjak  

* config/i386/i386.c (decide_alg): Correctly handle maximum size of
stringop algorithm.

Patch was bootstrapped and regression tested on x86_64-pc-linux-gnu
{,-m32}, also with
RUNTESTFLAGS="--target_board=unix/-march=corei7/-mtune=intel\{,-m32\}",
where it fixes both memcpy failures from [1].

[1] https://gcc.gnu.org/ml/gcc-testresults/2014-06/msg00127.html

Jan, can you please review the patch, to check if the logic is OK?

Uros.
Index: fuse-caller-save.c
===
--- fuse-caller-save.c  (revision 22)
+++ fuse-caller-save.c  (working copy)
@@ -1,5 +1,7 @@
 /* { dg-do compile } */
 /* { dg-options "-O2 -fuse-caller-save" } */
+/* { dg-additional-options "-mregparm=1" { target ia32 } } */
+
 /* Testing -fuse-caller-save optimization option.  */
 
 static int __attribute__((noinline))
Index: sibcall-1.c
===
--- sibcall-1.c (revision 22)
+++ sibcall-1.c (working copy)
@@ -1,5 +1,4 @@
-/* { dg-do compile } */
-/* { dg-require-effective-target ia32 } */
+/* { dg-do compile { target ia32 } } */
 /* { dg-options "-O2" } */
 
 extern int (*foo)(int);
Index: sibcall-2.c
===
--- sibcall-2.c (revision 28)
+++ sibcall-2.c (working copy)
@@ -1,5 +1,4 @@
-/* { dg-do compile { xfail { *-*-* } } } */
-/* { dg-require-effective-target ia32 } */
+/* { dg-do compile { target ia32 } } */
 /* { dg-options "-O2" } */
 
 extern int doo1 (int);
@@ -13,4 +12,4 @@
   return (a < 0 ? doo1 : doo2) (a);
 }
 
-/* { dg-final { scan-assembler-not "call\[ \t\]*.%eax" } } */
+/* { dg-final { scan-assembler-not "call\[ \t\]*.%eax" { xfail *-*-* } } } */
Index: sibcall-3.c
===
--- sibcall-3.c (revision 28)
+++ sibcall-3.c (working copy)
@@ -1,5 +1,4 @@
-/* { dg-do compile } */
-/* { dg-require-effective-target ia32 } */
+/* { dg-do compile { target ia32 } } */
 /* { dg-options "-O2" } */
 
 extern 
Index: sibcall-4.c
===
--- sibcall-4.c (revision 28)
+++ sibcall-4.c (working copy)
@@ -1,6 +1,5 @@
 /* Testcase for PR target/46219.  */
-/* { dg-do compile { xfail { *-*-* } } } */
-/* { dg-require-effective-target ia32 } */
+/* { dg-do compile  { target ia32 } } */
 /* { dg-options "-O2" } */
 
 typedef void (*dispatch_t)(long offset);
@@ -12,4 +11,4 @@
   dispatch[offset](offset);
 }
 
-/* { dg-final { scan-assembler-not "jmp\[ \t\]*.%eax" } } */
+/* { dg-final { scan-assembler-not "jmp\[ \t\]*.%eax" { xfail *-*-* } } } */
Index: sibcall-5.c
===
--- sibcall-5.c (revision 22)
+++ sibcall-5.c (working copy)
@@ -1,6 +1,5 @@
 /* Check that indirect sibcalls understand regparm.  */
-/* { dg-do run } */
-/* { dg-require-effective-target ia32 } */
+/* { dg-do run { target ia32 } } */
 /* { dg-options "-O2" } */
 
 extern void abort (void);
Index: sibcall-6.c
===
--- sibcall-6.c (revision 28)
+++ sibcall-6.c (working copy)
@@ -1,5 +1,4 @@
-/* { dg-do compile } */
-/* { dg-require-effective-target ia32 } */
+/* { dg-do compile { target ia32 } } */
 /* { dg-options "-O2" } */
 
 typedef void *ira_loop_tree_node_t;


Re: [PATCH] rebuild frequency after vrp

2014-06-02 Thread Jan Hubicka
> On 06/02/14 14:27, Jan Hubicka wrote:
> >>On 06/02/14 12:07, Jan Hubicka wrote:
> >>>
> >>>It is one of reasions why I think it would be cool to do jump threading in
> >>>early opts, too, at least in a lightweidt form.
> >>Conceptually it's pretty easy to do during the into-ssa step.  Not
> >>sure it it'd catch the cases you care about though.
> >
> >Yep, it may be an option, too. I always had in mind Muchnick style cheap
> >DOM pass run during into-SSA or as very first cleanup to get rid of 
> >unnecesary
> >code quickly and cheaply. Our DOM is bit different beast though :).
> >Very basic jump threading may fit here - never really tought about that.
> We had all this about 10 years ago ;-)  DOM actually started its
> life a Morgan-esque bolt onto the renamer.

Yep, I know :)) But being one of first SSA passes, it envoled to be bit too
smart for what I want.

I used to have some numbers on running dom or VRP early. I suppose I can
re-test them and see how much benefits that makes.  This things are bit hard
to get - strenghtening early opts always makes inliner to increase its activity
making a mess of code size comparsions.
> 
> 
> 
> >You probably know better than me how many of threading oppurtunities are
> >"obvious" and how many are the difficult ones solved by VRP&DOM. My gut 
> >feeling
> >is that doing the obvious ones may be good enough. But I do not know.
> A huge number of them are trivially derivable by just looking at the
> PHI nodes in the current block and I've pondered many times having a
> simpler jump threading pass that runs early in the gimple pipeline.

Yep, I think it would make sense indeed even though we currently have 3 
threading
passes and I am responsible for one of them already :)

Honza
> 
> Jeff


Re: [PATCH] rebuild frequency after vrp

2014-06-02 Thread Jeff Law

On 06/02/14 14:27, Jan Hubicka wrote:

On 06/02/14 12:07, Jan Hubicka wrote:


It is one of reasions why I think it would be cool to do jump threading in
early opts, too, at least in a lightweidt form.

Conceptually it's pretty easy to do during the into-ssa step.  Not
sure it it'd catch the cases you care about though.


Yep, it may be an option, too. I always had in mind Muchnick style cheap
DOM pass run during into-SSA or as very first cleanup to get rid of unnecesary
code quickly and cheaply. Our DOM is bit different beast though :).
Very basic jump threading may fit here - never really tought about that.
We had all this about 10 years ago ;-)  DOM actually started its life a 
Morgan-esque bolt onto the renamer.





You probably know better than me how many of threading oppurtunities are
"obvious" and how many are the difficult ones solved by VRP&DOM. My gut feeling
is that doing the obvious ones may be good enough. But I do not know.
A huge number of them are trivially derivable by just looking at the PHI 
nodes in the current block and I've pondered many times having a simpler 
jump threading pass that runs early in the gimple pipeline.


Jeff



Re: [PATCH] rebuild frequency after vrp

2014-06-02 Thread Jan Hubicka
> On 06/02/14 12:07, Jan Hubicka wrote:
> >
> >It is one of reasions why I think it would be cool to do jump threading in
> >early opts, too, at least in a lightweidt form.
> Conceptually it's pretty easy to do during the into-ssa step.  Not
> sure it it'd catch the cases you care about though.

Yep, it may be an option, too. I always had in mind Muchnick style cheap
DOM pass run during into-SSA or as very first cleanup to get rid of unnecesary
code quickly and cheaply. Our DOM is bit different beast though :).
Very basic jump threading may fit here - never really tought about that.

You probably know better than me how many of threading oppurtunities are
"obvious" and how many are the difficult ones solved by VRP&DOM. My gut feeling
is that doing the obvious ones may be good enough. But I do not know.

Honza
> 
> jeff
> 


Re: [PATCH, Fortan] fix initialization of flag_errno_math and flag_associative_math

2014-06-02 Thread FX
> Why do you want -fno-math-errno to be the default for gfortran?
> AFAICT such default is not documented and the flag works
> (checked on your test gfortran.dg/errnocheck_1.f90).

It should be the default, and it used to be. Fortran doesn’t care about math 
routines setting errno (its existence is specified in C & C++ standards, but 
not in the Fortran standard). If I understand correctly, Joost’s patch just 
adapts this to a new flag handling mechanism.

FX

Re: [PATCH, Fortran] PR61234: -Wuse-no-only

2014-06-02 Thread FX
> I think it is really weird if a coding style warning is included in -Wall.

Same here. It’s not a very commonly shared coding style, so I don’t think it 
should be included in -Wall.
Other than that, I like the idea (but cannot review the patch).

FX

Re: [C++ PATCH] c++/PR 59483, c++/PR 61148

2014-06-02 Thread Jason Merrill

On 06/02/2014 03:56 PM, Jason Merrill wrote:

OK with that change.


...but since you don't have write access, I'll just make the change.

Jason




Re: [C++ PATCH] c++/PR 59483, c++/PR 61148

2014-06-02 Thread Jason Merrill

On 06/02/2014 03:01 PM, Ville Voutilainen wrote:

+  if (current_nonlambda_class_type ())
protected_ok = protected_accessible_p (decl,
-  current_class_type, binfo);
+  current_nonlambda_class_type (),


Let's store the value of current_nonlambda_class_type() in a local 
variable rather than call it twice.



+ && DERIVED_FROM_P (scope, current_nonlambda_class_type ()))
+   qualifying_type = current_nonlambda_class_type ();


Here too.

OK with that change.

Jason



RFA: Make LRA temporarily eliminate addresses before testing constraints

2014-06-02 Thread Richard Sandiford
Ping.  Imagination's copyright assignment has now gone through and so
in principle we're ready for the MIPS LRA switch to go in.  We need
this LRA patch as a prequisite though.

Robert: you also had an LRA change, but is it still needed after this one?
If so, could you repost it and explain the case it handles?

Thanks,
Richard

Richard Sandiford  writes:
> Richard Sandiford  writes:
>> I think a cleaner way of doing it would be to have helper functions
>> that switch in and out of the eliminated form, storing the old form
>> in fields of a new structure (either separate from address_info,
>> or a local inheritance of it).  We probably also want to have arrays
>> of address_infos, one for each operand, so that we don't analyse the
>> same address too many times during the same insn.
>
> In the end maintaining the array of address_infos seemed like too much
> work.  It was hard to keep it up-to-date with various other changes
> that can be made, including swapping commutative operands, to the point
> where it wasn't obvious whether it was really an optimisation or not.
>
> Here's a patch that does the first.  Tested on x86_64-linux-gnu.
> This time I also compared the assembly output for gcc.dg, g++.dg
> and gcc.c-torture at -O2 on:
>
>   arch64-linux-gnu arm-eabi mipsisa64-sde-elf s390x-linux-gnu
>   powerpc64-linux-gnu x86_64-linux-gnu
>
> s390x in particular is very good at exposing problems with this code.
> (It caught bugs in the aborted attempt to keep an array of address_infos.)
>
> OK to install?
>
> Thanks,
> Richard
>
>
> gcc/
>   * lra-constraints.c (valid_address_p): Move earlier in file.
>   (address_eliminator): New structure.
>   (satisfies_memory_constraint_p): New function.
>   (satisfies_address_constraint_p): Likewise.
>   (process_alt_operands, process_address, curr_insn_transform): Use them.
>
> Index: gcc/lra-constraints.c
> ===
> --- gcc/lra-constraints.c 2014-05-17 17:49:19.071639652 +0100
> +++ gcc/lra-constraints.c 2014-05-18 20:36:17.499181467 +0100
> @@ -317,6 +317,118 @@ in_mem_p (int regno)
>return get_reg_class (regno) == NO_REGS;
>  }
>  
> +/* Return 1 if ADDR is a valid memory address for mode MODE in address
> +   space AS, and check that each pseudo has the proper kind of hard
> +   reg.   */
> +static int
> +valid_address_p (enum machine_mode mode ATTRIBUTE_UNUSED,
> +  rtx addr, addr_space_t as)
> +{
> +#ifdef GO_IF_LEGITIMATE_ADDRESS
> +  lra_assert (ADDR_SPACE_GENERIC_P (as));
> +  GO_IF_LEGITIMATE_ADDRESS (mode, addr, win);
> +  return 0;
> +
> + win:
> +  return 1;
> +#else
> +  return targetm.addr_space.legitimate_address_p (mode, addr, 0, as);
> +#endif
> +}
> +
> +namespace {
> +  /* Temporarily eliminates registers in an address (for the lifetime of
> + the object).  */
> +  class address_eliminator {
> +  public:
> +address_eliminator (struct address_info *ad);
> +~address_eliminator ();
> +
> +  private:
> +struct address_info *m_ad;
> +rtx *m_base_loc;
> +rtx m_base_reg;
> +rtx *m_index_loc;
> +rtx m_index_reg;
> +  };
> +}
> +
> +address_eliminator::address_eliminator (struct address_info *ad)
> +  : m_ad (ad),
> +m_base_loc (strip_subreg (ad->base_term)),
> +m_base_reg (NULL_RTX),
> +m_index_loc (strip_subreg (ad->index_term)),
> +m_index_reg (NULL_RTX)
> +{
> +  if (m_base_loc != NULL)
> +{
> +  m_base_reg = *m_base_loc;
> +  lra_eliminate_reg_if_possible (m_base_loc);
> +  if (m_ad->base_term2 != NULL)
> + *m_ad->base_term2 = *m_ad->base_term;
> +}
> +  if (m_index_loc != NULL)
> +{
> +  m_index_reg = *m_index_loc;
> +  lra_eliminate_reg_if_possible (m_index_loc);
> +}
> +}
> +
> +address_eliminator::~address_eliminator ()
> +{
> +  if (m_base_loc && *m_base_loc != m_base_reg)
> +{
> +  *m_base_loc = m_base_reg;
> +  if (m_ad->base_term2 != NULL)
> + *m_ad->base_term2 = *m_ad->base_term;
> +}
> +  if (m_index_loc && *m_index_loc != m_index_reg)
> +*m_index_loc = m_index_reg;
> +}
> +
> +/* Return true if the eliminated form of AD is a legitimate target address.  
> */
> +static bool
> +valid_address_p (struct address_info *ad)
> +{
> +  address_eliminator eliminator (ad);
> +  return valid_address_p (ad->mode, *ad->outer, ad->as);
> +}
> +
> +#ifdef EXTRA_CONSTRAINT_STR
> +/* Return true if the eliminated form of memory reference OP satisfies
> +   extra address constraint CONSTRAINT.  */
> +static bool
> +satisfies_memory_constraint_p (rtx op, const char *constraint)
> +{
> +  struct address_info ad;
> +
> +  decompose_mem_address (&ad, op);
> +  address_eliminator eliminator (&ad);
> +  return EXTRA_CONSTRAINT_STR (op, *constraint, constraint);
> +}
> +
> +/* Return true if the eliminated form of address AD satisfies extra
> +   address constraint CONSTRAINT.  */
> +static bool
> +satisfies_address_constraint_p (struct address_info *

Re: [patch 1/N] std::regex refactoring - _BracketMatcher

2014-06-02 Thread Jonathan Wakely

I'm committing the attached patch, combining the various patches we
discussed in April.

Tested x86_64-linux, committed to trunk.

commit f8e0936df9cdc31460bb79ac82f43486967983b1
Author: Jonathan Wakely 
Date:   Tue Apr 8 16:24:56 2014 +0100

	* include/bits/regex_compiler.h (__detail::_BracketMatcher): Reorder
	members to avoid wasted space when not using a cache.
	(__detail::_BracketMatcher::_M_ready()): Sort and deduplicate set.
	* include/bits/regex_compiler.tcc
	(__detail::_BracketMatcher::_M_apply(_CharT, false_type)): Use binary
	search on set.
	* include/bits/regex_executor.h (__detail::_Executor::_Match_mode):
	New enumeration type to indicate match mode.
	(__detail::_Executor::_State_info): New type holding members only
	needed in BFS-mode. Replace unique_ptr> with
	unique_ptr.
	(__detail::_Executor::_M_rep_once_more, __detail::_Executor::_M_dfs):
	Replace template parameter with run-time function parameter.
	(__detail::_Executor::_M_main): Likewise. Dispatch to ...
	(__detail::_Executor::_M_main_dispatch): New overloaded functions to
	implement DFS and BFS mode.
	* include/bits/regex_executor.tcc (__detail::_Executor::_M_main):
	Split implementation into ...
	(__detail::_Executor::_M_main_dispatch): New overloaded functions.
	(__detail::_Executor::_M_lookahead): Create nested executor on stack.
	(__detail::_Executor::_M_rep_once_more): Pass match mode as function
	argument instead of template argument.
	(__detail::_Executor::_M_dfs): Likewise.
	* include/bits/regex_scanner.tcc: Fix typos in comments.
	* testsuite/performance/28_regex/range.cc: New.

diff --git a/libstdc++-v3/include/bits/regex.tcc b/libstdc++-v3/include/bits/regex.tcc
index 0d737a0..a81f517 100644
--- a/libstdc++-v3/include/bits/regex.tcc
+++ b/libstdc++-v3/include/bits/regex.tcc
@@ -32,7 +32,7 @@
 // If _GLIBCXX_REGEX_USE_THOMPSON_NFA is defined, the thompson NFA
 // algorithm will be used. This algorithm is not enabled by default,
 // and cannot be used if the regex contains back-references, but has better
-// (polynomial instead of exponential) worst case performace.
+// (polynomial instead of exponential) worst case performance.
 // See __regex_algo_impl below.
 
 namespace std _GLIBCXX_VISIBILITY(default)
diff --git a/libstdc++-v3/include/bits/regex_compiler.h b/libstdc++-v3/include/bits/regex_compiler.h
index 52f7235..ca116de 100644
--- a/libstdc++-v3/include/bits/regex_compiler.h
+++ b/libstdc++-v3/include/bits/regex_compiler.h
@@ -43,7 +43,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 struct _BracketMatcher;
 
   /**
-   * @brief Builds an NFA from an input iterator interval.
+   * @brief Builds an NFA from an input iterator range.
*
* The %_TraitsT type should fulfill requirements [28.3].
*/
@@ -329,7 +329,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   operator()(_CharT __ch) const
   {
 	_GLIBCXX_DEBUG_ASSERT(_M_is_ready);
-	return _M_apply(__ch, _IsChar());
+	return _M_apply(__ch, _UseCache());
   }
 
   void
@@ -400,21 +400,28 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   void
   _M_ready()
   {
-	_M_make_cache(_IsChar());
+	std::sort(_M_char_set.begin(), _M_char_set.end());
+	auto __end = std::unique(_M_char_set.begin(), _M_char_set.end());
+	_M_char_set.erase(__end, _M_char_set.end());
+	_M_make_cache(_UseCache());
 #ifdef _GLIBCXX_DEBUG
 	_M_is_ready = true;
 #endif
   }
 
 private:
-  typedef typename is_same<_CharT, char>::type _IsChar;
+  // Currently we only use the cache for char
+  typedef typename std::is_same<_CharT, char>::type _UseCache;
+
+  static constexpr size_t
+  _S_cache_size() { return 1ul << (sizeof(_CharT) * __CHAR_BIT__); }
+
   struct _Dummy { };
-  typedef typename conditional<_IsChar::value,
-   std::bitset<1 << (8 * sizeof(_CharT))>,
-   _Dummy>::type _CacheT;
-  typedef typename make_unsigned<_CharT>::type _UnsignedCharT;
+  typedef typename std::conditional<_UseCache::value,
+	std::bitset<_S_cache_size()>,
+	_Dummy>::type _CacheT;
+  typedef typename std::make_unsigned<_CharT>::type _UnsignedCharT;
 
-private:
   bool
   _M_apply(_CharT __ch, false_type) const;
 
@@ -425,9 +432,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   void
   _M_make_cache(true_type)
   {
-	for (size_t __i = 0; __i < _M_cache.size(); __i++)
-	  _M_cache[static_cast<_UnsignedCharT>(__i)] =
-	_M_apply(__i, false_type());
+	for (unsigned __i = 0; __i < _M_cache.size(); __i++)
+	  _M_cache[__i] = _M_apply(static_cast<_CharT>(__i), false_type());
   }
 
   void
@@ -435,7 +441,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   { }
 
 private:
-  _CacheT   _M_cache;
   std::vector<_CharT>   _M_char_set;
   std::vector<_StringT> _M_equiv_set;
   std::vector> _M_range_set;
@@ -444,6 +449,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION

Re: RFA: Remove support for old-style constraint macros

2014-06-02 Thread Jeff Law

On 06/02/14 13:12, Richard Sandiford wrote:

All ports have moved over to define*_constraints so we can finally get rid
of the old constraints support.  In the case of FR-V I did that by removing
a large quote from the old documentation; that sort of thing tends to get
out of date.

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

If so, it seems we've acheived a full transition. :-)

Umm, isn't that a sign the world is coming to an end shortly? :-)



Thanks,
Richard


gcc/
* defaults.h (USE_MD_CONSTRAINTS, EXTRA_MEMORY_CONSTRAINT)
(EXTRA_ADDRESS_CONSTRAINT, DEFAULT_CONSTRAINT_LEN, CONSTRAINT_LEN)
(CONST_OK_FOR_CONSTRAINT_P, CONST_DOUBLE_OK_FOR_LETTER_P)
(REG_CLASS_FROM_CONSTRAINT, EXTRA_CONSTRAINT_STR): Delete definitions
in this file.
(REG_CLASS_FROM_LETTER, CONST_OK_FOR_LETTER_P)
(CONST_DOUBLE_OK_FOR_LETTER_P, EXTRA_CONSTRAINT): Move poising to...
* system.h: ...here and make it unconditional.
* target.def (conditional_register_usage): Mention
define_register_constraint instead of old-style constraint macros.
* doc/tm.texi.in: Remove documentation for old-style constraint macros.
* doc/tm.texi: Regenerate.
* genoutput.c: Remove USE_MD_CONSTRAINTS conditions and all code
protected by !USE_MD_CONSTRAINTS.
* config/frv/frv.md: Remove quote from old version of documentation.
* config/frv/frv.c (frv_conditional_register_usage): Likewise.
* config/m32r/m32r.c (easy_di_const, easy_df_const): Avoid mentioning
CONST_DOUBLE_OK_FOR_LETTER.
* config/sh/constraints.md: Likewise EXTRA_CONSTRAINT.

OK.

jeff



[rtl-optimization/61094] Do not re-extend in ree.c if a copy was needed

2014-06-02 Thread Jeff Law


As discussed in the PR, we have an extension we want to eliminate and 
doing so requires a copy.


We later find another extension we want to eliminate and doing so would 
require widening the copy, which may not result in a valid insn.


This patch does two things.

First, when we want to eliminate an extension and a copy is needed, we 
generate the copy, verify its a single insn, recognize it and verify it 
matches its constraints.  If any of those fail, then we can not 
eliminate the extension.


Second, when we eliminate an extension using a copy, we mark it as 
do_not_reextend, which avoids the problems noted above.  Note this is 
only done when we have an extension that is eliminated and a copy was 
needed to do so.


While this potentially disables an optimization, these situations are 
exceedingly rare.  Obviously if someone finds code that suffers as a 
result, we'll have to go with a more complex solution.


Bootstrapped and regression tested on x86_64-unknown-linux-gnu. 
Installed on the trunk.


commit 13d0ab22e1eb98e20f63bb33ca33f2b1599b1598
Author: law 
Date:   Mon Jun 2 19:12:08 2014 +

PR rtl-optimization/61094
* ree.c (combine_reaching_defs): Do not reextend an insn if it
was marked as do_no_reextend.  If a copy is needed to eliminate
an extension, then mark it as do_not_reextend.

PR rtl-optimization/61094
* g++.dg/pr61094: New test.

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

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index cffab0b..acefcc0 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2014-06-02  Jeff Law  
+
+   PR rtl-optimization/61094
+   * ree.c (combine_reaching_defs): Do not reextend an insn if it
+   was marked as do_no_reextend.  If a copy is needed to eliminate
+   an extension, then mark it as do_not_reextend.
+
 2014-06-02  Marcus Shawcroft  
 
* config/aarch64/aarch64.md (set_fpcr): Drop ISB after FPCR write.
diff --git a/gcc/ree.c b/gcc/ree.c
index 77f1384..ade413e 100644
--- a/gcc/ree.c
+++ b/gcc/ree.c
@@ -507,6 +507,8 @@ struct ATTRIBUTE_PACKED ext_modified
   /* Kind of modification of the insn.  */
   ENUM_BITFIELD(ext_modified_kind) kind : 2;
 
+  unsigned int do_not_reextend : 1;
+
   /* True if the insn is scheduled to be deleted.  */
   unsigned int deleted : 1;
 };
@@ -712,8 +714,10 @@ combine_reaching_defs (ext_cand *cand, const_rtx set_pat, 
ext_state *state)
  register than the source operand, then additional restrictions
  are needed.  Note we have to handle cases where we have nested
  extensions in the source operand.  */
-  if (REGNO (SET_DEST (PATTERN (cand->insn)))
-  != REGNO (get_extended_src_reg (SET_SRC (PATTERN (cand->insn)
+  bool copy_needed
+= (REGNO (SET_DEST (PATTERN (cand->insn)))
+   != REGNO (get_extended_src_reg (SET_SRC (PATTERN (cand->insn);
+  if (copy_needed)
 {
   /* In theory we could handle more than one reaching def, it
 just makes the code to update the insn stream more complex.  */
@@ -722,7 +726,7 @@ combine_reaching_defs (ext_cand *cand, const_rtx set_pat, 
ext_state *state)
 
   /* We require the candidate not already be modified.  It may,
 for example have been changed from a (sign_extend (reg))
-into (zero_extend (sign_extend (reg)).
+into (zero_extend (sign_extend (reg))).
 
 Handling that case shouldn't be terribly difficult, but the code
 here and the code to emit copies would need auditing.  Until
@@ -777,6 +781,31 @@ combine_reaching_defs (ext_cand *cand, const_rtx set_pat, 
ext_state *state)
  || reg_set_between_p (SET_DEST (PATTERN (cand->insn)),
def_insn, cand->insn))
return false;
+
+  /* We must be able to copy between the two registers.   Generate,
+recognize and verify constraints of the copy.  Also fail if this
+generated more than one insn.
+
+ This generates garbage since we throw away the insn when we're
+done, only to recreate it later if this test was successful.  */
+  start_sequence ();
+  rtx sub_rtx = *get_sub_rtx (def_insn);
+  rtx pat = PATTERN (cand->insn);
+  rtx new_dst = gen_rtx_REG (GET_MODE (SET_DEST (sub_rtx)),
+ REGNO (XEXP (SET_SRC (pat), 0)));
+  rtx new_src = gen_rtx_REG (GET_MODE (SET_DEST (sub_rtx)),
+ REGNO (SET_DEST (pat)));
+  emit_move_insn (new_dst, new_src);
+
+  rtx insn = get_insns();
+  end_sequence ();
+  if (NEXT_INSN (insn))
+   return false;
+  if (recog_memoized (insn) == -1)
+   return false;
+  extract_insn (insn);
+  if (!constrain_operands (1))
+   return false;
 }
 
 
@@ -843,11 +872,15 @@ combine_reaching_defs (ext_cand *cand, const_rtx set_pat, 
ext_state *state)
 fprintf (dump_file, "All merges were su

RFA: Remove "m" column from backends.html

2014-06-02 Thread Richard Sandiford
As per the patch I just posted, all ports have moved over to the new
way of defining constraints.  This patch removes the associated "m"
column from backends.html.  (Note that the ports still listed with "m"
have in fact been converted.)

OK to install?

Thanks,
Richard


Index: htdocs/backends.html
===
RCS file: /cvs/gcc/wwwdocs/htdocs/backends.html,v
retrieving revision 1.49
diff -u -r1.49 backends.html
--- htdocs/backends.html9 May 2014 16:26:37 -   1.49
+++ htdocs/backends.html2 Jun 2014 19:10:15 -
@@ -50,7 +50,6 @@
 p   Port does not use define_peephole.
 f   Port does not define prologue and/or epilogue RTL expanders.
 g   Port does not define TARGET_ASM_FUNCTION_(PRO|EPI)LOGUE.
-m   Port does not use define_constants.
 b   Port does not use '"* ..."' notation for output template code.
 d   Port uses DFA scheduler descriptions.
 a   Port generates multiple inheritance thunks using
@@ -64,50 +63,50 @@
 
 
  | Characteristics
-Target   | HMSLQNFICBD lqrcpfgmbdates
+Target   | HMSLQNFICBD lqrcpfgbdates
 -+---
-aarch64  | Qq  p g  da  s
-alpha|  ?? Q   Cq  p g bda e 
-arm  |  da  s
-avr  |L  FIl  c  g b
-bfin |   F p g  da
-c4x  |  ??  N I BD   g  d  e 
-c6x  |   S CB  p g bda 
-cr16 |L  F C g  s
-cris |   F  B cp g b a  s
-epiphany | C   p g bda  s
-fr30 | ??FI Bgm s
-frv  | ??   B  pda  s
-h8300|   FI   cp g  s
-i386 |   ? Qq  pda   
-ia64 |   ? Q   Cqr pda   
-iq2000   | ???   FICB  p g  d t  
-m32c |L  FIl   p g  s
-m32r |   FI d   s
-m68hc11  |L  FIl  c s
-m68k |   ?c  a   
-mcore|  ?FI  gm d   s
-mep  |   F C   p g  d t s
-microblaze CB  bd   s
-mips | Q   CB   qr p   bda  s
-mmix | HM  Q   Cq  p   b a e 
-mn10300  | ?? c  g  s
-ms1  |   S   F  B  p g bd
-msp430   |L  FIl   p g  s
-nds32|   F C   pda  s
-pa   |   ? Q   CBD  qrm da e 
-pdp11|L   ICqrcp   e 
-rs6000   | Q   Cqr  da   
-s390 |   ? Qqr p g bda e 
-sh   | Q   CB   qr bda   
-sparc| Q   CB   qr pda   
-spu  |   ? Q  *C   p g bd
-stormy16 | ???L  FIC D l   p  m  a
-tilegx   |   S Q   Cq  p g bda e
-tilepro  |   S   F C   p g bda e
-v850 | ??FI   cp gm d   s
-vax  |  M?I   cp a e 
-xtensa   |   ? C   p   bd
+aarch64  | Qq  p g da  s
+alpha|  ?? Q   Cq  p gbda e 
+arm  | da  s
+avr  |L  FIl  c  gb
+bfin |   F p g da
+c4x  |  ??  N I BD   g d  e 
+c6x  |   S CB  p gbda 
+cr16 |L  F C g s
+cris |   F  B cp gb a  s
+epiphany | C   p gbda  s
+fr30 | ??FI Bg s
+frv  | ??   B  p   da  s
+h8300|   FI   cp g s
+i386 |   ? Qq  p   da   
+ia64 |   ? Q   Cqr p   da   
+iq2000   | ???   FICB  p g d t  
+m32c |L  FIl   p g s
+m32r |   FId   s
+m68hc11  |L  FIl  cs
+m68k |   ?c a   
+mcore|  ?FI  g d   s
+mep  |   F C   p g d t s
+microblaze CB bd   s
+mips | Q   CB   qr p  bda  s
+mmix | HM  Q   Cq  p  b a e 
+mn10300  | ?? c  g s
+ms1  |   S   F  B  p gbd
+msp430   |L  FIl   p g s
+nds32|   F C   p   da  s
+pa   |   ? Q   CBD  qr da e 
+pdp11|L   ICqrcp  e 
+rs6000   | Q   Cqr da   
+s390 |   ? Qqr p gbda e 
+sh   | Q   CB   qrbda   
+sparc| Q   CB   qr p   da   
+spu  |   ? Q  *C   p gbd
+stormy16 | ???L  FIC D l   pa
+tilegx   |   S Q   Cq  p gbda e
+tilepro  |   S   F C   p gbda e
+v850 | ??FI   cp g d   s
+vax  |  M?I   cpa e 
+xtensa   |   ? C   p  bd
 
 
 For AVR simulator, see 

RFA: Remove support for old-style constraint macros

2014-06-02 Thread Richard Sandiford
All ports have moved over to define*_constraints so we can finally get rid
of the old constraints support.  In the case of FR-V I did that by removing
a large quote from the old documentation; that sort of thing tends to get
out of date.

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

If so, it seems we've acheived a full transition. :-)

Thanks,
Richard


gcc/
* defaults.h (USE_MD_CONSTRAINTS, EXTRA_MEMORY_CONSTRAINT)
(EXTRA_ADDRESS_CONSTRAINT, DEFAULT_CONSTRAINT_LEN, CONSTRAINT_LEN)
(CONST_OK_FOR_CONSTRAINT_P, CONST_DOUBLE_OK_FOR_LETTER_P)
(REG_CLASS_FROM_CONSTRAINT, EXTRA_CONSTRAINT_STR): Delete definitions
in this file.
(REG_CLASS_FROM_LETTER, CONST_OK_FOR_LETTER_P)
(CONST_DOUBLE_OK_FOR_LETTER_P, EXTRA_CONSTRAINT): Move poising to...
* system.h: ...here and make it unconditional.
* target.def (conditional_register_usage): Mention
define_register_constraint instead of old-style constraint macros.
* doc/tm.texi.in: Remove documentation for old-style constraint macros.
* doc/tm.texi: Regenerate.
* genoutput.c: Remove USE_MD_CONSTRAINTS conditions and all code
protected by !USE_MD_CONSTRAINTS.
* config/frv/frv.md: Remove quote from old version of documentation.
* config/frv/frv.c (frv_conditional_register_usage): Likewise.
* config/m32r/m32r.c (easy_di_const, easy_df_const): Avoid mentioning
CONST_DOUBLE_OK_FOR_LETTER.
* config/sh/constraints.md: Likewise EXTRA_CONSTRAINT.

Index: gcc/defaults.h
===
--- gcc/defaults.h  2014-06-02 19:57:03.814627133 +0100
+++ gcc/defaults.h  2014-06-02 19:57:07.688661350 +0100
@@ -976,74 +976,11 @@ #define HAS_LONG_UNCOND_BRANCH 0
 #define DEFAULT_USE_CXA_ATEXIT 0
 #endif
 
-/* If none of these macros are defined, the port must use the new
-   technique of defining constraints in the machine description.
-   tm_p.h will define those macros that machine-independent code
-   still uses.  */
-#if  !defined CONSTRAINT_LEN   \
-  && !defined REG_CLASS_FROM_LETTER\
-  && !defined REG_CLASS_FROM_CONSTRAINT\
-  && !defined CONST_OK_FOR_LETTER_P\
-  && !defined CONST_OK_FOR_CONSTRAINT_P\
-  && !defined CONST_DOUBLE_OK_FOR_LETTER_P \
-  && !defined CONST_DOUBLE_OK_FOR_CONSTRAINT_P  \
-  && !defined EXTRA_CONSTRAINT \
-  && !defined EXTRA_CONSTRAINT_STR \
-  && !defined EXTRA_MEMORY_CONSTRAINT  \
-  && !defined EXTRA_ADDRESS_CONSTRAINT
-
-#define USE_MD_CONSTRAINTS
-
 #if GCC_VERSION >= 3000 && defined IN_GCC
 /* These old constraint macros shouldn't appear anywhere in a
configuration using MD constraint definitions.  */
-#pragma GCC poison REG_CLASS_FROM_LETTER CONST_OK_FOR_LETTER_P \
-   CONST_DOUBLE_OK_FOR_LETTER_P EXTRA_CONSTRAINT
-#endif
-
-#else /* old constraint mechanism in use */
-
-/* Determine whether extra constraint letter should be handled
-   via address reload (like 'o').  */
-#ifndef EXTRA_MEMORY_CONSTRAINT
-#define EXTRA_MEMORY_CONSTRAINT(C,STR) 0
-#endif
-
-/* Determine whether extra constraint letter should be handled
-   as an address (like 'p').  */
-#ifndef EXTRA_ADDRESS_CONSTRAINT
-#define EXTRA_ADDRESS_CONSTRAINT(C,STR) 0
-#endif
-
-/* When a port defines CONSTRAINT_LEN, it should use DEFAULT_CONSTRAINT_LEN
-   for all the characters that it does not want to change, so things like the
-  'length' of a digit in a matching constraint is an implementation detail,
-   and not part of the interface.  */
-#define DEFAULT_CONSTRAINT_LEN(C,STR) 1
-
-#ifndef CONSTRAINT_LEN
-#define CONSTRAINT_LEN(C,STR) DEFAULT_CONSTRAINT_LEN (C, STR)
 #endif
 
-#if defined (CONST_OK_FOR_LETTER_P) && ! defined (CONST_OK_FOR_CONSTRAINT_P)
-#define CONST_OK_FOR_CONSTRAINT_P(VAL,C,STR) CONST_OK_FOR_LETTER_P (VAL, C)
-#endif
-
-#if defined (CONST_DOUBLE_OK_FOR_LETTER_P) && ! defined 
(CONST_DOUBLE_OK_FOR_CONSTRAINT_P)
-#define CONST_DOUBLE_OK_FOR_CONSTRAINT_P(OP,C,STR) \
-  CONST_DOUBLE_OK_FOR_LETTER_P (OP, C)
-#endif
-
-#ifndef REG_CLASS_FROM_CONSTRAINT
-#define REG_CLASS_FROM_CONSTRAINT(C,STR) REG_CLASS_FROM_LETTER (C)
-#endif
-
-#if defined (EXTRA_CONSTRAINT) && ! defined (EXTRA_CONSTRAINT_STR)
-#define EXTRA_CONSTRAINT_STR(OP, C,STR) EXTRA_CONSTRAINT (OP, C)
-#endif
-
-#endif /* old constraint mechanism in use */
-
 /* Determin whether the target runtime library is Bionic */
 #ifndef TARGET_HAS_BIONIC
 #define TARGET_HAS_BIONIC 0
Index: gcc/system.h
===
--- gcc/system.h2014-06-02 19:57:03.814627133 +0100
+++ gcc/system.h2014-06-02 19:57:07.689661359 +0100
@@ -928,7 +928,9 @@ #define realloc xrealloc
USE_COMMON_FOR_ONE_ONLY IFCVT_EXTRA_FIELDS IFCVT_INIT_EXTRA_FIELDS \
CASE_USE_BIT_TESTS FIXUNS_TRUNC_LIKE_FIX_TRUNC \
 

Re: [PATCH][match-and-simplify]

2014-06-02 Thread Marc Glisse



   (plus (bit_not @0) @0)
   if (INTEGRAL_TYPE_P (TREE_TYPE (@0)))
   { build_int_cst (TREE_TYPE (@0), -1); })
+(match_and_simplify
+  (plus @0 (bit_not @0))
+  if (INTEGRAL_TYPE_P (TREE_TYPE (@0)))
+  { build_int_cst (TREE_TYPE (@0), -1); })


Why not just:

(match_and_simplify
  (plus @0 (bit_not @0))
  { build_all_ones_cst (TREE_TYPE (@0)); })

? Works for vector/complex, I don't know what type a bit_not_expr can have 
where the simplification wouldn't be true.


--
Marc Glisse


[C++ PATCH] c++/PR 59483, c++/PR 61148

2014-06-02 Thread Ville Voutilainen
Tested on Linux X86-64. Note that I have not bootstrapped this patch.
diff --git a/gcc/cp/search.c b/gcc/cp/search.c
index c3eed90..6907533 100644
--- a/gcc/cp/search.c
+++ b/gcc/cp/search.c
@@ -917,9 +917,10 @@ accessible_p (tree type, tree decl, bool consider_local_p)
   /* Figure out where the reference is occurring.  Check to see if
 DECL is private or protected in this scope, since that will
 determine whether protected access is allowed.  */
-  if (current_class_type)
+  if (current_nonlambda_class_type ())
protected_ok = protected_accessible_p (decl,
-  current_class_type, binfo);
+  current_nonlambda_class_type (),
+  binfo);
 
   /* Now, loop through the classes of which we are a friend.  */
   if (!protected_ok)
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 7e144a6..06acd4e 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -1837,8 +1837,8 @@ check_accessibility_of_qualified_id (tree decl,
 `this'.  */
   if (DECL_NONSTATIC_MEMBER_P (decl)
  && current_class_ptr
- && DERIVED_FROM_P (scope, current_class_type))
-   qualifying_type = current_class_type;
+ && DERIVED_FROM_P (scope, current_nonlambda_class_type ()))
+   qualifying_type = current_nonlambda_class_type ();
   /* Otherwise, use the type indicated by the
 nested-name-specifier.  */
   else
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-59483.C 
b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-59483.C
new file mode 100644
index 000..fa79df9
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-59483.C
@@ -0,0 +1,31 @@
+// PR c++/59483
+// { dg-do compile { target c++11 } }
+
+struct X 
+{ 
+protected: 
+  int i; 
+};  
+
+struct Y : X 
+{ 
+  Y() 
+  { 
+[&]{ X::i = 3; }(); 
+  }
+};
+
+template 
+struct Y2 : T
+{
+  Y2() 
+  { 
+[&]{ T::i = 3; }(); 
+  }
+};
+
+int main()
+{
+  Y y;
+  Y2 y2;
+}
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-61148.C 
b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-61148.C
new file mode 100644
index 000..32bb734
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-61148.C
@@ -0,0 +1,33 @@
+// PR c++/61148
+// { dg-do compile { target c++11 } }
+
+class DB 
+{
+protected:
+  void foo() {};
+};
+
+class DC : public DB 
+{
+public:
+  DC() 
+  {
+[this]() {DB::foo();}();
+  };
+};
+
+template 
+class DC2 : public T
+{
+public:
+  DC2() 
+  {
+[this]() {T::foo();}();
+  };
+};
+
+int main(void)
+{
+  DC x;
+  DC2 x2;
+}


pr59483_pr61148.changelog
Description: Binary data


Re: Eliminate write-only variables

2014-06-02 Thread Jan Hubicka
> 
> Yeah, I discussed this with martin today on irc.  For aliasing we'd like to 
> know whether a decl possibly has its address taken. Currently we only trust 
> TREE_ADDRESSABLE for statics - and lto might change those to hidden 
> visibility public :(
> 
> So we want deck_referred_to_by_single_function 

OK, I will implement this one in IPA mini-pass.  It is easy.
This property changes by clonning and inlining. What Martin wants to use it for?
(I.e. my plan would be to compute it as last IPA pass making it useless for
IPA analysis&propagation)

> and deck_may_have_address_taken.

We currently clear TREE_ADDRESSABLE for statics that have no address taken at
WPA time and that ought to keep the flag cleared at ltrans (I think I even made
testcase for this)

What I think we could improve is to not consider string functions as ADDR 
operations
for this analysis, i.e. it is common to only memset to 0.

How may_have_address_taken would differ here?

Honza


Re: Eliminate write-only variables

2014-06-02 Thread Richard Biener
On June 2, 2014 5:44:13 PM CEST, Jan Hubicka  wrote:
>> 
>> Well, I'm hesitant to add a new pass just to optimize a (irrelevant
>in practice)
>> benchmark.  I'm ok with strengthening existing infrastructure or
>enhancing
>> existing passes.
>> 
>> The issue with these mini-passes is that they are very placement
>sensitive
>> and you don't easily get secondary effects.  See the comment (and
>> "patch") about DCE - the ??? comment can be addressed the same
>> way Bernd addressed it (use cgraph_function_possibly_inlined_p).
>> Would that optimize the testcase?
>> 
>> Note that the issue with nested function use prevails (not sure how
>to
>> solve that - same issue in Bernds patch).
>
>I think this part of the patch can be made much cleaner by simply
>adding flag
>"used by one function only" to variables.  We can compute it at the end
>of IPA
>queue and remove the code playing with local statics, nested functions
>and inlines.
>
>I can easily implement this analysis - perhaps it would be useful for
>AA or
>something else, too?

Yeah, I discussed this with martin today on irc.  For aliasing we'd like to 
know whether a decl possibly has its address taken. Currently we only trust 
TREE_ADDRESSABLE for statics - and lto might change those to hidden visibility 
public :(

So we want deck_referred_to_by_single_function and deck_may_have_address_taken.

Richard.

>Honza
>> 
>> Thanks,
>> Richard.
>> 
>> > -Sandra
>> >




Re: Patch for builtins.h restructuring [1/2]

2014-06-02 Thread Andrew MacLeod

On 06/02/2014 01:30 PM, Jeff Law wrote:




* Finally, fortran/trans.c was calling fold_builtin_call_array directly.
That means it would have needed builtins.h which caused issues since
builtins.h defines struct target_builtins and uses
FIRST_PSEUDO_REGISTER... which is defined within the target config
file... something I dont think we really want to expose to the fortran
front end :-P.  Anyway, looking aorund, it turns out
fold-const.c::fold_build_call_array_loc is really a wrapper for a call
to fold_builtin_call_array, with some extra checking code before and
after the call protected by ENABLE_FOLD_CHECKING.  I'd think that should
be OK since its what other front ends call...

Ick.  Yea, it'd be good if FIRST_PSEUDO_REGISTER doesn't bleed all the 
way into the front-ends.


I in fact tried to remove that from builtins.h since the structure is 
only used in builtins.[ch] and target-globals.[ch], but it was not 
easily possible.. target-globals.c has a struct target_globals_extra 
which uses a copy of struct target_builtins, along with half a dozen 
others, and thus needs to see the declaration.  All the other references 
simply use a pointer to the structure.


maybe at some point we could hide that with something more generic for 
all those structs.. All we likely need is to export a few routines like 
target_builtins_alloc () and target_builtins_copy (p)...  and maybe a 
target_builtins_free ()... for each kind of structure...  I wasnt about 
to do anything like that when it turned out to be something simpler 
available.


Andrew


Re: [PATCH] rebuild frequency after vrp

2014-06-02 Thread Teresa Johnson
On Mon, Jun 2, 2014 at 11:04 AM, Teresa Johnson  wrote:
> On Mon, Jun 2, 2014 at 10:26 AM, Dehao Chen  wrote:
>> Just tried with Teresa's patch, the ICE in
>> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61384 is not resolved.
>
> I will take a look to see why this wasn't fixed by my profile redesign.

Turns out this is a case of garbage-in, garbage-out. Jump threading is
producing a block with a frequency >10K, but it is directly due to a
block with an invalid frequency after the upstream ccp2 pass. After
ccp2:

;;   basic block 3, loop depth 1, count 0, freq 9100, maybe hot
;;prev block 2, next block 4, flags: (NEW, REACHABLE)
;;pred:   10 [91.0%]  (TRUE_VALUE,EXECUTABLE)
...
;;succ:   5 [50.0%]  (TRUE_VALUE,EXECUTABLE)
;;4 [50.0%]  (FALSE_VALUE,EXECUTABLE)

;;   basic block 4, loop depth 1, count 0, freq 6825, maybe hot
;;   Invalid sum of incoming frequencies 4550, should be 6825
;;prev block 3, next block 5, flags: (NEW, REACHABLE)
;;pred:   3 [50.0%]  (FALSE_VALUE,EXECUTABLE)
;; , discriminator 4
;;succ:   5 [100.0%]  (FALLTHRU,EXECUTABLE)


Jump threading introduced BB 13, with predecessors 3 and 4 shown above:

;;   basic block 13, loop depth 1, count 0, freq 11375, maybe hot
;;   Invalid sum of outgoing probabilities 40.0%
;;prev block 12, next block 1, flags: (NEW, REACHABLE)
;;pred:   4 [100.0%]  (FALLTHRU,EXECUTABLE)
;;3 [50.0%]  (TRUE_VALUE,EXECUTABLE)

11375 = 9100/2 + 6825

If bb 4 had the correct frequency of 4550 (9100/2), this block would
have gotten the correct count of 9100. BB 13's successor has the
correct frequency of 9100.

Teresa

>
> Teresa
>
>>
>> Dehao
>>
>> On Mon, Jun 2, 2014 at 9:45 AM, Jeff Law  wrote:
>>> On 06/02/14 10:17, Dehao Chen wrote:

 We need to rebuild frequency after vrp, otherwise the following code
 in tree-ssa-threadupdate.c will make the frequency larger than
 upper-bound.

/* Excessive jump threading may make frequencies large enough
 so
   the computation overflows.  */
if (rd->dup_blocks[0]->frequency < BB_FREQ_MAX * 2)
  rd->dup_blocks[0]->frequency += EDGE_FREQUENCY (e);

 This is referring to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61384
>>>
>>> Can you try this with Teresa's revamping of the jump threading frequency
>>> updates?  It's still in my queue of things to review.
>>>
>>> Fixing this stuff in the updater would be better than rebuilding the
>>> frequencies, IMHO.
>>>
>>> Jeff
>>>
>
>
>
> --
> Teresa Johnson | Software Engineer | tejohn...@google.com | 408-460-2413



-- 
Teresa Johnson | Software Engineer | tejohn...@google.com | 408-460-2413


Re: [PATCH] rebuild frequency after vrp

2014-06-02 Thread Jan Hubicka
> We need to rebuild frequency after vrp, otherwise the following code
> in tree-ssa-threadupdate.c will make the frequency larger than
> upper-bound.
> 
>   /* Excessive jump threading may make frequencies large enough so
>  the computation overflows.  */
>   if (rd->dup_blocks[0]->frequency < BB_FREQ_MAX * 2)
> rd->dup_blocks[0]->frequency += EDGE_FREQUENCY (e);
> 
> This is referring to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61384

I see, I still think C++ conversion gives us chance to turn both counts and
frequencies to types that are safe WRT such calculations.  Counts can be either
software floats as discussed or fixed point 64bit type (I think we only need
something like 8-10 bits to get problems Teresa is running into resolved - the
cases where expanding statements gets sub 1 counts that needs to be diferent
from 0) that does caps instead of overflow. Frequencies can be either the same
or 32bit fixed point with capping as we do, sort of, now.

I would really welcome if someone worked on this rather than papering around the
bugs in current hand written fixed point arithmetics. (I am currently occupied
by other projects, so I am not sure I can do it myself really soon)

Honza


Re: [PATCH] rebuild frequency after vrp

2014-06-02 Thread Jeff Law

On 06/02/14 12:07, Jan Hubicka wrote:


It is one of reasions why I think it would be cool to do jump threading in
early opts, too, at least in a lightweidt form.
Conceptually it's pretty easy to do during the into-ssa step.  Not sure 
it it'd catch the cases you care about though.


jeff




Re: [PATCH] rebuild frequency after vrp

2014-06-02 Thread Teresa Johnson
On Mon, Jun 2, 2014 at 10:26 AM, Dehao Chen  wrote:
> Just tried with Teresa's patch, the ICE in
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61384 is not resolved.

I will take a look to see why this wasn't fixed by my profile redesign.

Teresa

>
> Dehao
>
> On Mon, Jun 2, 2014 at 9:45 AM, Jeff Law  wrote:
>> On 06/02/14 10:17, Dehao Chen wrote:
>>>
>>> We need to rebuild frequency after vrp, otherwise the following code
>>> in tree-ssa-threadupdate.c will make the frequency larger than
>>> upper-bound.
>>>
>>>/* Excessive jump threading may make frequencies large enough
>>> so
>>>   the computation overflows.  */
>>>if (rd->dup_blocks[0]->frequency < BB_FREQ_MAX * 2)
>>>  rd->dup_blocks[0]->frequency += EDGE_FREQUENCY (e);
>>>
>>> This is referring to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61384
>>
>> Can you try this with Teresa's revamping of the jump threading frequency
>> updates?  It's still in my queue of things to review.
>>
>> Fixing this stuff in the updater would be better than rebuilding the
>> frequencies, IMHO.
>>
>> Jeff
>>



-- 
Teresa Johnson | Software Engineer | tejohn...@google.com | 408-460-2413


Re: [PATCH] rebuild frequency after vrp

2014-06-02 Thread Jan Hubicka
> On 06/02/14 10:17, Dehao Chen wrote:
> >We need to rebuild frequency after vrp, otherwise the following code
> >in tree-ssa-threadupdate.c will make the frequency larger than
> >upper-bound.
> >
> >   /* Excessive jump threading may make frequencies large enough so
> >  the computation overflows.  */
> >   if (rd->dup_blocks[0]->frequency < BB_FREQ_MAX * 2)
> > rd->dup_blocks[0]->frequency += EDGE_FREQUENCY (e);
> >
> >This is referring to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61384
> Can you try this with Teresa's revamping of the jump threading
> frequency updates?  It's still in my queue of things to review.
> 
> Fixing this stuff in the updater would be better than rebuilding the
> frequencies, IMHO.

Agreed. However one of problems is that the frequencies after VRP may be 
unfixable.
If i.e. you have

if (a)
  prob 20
else
  prob 80
if (a)
  prob 50
else
  prob 50
that can easily happen if the second conditional was more convoluted earlier in
the optimization queue.

We may track when this change and ask for frequency rebuild, but issue is that
I am not completely sure if that is going to give us consistently more reliable
profiles than without: the problem is that branch probabilities themselves may
be misupdated by earlier passes.  It may be interesting to do some analysis how
well estimated profile corelate with measured profile thorough the
optimization.

The problem above would be less troublesome if we jump threaded at least some
cases pre-branch prediction.

It is one of reasions why I think it would be cool to do jump threading in
early opts, too, at least in a lightweidt form. Now when VRP is able to annotate
SSA names, VRP results could feed loop estimation analysis for i.e. get upper
bound on iterations of:

if (a<50)
  for (i=0;i 
> Jeff


Re: [C/C++ PATCH] Add -Wlogical-not-parentheses (PR c/49706)

2014-06-02 Thread Jason Merrill

On 06/02/2014 01:04 PM, Marek Polacek wrote:

#ifdef __cplusplus
template  bool f(T t, U u) { return (!t == u); }
#endif

I think !t should have null TREE_TYPE in this case.


Hmm, I see no crash; the types seem to be
template_type_parm 0x7013d5e8 T type_0 type_6 VOID ...


Right, because you're pulling out the operand of the not.  OK, then you 
need something a little more complicated like !g(t).



Do we actually want to warn in that case?  As the patch doesn't warn
if the type is bool or vector, if somebody instantiates the above with
say T=bool, U=bool, then we'd warn on something that otherwise will not be
warned about when not in template.


I think we still want to warn.  A template that is only correct for one 
possible template argument shouldn't be a template.


Jason



Re: [PATCH 3/4] New attribute lookup function addition

2014-06-02 Thread Jeff Law

On 06/02/14 08:24, Martin Liška wrote:


On 05/30/2014 06:37 PM, Jeff Law wrote:

On 05/30/14 00:49, Martin Liška wrote:

Hi,
this patch introduces a new function lookup_attribute_starting that
can find all attributes starting with a specified string. Purpose of the
function is to be able to identify e.g. if a function has any 'omp'
attribute.

Bootstrapped and tested on x86_64-linux.
OK for trunk?

Thanks,
Martin

2014-05-29  Martin Liska  

 * tree.h (private_lookup_attribute_starting): New function.
 (lookup_attribute_starting): Likewise.
 * tree.c (private_lookup_attribute_starting): Likewise.

private_lookup_attribute_starting needs a block comment.


Added.




+tree
+private_lookup_attribute_starting (const char *attr_name, size_t
attr_len, tree list)

Long line needs to be wrapped?   Please review the patch for lines
that need wrapping at 80 columns.

Fixed too.


So it's really a lookup by prefix, so I'd probably use a name like
lookup_attribute_by_prefix.  Why "private_" in the function name?

I used the same construction as for function 'private_is_attribute_p'; I
hope the construction is fine?

Ah.  OK.




It appears it just returns the first attribute from LIST with the
given prefix.  Presumably you use it iteratively.


+/* Given an attribute name ATTR_NAME and a list of attributes LIST,
+   return a pointer to the attribute's list element if the attribute
+   starts with ATTR_NAME. ATTR_NAME must be in the form 'text' (not
+   '__text__').  */
+
+static inline tree
+lookup_attribute_starting (const char *attr_name, tree list)
+{
+  gcc_checking_assert (attr_name[0] != '_');
+  /* In most cases, list is NULL_TREE.  */
+  if (list == NULL_TREE)
+return NULL_TREE;
+  else
+return private_lookup_attribute_starting (attr_name, strlen
(attr_name), list);
+}

So again, I prefer "prefix" rather than "starting".  Similarly this is
meant to be called iteratively since you only get the first attribute
with the given prefix, right?

I added a comment that it returns just such first argument.

Is the reworked patch OK for trunk?

Yes.  Thanks for the tweaks.

jeff



Re: Patch for builtins.h restructuring [1/2]

2014-06-02 Thread Jeff Law

On 06/02/14 09:26, Andrew MacLeod wrote:

Furthering the include file restructuring, this patch fixes the header
files for builtins.h. The prototypes were spread between tree.h, expr.h
and fold-const.h.

  * There were 5 build_* routines in builtins.c that really should be in
tree.c. They are used all over the place.  The prototypes were already
in tree.h.
  * There were 3 routines in builtins.c that belonged in targhooks.c.
The prototypes were already in targhooks.h

* fold-const.c uses do_mpc_arg2() which is defined in builtins.c, so the
prototype should be in builtins.h. The prototype utilizes type
mpc_srcptr from  which means that every file which includes
builtins.h would also require #include . That is likely the
reason the prototype was placed into realmpfr.h.  I added #include
 to builtins.h.  Normally we're trying not to do that until we
can rebuild a decent module structure, but I think that rule only makes
sense for include files within gcc's source base...

Seems reasonable.



* Finally, fortran/trans.c was calling fold_builtin_call_array directly.
That means it would have needed builtins.h which caused issues since
builtins.h defines struct target_builtins and uses
FIRST_PSEUDO_REGISTER... which is defined within the target config
file... something I dont think we really want to expose to the fortran
front end :-P.  Anyway, looking aorund, it turns out
fold-const.c::fold_build_call_array_loc is really a wrapper for a call
to fold_builtin_call_array, with some extra checking code before and
after the call protected by ENABLE_FOLD_CHECKING.  I'd think that should
be OK since its what other front ends call...

Ick.  Yea, it'd be good if FIRST_PSEUDO_REGISTER doesn't bleed all the 
way into the front-ends.




Bootstraps on x86_64-unknown-linux-gnu with no regressions. I also ran
it through a full set of target builds for compilation, with no new
failures there.

The second set of patches are the updated #includes required for
compilation.

OK for trunk?

OK.
jeff



Re: [PATCH, Pointer Bounds Checker 13/x] Early versioning

2014-06-02 Thread Jeff Law

On 06/02/14 04:48, Ilya Enkovich wrote:

Hmm, so if I understand things correctly, src_fun has no loop
structures attached, thus there's nothing to copy.  Presumably at
some later point we build loop structures for the copy from scratch?

I suppose it is just a simple bug with absent NULL pointer check.  Here is 
original code:

   /* Duplicate the loop tree, if available and wanted.  */
   if (loops_for_fn (src_cfun) != NULL
   && current_loops != NULL)
 {
   copy_loops (id, entry_block_map->loop_father,
   get_loop (src_cfun, 0));
   /* Defer to cfgcleanup to update loop-father fields of basic-blocks.  */
   loops_state_set (LOOPS_NEED_FIXUP);
 }

   /* If the loop tree in the source function needed fixup, mark the
  destination loop tree for fixup, too.  */
   if (loops_for_fn (src_cfun)->state & LOOPS_NEED_FIXUP)
 loops_state_set (LOOPS_NEED_FIXUP);

As you may see we have check for absent loops structure in the first 
if-statement and no check in the second one.  I hit segfault and added the 
check.
Downthread you indicated you're not in SSA form which might explain the 
inconsistency here.  If so, then we need to make sure that the loop & df 
structures do get set up properly later.


Jeff


Re: [PATCH] rebuild frequency after vrp

2014-06-02 Thread Dehao Chen
Just tried with Teresa's patch, the ICE in
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61384 is not resolved.

Dehao

On Mon, Jun 2, 2014 at 9:45 AM, Jeff Law  wrote:
> On 06/02/14 10:17, Dehao Chen wrote:
>>
>> We need to rebuild frequency after vrp, otherwise the following code
>> in tree-ssa-threadupdate.c will make the frequency larger than
>> upper-bound.
>>
>>/* Excessive jump threading may make frequencies large enough
>> so
>>   the computation overflows.  */
>>if (rd->dup_blocks[0]->frequency < BB_FREQ_MAX * 2)
>>  rd->dup_blocks[0]->frequency += EDGE_FREQUENCY (e);
>>
>> This is referring to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61384
>
> Can you try this with Teresa's revamping of the jump threading frequency
> updates?  It's still in my queue of things to review.
>
> Fixing this stuff in the updater would be better than rebuilding the
> frequencies, IMHO.
>
> Jeff
>


Re: [C/C++ PATCH] Add -Wlogical-not-parentheses (PR c/49706)

2014-06-02 Thread Jakub Jelinek
On Mon, Jun 02, 2014 at 07:04:58PM +0200, Marek Polacek wrote:
> > Do we actually want to warn in that case?  As the patch doesn't warn
> > if the type is bool or vector, if somebody instantiates the above with
> > say T=bool, U=bool, then we'd warn on something that otherwise will not be
> > warned about when not in template.
> > But to warn about this during instantiation, we'd need to somehow tell
> > tsubst* whether it was !t == u or (!t) == u ...
> 
> Ah - indeed.  So I suggest to stay with !processing_template_decl ;).

Well, if the vars are known not to be boolean, even in template, you can
warn about this right away (i.e. if they aren't
type_dependent_expression_p).

Jakub


Re: [C/C++ PATCH] Add -Wlogical-not-parentheses (PR c/49706)

2014-06-02 Thread Marek Polacek
On Mon, Jun 02, 2014 at 06:36:06PM +0200, Jakub Jelinek wrote:
> On Mon, Jun 02, 2014 at 12:31:32PM -0400, Jason Merrill wrote:
> > On 06/02/2014 12:23 PM, Marek Polacek wrote:
> > >I have no special reason for that check, so dropped it too in this
> > >patch.
> > 
> > Thanks. I expect that warn_logical_not_parentheses will crash if one
> > of the operands is type-dependent such that TREE_TYPE is NULL_TREE,
> > so you'll want to handle that case, and test it in the testcase,
> > i.e. something like
> > 
> > #ifdef __cplusplus
> > template  bool f(T t, U u) { return (!t == u); }
> > #endif
> > 
> > I think !t should have null TREE_TYPE in this case.
 
Hmm, I see no crash; the types seem to be
template_type_parm 0x7013d5e8 T type_0 type_6 VOID ...

> Do we actually want to warn in that case?  As the patch doesn't warn
> if the type is bool or vector, if somebody instantiates the above with
> say T=bool, U=bool, then we'd warn on something that otherwise will not be
> warned about when not in template.
> But to warn about this during instantiation, we'd need to somehow tell
> tsubst* whether it was !t == u or (!t) == u ...

Ah - indeed.  So I suggest to stay with !processing_template_decl ;).

Marek


[PATCH] [ARM] Post-indexed addressing for NEON memory access

2014-06-02 Thread Charles Baylis
This patch adds support for post-indexed addressing for NEON structure
memory accesses.

For example VLD1.8 {d0}, [r0], r1


Bootstrapped and checked on arm-unknown-gnueabihf using Qemu.

Ok for trunk?


gcc/Changelog:

2014-06-02  Charles Baylis  

* config/arm/arm.c (neon_vector_mem_operand): Allow register
POST_MODIFY for neon loads and stores.
(arm_print_operand): Output post-index register for neon loads and
stores.
From a8e0bdbceab00d5e5b655611965d3975ba74365c Mon Sep 17 00:00:00 2001
From: Charles Baylis 
Date: Tue, 6 May 2014 15:23:46 +0100
Subject: [PATCH] post-indexed addressing for vld/vst

2014-05-09  Charles Baylis  

	* config/arm/arm.c (neon_vector_mem_operand): Allow register
	POST_MODIFY for neon loads and stores.
	(arm_print_operand): Output post-index register for neon loads and
	stores.
---
 gcc/config/arm/arm.c | 14 +-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index 1117bd4..6ab02ef 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -12786,7 +12786,11 @@ neon_vector_mem_operand (rtx op, int type, bool strict)
   || (type == 0 && GET_CODE (ind) == PRE_DEC))
 return arm_address_register_rtx_p (XEXP (ind, 0), 0);
 
-  /* FIXME: vld1 allows register post-modify.  */
+  /* Allow post-increment by register for VLDn */
+  if (type == 2 && GET_CODE (ind) == POST_MODIFY
+  && GET_CODE (XEXP (ind, 1)) == PLUS
+  && REG_P (XEXP (XEXP (ind, 1), 1)))
+ return true;
 
   /* Match:
  (plus (reg)
@@ -21816,6 +21820,7 @@ arm_print_operand (FILE *stream, rtx x, int code)
   {
 	rtx addr;
 	bool postinc = FALSE;
+	rtx postinc_reg = NULL;
 	unsigned align, memsize, align_bits;
 
 	gcc_assert (MEM_P (x));
@@ -21825,6 +21830,11 @@ arm_print_operand (FILE *stream, rtx x, int code)
 	postinc = 1;
 	addr = XEXP (addr, 0);
 	  }
+	if (GET_CODE (addr) == POST_MODIFY)
+	  {
+	postinc_reg = XEXP( XEXP (addr, 1), 1);
+	addr = XEXP (addr, 0);
+	  }
 	asm_fprintf (stream, "[%r", REGNO (addr));
 
 	/* We know the alignment of this access, so we can emit a hint in the
@@ -21850,6 +21860,8 @@ arm_print_operand (FILE *stream, rtx x, int code)
 
 	if (postinc)
 	  fputs("!", stream);
+	if (postinc_reg)
+	  asm_fprintf (stream, ", %r", REGNO (postinc_reg));
   }
   return;
 
-- 
1.9.1



Re: [PATCH] rebuild frequency after vrp

2014-06-02 Thread Jeff Law

On 06/02/14 10:17, Dehao Chen wrote:

We need to rebuild frequency after vrp, otherwise the following code
in tree-ssa-threadupdate.c will make the frequency larger than
upper-bound.

   /* Excessive jump threading may make frequencies large enough so
  the computation overflows.  */
   if (rd->dup_blocks[0]->frequency < BB_FREQ_MAX * 2)
 rd->dup_blocks[0]->frequency += EDGE_FREQUENCY (e);

This is referring to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61384
Can you try this with Teresa's revamping of the jump threading frequency 
updates?  It's still in my queue of things to review.


Fixing this stuff in the updater would be better than rebuilding the 
frequencies, IMHO.


Jeff



Fix target/61336 -- alpha ice on questionable asm

2014-06-02 Thread Richard Henderson
The scheme that alpha uses to split symbolic references into trackable pairs of
relocations doesn't really handle asms.  Of course, normal asms don't have the
problem seen here because they're interested in producing instructions, whereas
this case is system tap creating some annotations.

The most important part of the patch is the call to output_operand_lossage,
which eliminates the ICE.

The rest of the patch is somewhat debatable.  It certainly "works" for the
given test case, in that the assembly hunk is producing string data.  But I
doubt that system tap has actually been ported to alpha, so whether it "works"
in the more specific sense of doing the right thing, I have no idea.

In order to more "properly" handle symbolic references in asms, we'd probably
have to write a dedicated pass rather than rely on post-reload splitting.
Which is more of a viable option now than in olden times.  But "properly" in
this particular case would almost certainly *not* work for system tap, since it
would result in a weird symbol+reloc string that I'm certain would not be
handled properly by system tap.


r~
PR target/61336
* config/alpha/alpha.c (print_operand_address): Allow symbolic
addresses inside asms.  Use output_operand_lossage instead of
gcc_unreachable.


diff --git a/gcc/config/alpha/alpha.c b/gcc/config/alpha/alpha.c
index efef1e9..7663e20 100644
--- a/gcc/config/alpha/alpha.c
+++ b/gcc/config/alpha/alpha.c
@@ -5450,22 +5450,23 @@ print_operand_address (FILE *file, rtx addr)
   offset = INTVAL (addr);
   break;
 
-#if TARGET_ABI_OPEN_VMS
 case SYMBOL_REF:
+  gcc_assert(TARGET_ABI_OPEN_VMS || this_is_asm_operands);
   fprintf (file, "%s", XSTR (addr, 0));
   return;
 
 case CONST:
+  gcc_assert(TARGET_ABI_OPEN_VMS || this_is_asm_operands);
   gcc_assert (GET_CODE (XEXP (addr, 0)) == PLUS
  && GET_CODE (XEXP (XEXP (addr, 0), 0)) == SYMBOL_REF);
   fprintf (file, "%s+" HOST_WIDE_INT_PRINT_DEC,
   XSTR (XEXP (XEXP (addr, 0), 0), 0),
   INTVAL (XEXP (XEXP (addr, 0), 1)));
   return;
-
-#endif
+
 default:
-  gcc_unreachable ();
+  output_operand_lossage ("invalid operand address");
+  return;
 }
 
   fprintf (file, HOST_WIDE_INT_PRINT_DEC "($%d)", offset, basereg);


Re: [C/C++ PATCH] Add -Wlogical-not-parentheses (PR c/49706)

2014-06-02 Thread Jakub Jelinek
On Mon, Jun 02, 2014 at 12:31:32PM -0400, Jason Merrill wrote:
> On 06/02/2014 12:23 PM, Marek Polacek wrote:
> >I have no special reason for that check, so dropped it too in this
> >patch.
> 
> Thanks. I expect that warn_logical_not_parentheses will crash if one
> of the operands is type-dependent such that TREE_TYPE is NULL_TREE,
> so you'll want to handle that case, and test it in the testcase,
> i.e. something like
> 
> #ifdef __cplusplus
> template  bool f(T t, U u) { return (!t == u); }
> #endif
> 
> I think !t should have null TREE_TYPE in this case.

Do we actually want to warn in that case?  As the patch doesn't warn
if the type is bool or vector, if somebody instantiates the above with
say T=bool, U=bool, then we'd warn on something that otherwise will not be
warned about when not in template.
But to warn about this during instantiation, we'd need to somehow tell
tsubst* whether it was !t == u or (!t) == u ...

Jakub


[COMMITTED][AArch64] Remove ISB after FPCR write.

2014-06-02 Thread Marcus Shawcroft

This patch removes the ISB following FPCR write.  Committed.

/Marcus

2014-06-02  Marcus Shawcroft  

   * config/aarch64/aarch64.md (set_fpcr): Drop ISB after FPCR write.
commit 933934b5636f539d2b678a9f3400f7dd1560faa1
Author: Marcus Shawcroft 
Date:   Mon Jun 2 12:51:49 2014 +0100

[AArch64] Drop ISB after FPCR write.

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 120ada9..9b46f58 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,7 @@
+2014-06-02  Marcus Shawcroft  
+
+   * config/aarch64/aarch64.md (set_fpcr): Drop ISB after FPCR write.
+
 2014-06-01  Uros Bizjak  
 
* config/i386/constraints.md (Bw): Rename from 'w'.
diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md
index fec2ea8..6e605c1 100644
--- a/gcc/config/aarch64/aarch64.md
+++ b/gcc/config/aarch64/aarch64.md
@@ -3904,7 +3904,7 @@
 (define_insn "set_fpcr"
   [(unspec_volatile [(match_operand:SI 0 "register_operand" "r")] 
UNSPECV_SET_FPCR)]
   ""
-  "msr\\tfpcr, %0\;isb"
+  "msr\\tfpcr, %0"
   [(set_attr "type" "mrs")])
 
 ;; Read Floating-point Control Register.

Re: [C/C++ PATCH] Add -Wlogical-not-parentheses (PR c/49706)

2014-06-02 Thread Jason Merrill

On 06/02/2014 12:23 PM, Marek Polacek wrote:

I have no special reason for that check, so dropped it too in this
patch.


Thanks. I expect that warn_logical_not_parentheses will crash if one of 
the operands is type-dependent such that TREE_TYPE is NULL_TREE, so 
you'll want to handle that case, and test it in the testcase, i.e. 
something like


#ifdef __cplusplus
template  bool f(T t, U u) { return (!t == u); }
#endif

I think !t should have null TREE_TYPE in this case.

Jason



Re: [C/C++ PATCH] Add -Wlogical-not-parentheses (PR c/49706)

2014-06-02 Thread Marek Polacek
On Mon, Jun 02, 2014 at 12:01:22PM -0400, Jason Merrill wrote:
> On 06/02/2014 11:17 AM, Marek Polacek wrote:
> >+  && !processing_template_decl
> 
> Also, why not warn when parsing a template?  We don't need to know the type
> to recognize the problematic syntax.

I have no special reason for that check, so dropped it too in this
patch.

Ran dg.exp with this warning enabled in -Wall; no regressions.

2014-06-02  Marek Polacek  

PR c/49706
* doc/invoke.texi: Document -Wlogical-not-parentheses.
c-family/
* c-common.c (warn_logical_not_parentheses): New function.
* c-common.h (warn_logical_not_parentheses): Declare.
* c.opt (Wlogical-not-parentheses): New option.
c/
* c-typeck.c (parser_build_binary_op): Warn when logical not is used
on the left hand side operand of a comparison. 
cp/
* parser.c (cp_parser_binary_expression): Warn when logical not is
used on the left hand side operand of a comparison.
testsuite/
* c-c++-common/pr49706.c: New test.

diff --git gcc/c-family/c-common.c gcc/c-family/c-common.c
index 6ec14fc..650afaf 100644
--- gcc/c-family/c-common.c
+++ gcc/c-family/c-common.c
@@ -1722,6 +1722,25 @@ warn_logical_operator (location_t location, enum 
tree_code code, tree type,
 }
 }
 
+/* Warn about logical not used on the left hand side operand of a comparison.
+   This function assumes that the LHS is inside of TRUTH_NOT_EXPR.
+   Do not warn if the LHS or RHS is of a boolean or a vector type.  */
+
+void
+warn_logical_not_parentheses (location_t location, enum tree_code code,
+ tree lhs, tree rhs)
+{
+  if (TREE_CODE_CLASS (code) != tcc_comparison
+  || TREE_CODE (TREE_TYPE (lhs)) == BOOLEAN_TYPE
+  || TREE_CODE (TREE_TYPE (rhs)) == BOOLEAN_TYPE
+  || VECTOR_TYPE_P (TREE_TYPE (lhs))
+  || VECTOR_TYPE_P (TREE_TYPE (rhs)))
+return;
+
+  warning_at (location, OPT_Wlogical_not_parentheses,
+ "logical not is only applied to the left hand side of "
+ "comparison");
+}
 
 /* Warn if EXP contains any computations whose results are not used.
Return true if a warning is printed; false otherwise.  LOCUS is the
diff --git gcc/c-family/c-common.h gcc/c-family/c-common.h
index 0d34004..83d5dee 100644
--- gcc/c-family/c-common.h
+++ gcc/c-family/c-common.h
@@ -772,6 +772,8 @@ extern void overflow_warning (location_t, tree);
 extern bool warn_if_unused_value (const_tree, location_t);
 extern void warn_logical_operator (location_t, enum tree_code, tree,
   enum tree_code, tree, enum tree_code, tree);
+extern void warn_logical_not_parentheses (location_t, enum tree_code, tree,
+ tree);
 extern void check_main_parameter_types (tree decl);
 extern bool c_determine_visibility (tree);
 extern bool vector_types_compatible_elements_p (tree, tree);
diff --git gcc/c-family/c.opt gcc/c-family/c.opt
index c586e65..d51c890 100644
--- gcc/c-family/c.opt
+++ gcc/c-family/c.opt
@@ -490,6 +490,10 @@ Wlogical-op
 C ObjC C++ ObjC++ Var(warn_logical_op) Init(0) Warning 
 Warn when a logical operator is suspiciously always evaluating to true or false
 
+Wlogical-not-parentheses
+C ObjC C++ ObjC++ Var(warn_logical_not_paren) Warning
+Warn when logical not is used on the left hand side operand of a comparison
+
 Wlong-long
 C ObjC C++ ObjC++ Var(warn_long_long) Init(-1) Warning
 Do not warn about using \"long long\" when -pedantic
diff --git gcc/c/c-typeck.c gcc/c/c-typeck.c
index 6ca584b..e98224e 100644
--- gcc/c/c-typeck.c
+++ gcc/c/c-typeck.c
@@ -3401,6 +3401,10 @@ parser_build_binary_op (location_t location, enum 
tree_code code,
 warn_logical_operator (location, code, TREE_TYPE (result.value),
   code1, arg1.value, code2, arg2.value);
 
+  if (warn_logical_not_paren
+  && code1 == TRUTH_NOT_EXPR)
+warn_logical_not_parentheses (location, code, arg1.value, arg2.value);
+
   /* Warn about comparisons against string literals, with the exception
  of testing for equality or inequality of a string literal with NULL.  */
   if (code == EQ_EXPR || code == NE_EXPR)
diff --git gcc/cp/parser.c gcc/cp/parser.c
index 2591ae5..60e6cda 100644
--- gcc/cp/parser.c
+++ gcc/cp/parser.c
@@ -7883,6 +7883,8 @@ cp_parser_binary_expression (cp_parser* parser, bool 
cast_p,
   enum tree_code rhs_type;
   enum cp_parser_prec new_prec, lookahead_prec;
   tree overload;
+  bool parenthesized_not_lhs_warn
+= cp_lexer_next_token_is (parser->lexer, CPP_NOT);
 
   /* Parse the first expression.  */
   current.lhs = cp_parser_cast_expression (parser, /*address_p=*/false,
@@ -7985,6 +7987,11 @@ cp_parser_binary_expression (cp_parser* parser, bool 
cast_p,
   else if (current.tree_type == TRUTH_ORIF_EXPR)
c_inhibit_evaluation_warnings -= current.lhs == truthvalue_true_node;
 
+  if (warn_logical_not_paren
+ && parenthesized_not_lhs_warn)
+   warn_logical_not

Re: [PATCH] rebuild frequency after vrp

2014-06-02 Thread Dehao Chen
We need to rebuild frequency after vrp, otherwise the following code
in tree-ssa-threadupdate.c will make the frequency larger than
upper-bound.

  /* Excessive jump threading may make frequencies large enough so
 the computation overflows.  */
  if (rd->dup_blocks[0]->frequency < BB_FREQ_MAX * 2)
rd->dup_blocks[0]->frequency += EDGE_FREQUENCY (e);

This is referring to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61384

Thanks,
Dehao

On Mon, Jun 2, 2014 at 9:13 AM, Jan Hubicka  wrote:
>> This patch rebuilds frequency after vrp.
>
> Why do you need to rebuild frequency after VRP?  I always tought it may be
> useful to do VRP as early optimization (modulo to compile time costs),
> but I do not think we should unconditionally rebuild frequencies like this...
>
> Honza
>>
>> Bootstrapped and testing on-going. OK for trunk if test pass?
>>
>> Thanks,
>> Dehao
>>
>> gcc/ChangeLog:
>> 2014-06-02  Dehao Chen  
>>
>> PR tree-optimization/61384
>> * tree-vrp.c (execute_vrp): rebuild frequency after vrp.
>>
>> gcc/testsuite/ChangeLog:
>> 2014-06-02  Dehao Chen  
>>
>> PR tree-optimization/61384
>> * gcc.dg/pr61384.c: New testcase.
>>
>> Index: gcc/testsuite/gcc.dg/pr61384.c
>> ===
>> --- gcc/testsuite/gcc.dg/pr61384.c (revision 0)
>> +++ gcc/testsuite/gcc.dg/pr61384.c (revision 0)
>> @@ -0,0 +1,32 @@
>> +/* PR tree-optimization/61384 */
>> +/* { dg-do compile } */
>> +/* { dg-options "-O3" } */
>> +
>> +int a, b, d, e, g, h;
>> +static int c = 1, f[5];
>> +
>> +int
>> +fn1 (int p1, int p2)
>> +{
>> +  return p1 && p2 && p2;
>> +}
>> +
>> +void
>> +fn2 ()
>> +{
>> +  for (d = 0; d < 1; d++)
>> +{
>> +  g = f[0];
>> +  e = 0;
>> +  h = fn1 (1, (a && c) ^ b);
>> +}
>> +  for (; e < 5; e++)
>> +f[e] = 1;
>> +}
>> +
>> +int
>> +main ()
>> +{
>> +  fn2 ();
>> +  return 0;
>> +}
>>
>> Index: gcc/tree-vrp.c
>> ===
>> --- gcc/tree-vrp.c (revision 211137)
>> +++ gcc/tree-vrp.c (working copy)
>> @@ -9794,7 +9794,7 @@ execute_vrp (void)
>>
>>scev_finalize ();
>>loop_optimizer_finalize ();
>> -  return 0;
>> +  return TODO_rebuild_frequencies;
>>  }
>>
>>  namespace {


Re: [PATCH] rebuild frequency after vrp

2014-06-02 Thread Jan Hubicka
> This patch rebuilds frequency after vrp.

Why do you need to rebuild frequency after VRP?  I always tought it may be
useful to do VRP as early optimization (modulo to compile time costs),
but I do not think we should unconditionally rebuild frequencies like this...

Honza
> 
> Bootstrapped and testing on-going. OK for trunk if test pass?
> 
> Thanks,
> Dehao
> 
> gcc/ChangeLog:
> 2014-06-02  Dehao Chen  
> 
> PR tree-optimization/61384
> * tree-vrp.c (execute_vrp): rebuild frequency after vrp.
> 
> gcc/testsuite/ChangeLog:
> 2014-06-02  Dehao Chen  
> 
> PR tree-optimization/61384
> * gcc.dg/pr61384.c: New testcase.
> 
> Index: gcc/testsuite/gcc.dg/pr61384.c
> ===
> --- gcc/testsuite/gcc.dg/pr61384.c (revision 0)
> +++ gcc/testsuite/gcc.dg/pr61384.c (revision 0)
> @@ -0,0 +1,32 @@
> +/* PR tree-optimization/61384 */
> +/* { dg-do compile } */
> +/* { dg-options "-O3" } */
> +
> +int a, b, d, e, g, h;
> +static int c = 1, f[5];
> +
> +int
> +fn1 (int p1, int p2)
> +{
> +  return p1 && p2 && p2;
> +}
> +
> +void
> +fn2 ()
> +{
> +  for (d = 0; d < 1; d++)
> +{
> +  g = f[0];
> +  e = 0;
> +  h = fn1 (1, (a && c) ^ b);
> +}
> +  for (; e < 5; e++)
> +f[e] = 1;
> +}
> +
> +int
> +main ()
> +{
> +  fn2 ();
> +  return 0;
> +}
> 
> Index: gcc/tree-vrp.c
> ===
> --- gcc/tree-vrp.c (revision 211137)
> +++ gcc/tree-vrp.c (working copy)
> @@ -9794,7 +9794,7 @@ execute_vrp (void)
> 
>scev_finalize ();
>loop_optimizer_finalize ();
> -  return 0;
> +  return TODO_rebuild_frequencies;
>  }
> 
>  namespace {


Re: [PATCH] Fix PR ipa/61190

2014-06-02 Thread Jan Hubicka
> Hi,
> 
> On Mon, 2 Jun 2014 12:06:12, Richard Biener wrote:
> >
> > On Mon, Jun 2, 2014 at 11:00 AM, Bernd Edlinger
> >  wrote:
> >> Hi,
> >>
> >> the test case g++.old-deja/g++.mike/p4736b.C is mis-compiled with with all
> >> optimization levels, except -O0 and -Og. This probably started with gcc 
> >> 4.7.x.
> >>
> >> The constructor Main::Main() is first inlined and then completely optimized
> >> away in the dce1 pass. But the thunk is still using the vtable, and 
> >> therefore
> >> crashes.

Why the ctor is eliminated? Is it because ipa-pure-const identifies the thunk 
as const?
I think we need to update it to notice the read of vtable in those thunks.   I 
will
take a look.

Honza
> >>
> >> Well, the problem seems to be, that the thunk code is
> >> not emitted in the normal way using gimple code,
> >> but instead by the i386 back-end with a callback.
> >>
> >> This makes the thunk invisible to the ipa-pure-const pass,
> >> which assumes that all values just flow straight thu the thunk.
> >>
> >> See ipa-pure-const.c (analyze_function):
> >>
> >> if (fn->thunk.thunk_p || fn->alias)
> >> {
> >> /* Thunk gets propagated through, so nothing interesting happens. */
> >> gcc_assert (ipa);
> >> return l;
> >> }
> >>
> >> But this is not true for a virtual base class:
> >> The thunk itself references the vtable, so if nothing else might need
> >> the vtable, the optimizer may remove the initalization of the vtable,
> >> which happened in this example.
> >>
> >> The most simple work around would be the attached patch, which
> >> simply falls back to emitting gimple code, if virtual base classes
> >> are used.
> >>
> >> Boot-Strapped and Regression-Tested on x86_64-linux-gnu.
> >> Ok for trunk?
> >
> > Honza should know better. I'd rather skip the above for
> > thunks going the output_mi_thunk way.
> >
> 
> Ahh Yes, that was of course my first attempt...
> 
> But there is not BB to enumerate in that case.
> And the loop below just crashed in:
> 
>   FOR_EACH_BB_FN (this_block, cfun)
>  
> 
> There is also another interesting thing to mention: when the
> output_mi_thunk outputs the virtual thunk, there is no inlining at all.
> 
> But with this patch, the thunk inlines the called function,
> and therefore the generated code looks rather nifty, compared to
> the state before the patch.
> 
> 
> Thanks
> Bernd.
> 
> > That is, the target hook docs should be updated to reflect which
> > kind of thunks it is supposed to handle.
> >
> > Richard.
> >
> >>
> >> Thanks
> >> Bernd.
> >>
> 


Re: [C/C++ PATCH] Add -Wlogical-not-parentheses (PR c/49706)

2014-06-02 Thread Jason Merrill

On 06/02/2014 11:17 AM, Marek Polacek wrote:

+ && !processing_template_decl


Also, why not warn when parsing a template?  We don't need to know the 
type to recognize the problematic syntax.


Jason



[PATCH, Pointer Bounds Checker 22/x] Inline

2014-06-02 Thread Ilya Enkovich
Hi,

This patch adds support for inlining instrumented calls.  Changes are mostly to 
support returned bounds.  Also generated mem-to-mem assignments are registered 
to be later instrumented with appropriate bounds copy.

Bootstrapped and tested on linux-x86_64.

Thanks,
Ilya
--
gcc/

2014-06-02  Ilya Enkovich  

* ipa-inline.c (early_inliner): Check edge has summary allocated.
* tree-inline.c: Include tree-chkp.h.
(declare_return_variable): Add arg holding
returned bounds slot.  Create and initialize returned bounds var.
(remap_gimple_stmt): Handle returned bounds.
Return sequence of statements instead of a single statement.
(insert_init_stmt): Add declaration.
(remap_gimple_seq): Adjust to new remap_gimple_stmt signature.
(copy_bb): Adjust to changed return type of remap_gimple_stmt.
(expand_call_inline): Handle returned bounds.  Add bounds copy
for generated mem to mem assignments.
* tree-inline.h (copy_body_data): Add fields retbnd and
assign_stmts.
* cgraph.c: Include tree-chkp.h.
(cgraph_redirect_edge_call_stmt_to_callee): Support
returned bounds.
* value-prof.c: Include tree-chkp.h.
(gimple_ic): Support returned bounds.
 

diff --git a/gcc/cgraph.c b/gcc/cgraph.c
index 1f684c2..4b6996b 100644
--- a/gcc/cgraph.c
+++ b/gcc/cgraph.c
@@ -63,6 +63,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "gimple-pretty-print.h"
 #include "expr.h"
 #include "tree-dfa.h"
+#include "tree-chkp.h"
 
 /* FIXME: Only for PROP_loops, but cgraph shouldn't have to know about this.  
*/
 #include "tree-pass.h"
@@ -1398,6 +1399,31 @@ cgraph_redirect_edge_call_stmt_to_callee (struct 
cgraph_edge *e)
  e->speculative = false;
  cgraph_set_call_stmt_including_clones (e->caller, e->call_stmt,
 new_stmt, false);
+
+ /* Fix edges for BUILT_IN_CHKP_BNDRET calls attached to the
+processed call stmt.  */
+ if (gimple_call_with_bounds_p (new_stmt)
+ && gimple_call_lhs (new_stmt)
+ && chkp_retbnd_call_by_val (gimple_call_lhs (e2->call_stmt)))
+   {
+ tree dresult = gimple_call_lhs (new_stmt);
+ tree iresult = gimple_call_lhs (e2->call_stmt);
+ gimple dbndret = chkp_retbnd_call_by_val (dresult);
+ gimple ibndret = chkp_retbnd_call_by_val (iresult);
+ struct cgraph_edge *iedge = cgraph_edge (e2->caller, ibndret);
+ struct cgraph_edge *dedge;
+
+ if (dbndret)
+   {
+ dedge = cgraph_create_edge (iedge->caller, iedge->callee,
+ dbndret, e->count,
+ e->frequency);
+ dedge->frequency = compute_call_stmt_bb_frequency
+   (dedge->caller->decl, gimple_bb (dedge->call_stmt));
+   }
+ iedge->frequency = compute_call_stmt_bb_frequency
+   (iedge->caller->decl, gimple_bb (iedge->call_stmt));
+   }
  e->frequency = compute_call_stmt_bb_frequency
   (e->caller->decl, gimple_bb (e->call_stmt));
  e2->frequency = compute_call_stmt_bb_frequency
diff --git a/gcc/ipa-inline.c b/gcc/ipa-inline.c
index 4051819..a6fc853 100644
--- a/gcc/ipa-inline.c
+++ b/gcc/ipa-inline.c
@@ -2301,11 +2301,15 @@ early_inliner (void)
 info that might be cleared out for newly discovered edges.  */
  for (edge = node->callees; edge; edge = edge->next_callee)
{
- struct inline_edge_summary *es = inline_edge_summary (edge);
- es->call_stmt_size
-   = estimate_num_insns (edge->call_stmt, &eni_size_weights);
- es->call_stmt_time
-   = estimate_num_insns (edge->call_stmt, &eni_time_weights);
+ /* We have no summary for new bound store calls yet.  */
+ if (inline_edge_summary_vec.length () > (unsigned)edge->uid)
+   {
+ struct inline_edge_summary *es = inline_edge_summary (edge);
+ es->call_stmt_size
+   = estimate_num_insns (edge->call_stmt, &eni_size_weights);
+ es->call_stmt_time
+   = estimate_num_insns (edge->call_stmt, &eni_time_weights);
+   }
  if (edge->callee->decl
  && !gimple_check_call_matching_types (
  edge->call_stmt, edge->callee->decl, false))
diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c
index 23fef90..6557a95 100644
--- a/gcc/tree-inline.c
+++ b/gcc/tree-inline.c
@@ -67,6 +67,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-pass.h"
 #include "target.h"
 #include "cfgloop.h"
+#include "tree-chkp.h"
 
 #include "rtl.h"   /* FIXME: For asm_str_count.  */
 
@@ -130,7 +131,8 @@ eni_weig

Re: [PATCH, Pointer Bounds Checker 19/x] Support bounds in expand

2014-06-02 Thread Ilya Enkovich
2014-06-02 19:28 GMT+04:00 Michael Matz :
> Hi,
>
> On Mon, 2 Jun 2014, Ilya Enkovich wrote:
>
>> This patch adds support for input bounds, call bounds args and returned
>> bounds in expand pass.
>>
>>   * expr.h (store_expr): Add param for bounds target.
>
> There is exactly one place (except for the self-recursive ones) where you
> call the new store_expr with a non-null argument for bounds target, and it
> seems to be only necessary for when some sub-expression of the RHS is a
> call.  Can you somehow arrange to move that handling to the single place
> in expand_assignment() so that you don't need to change the signature of
> store_expr?

I see the only nice way to do it - store_expr should return bounds of
expanded exp. Currently it always return NULL_RTX. Does it look better
than a new argument?

Ilya
>
>
> Ciao,
> Michael.


Re: [patch] Update catch(...) handlers to deal with __forced_unwind

2014-06-02 Thread Jonathan Wakely

On 14/05/14 20:37 +0100, Jonathan Wakely wrote:

Failing to rethrow a __forced_unwind exception is very bad.

This patch ensures we rethrow them in async tasks, and makes the
shared state ready with a broken_promise so that waiting threads
don't block forever. That seems reasonable to me, does anyone have any
better ideas?

Tested x86_64-linux, will wait for feedback before committing.


Committed to trunk.



commit 8d4a49e0391269380b160bd277339f740716de0c
Author: Jonathan Wakely 
Date:   Tue May 13 15:35:29 2014 +0100

* include/std/condition_variable (condition_variable_any::_Unlock): Do
not swallow __forced_unwind.
* include/std/future (__future_base::_Task_setter): Likewise.
(__future_base::_Async_state_impl): Turn __forced_unwind into broken
promise and rethrow.
* include/std/mutex (try_lock): Likewise.
* testsuite/30_threads/async/forced_unwind.cc: New.
* testsuite/30_threads/packaged_task/forced_unwind.cc: New.

diff --git a/libstdc++-v3/include/std/condition_variable 
b/libstdc++-v3/include/std/condition_variable
index fc111dd..921cb83 100644
--- a/libstdc++-v3/include/std/condition_variable
+++ b/libstdc++-v3/include/std/condition_variable
@@ -189,7 +189,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
~_Unlock() noexcept(false)
{
  if (uncaught_exception())
-   __try { _M_lock.lock(); } __catch(...) { }
+   {
+ __try
+ { _M_lock.lock(); }
+ __catch(const __cxxabiv1::__forced_unwind&)
+ { __throw_exception_again; }
+ __catch(...)
+ { }
+   }
  else
_M_lock.lock();
}
diff --git a/libstdc++-v3/include/std/future b/libstdc++-v3/include/std/future
index 717ce71..8972ecf 100644
--- a/libstdc++-v3/include/std/future
+++ b/libstdc++-v3/include/std/future
@@ -1231,6 +1231,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
  {
_M_result->_M_set(_M_fn());
  }
+   __catch(const __cxxabiv1::__forced_unwind&)
+ {
+   __throw_exception_again; // will cause broken_promise
+ }
__catch(...)
  {
_M_result->_M_error = current_exception();
@@ -1250,6 +1254,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
  {
_M_fn();
  }
+   __catch(const __cxxabiv1::__forced_unwind&)
+ {
+   __throw_exception_again; // will cause broken_promise
+ }
__catch(...)
  {
_M_result->_M_error = current_exception();
@@ -1510,7 +1518,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
  : _M_result(new _Result<_Res>()), _M_fn(std::move(__fn))
  {
_M_thread = std::thread{ [this] {
- _M_set_result(_S_task_setter(_M_result, _M_fn));
+   __try
+ {
+   _M_set_result(_S_task_setter(_M_result, _M_fn));
+ }
+   __catch (const __cxxabiv1::__forced_unwind&)
+ {
+   // make the shared state ready on thread cancellation
+   if (static_cast(_M_result))
+ this->_M_break_promise(std::move(_M_result));
+   __throw_exception_again;
+ }
} };
  }

diff --git a/libstdc++-v3/include/std/mutex b/libstdc++-v3/include/std/mutex
index 3d70754..f6b851c 100644
--- a/libstdc++-v3/include/std/mutex
+++ b/libstdc++-v3/include/std/mutex
@@ -44,6 +44,7 @@
#include 
#include 
#include  // for std::swap
+#include 

#ifdef _GLIBCXX_USE_C99_STDINT_TR1

@@ -631,6 +632,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
  auto __locks = std::tie(__l1, __l2, __l3...);
  __try
  { __try_lock_impl<0>::__do_try_lock(__locks, __idx); }
+  __catch(const __cxxabiv1::__forced_unwind&)
+  { __throw_exception_again; }
  __catch(...)
  { }
  return __idx;
diff --git a/libstdc++-v3/testsuite/30_threads/async/forced_unwind.cc 
b/libstdc++-v3/testsuite/30_threads/async/forced_unwind.cc
new file mode 100644
index 000..7b0a492
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/async/forced_unwind.cc
@@ -0,0 +1,45 @@
+// { dg-do run { target *-*-linux* *-*-gnu* } }
+// { dg-options " -std=gnu++11 -pthread" { target *-*-linux* *-*-gnu* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2014 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU Gene

Re: Eliminate write-only variables

2014-06-02 Thread Jan Hubicka
> 
> Well, I'm hesitant to add a new pass just to optimize a (irrelevant in 
> practice)
> benchmark.  I'm ok with strengthening existing infrastructure or enhancing
> existing passes.
> 
> The issue with these mini-passes is that they are very placement sensitive
> and you don't easily get secondary effects.  See the comment (and
> "patch") about DCE - the ??? comment can be addressed the same
> way Bernd addressed it (use cgraph_function_possibly_inlined_p).
> Would that optimize the testcase?
> 
> Note that the issue with nested function use prevails (not sure how to
> solve that - same issue in Bernds patch).

I think this part of the patch can be made much cleaner by simply adding flag
"used by one function only" to variables.  We can compute it at the end of IPA
queue and remove the code playing with local statics, nested functions and 
inlines.

I can easily implement this analysis - perhaps it would be useful for AA or
something else, too?

Honza
> 
> Thanks,
> Richard.
> 
> > -Sandra
> >


[PATCH] rebuild frequency after vrp

2014-06-02 Thread Dehao Chen
This patch rebuilds frequency after vrp.

Bootstrapped and testing on-going. OK for trunk if test pass?

Thanks,
Dehao

gcc/ChangeLog:
2014-06-02  Dehao Chen  

PR tree-optimization/61384
* tree-vrp.c (execute_vrp): rebuild frequency after vrp.

gcc/testsuite/ChangeLog:
2014-06-02  Dehao Chen  

PR tree-optimization/61384
* gcc.dg/pr61384.c: New testcase.

Index: gcc/testsuite/gcc.dg/pr61384.c
===
--- gcc/testsuite/gcc.dg/pr61384.c (revision 0)
+++ gcc/testsuite/gcc.dg/pr61384.c (revision 0)
@@ -0,0 +1,32 @@
+/* PR tree-optimization/61384 */
+/* { dg-do compile } */
+/* { dg-options "-O3" } */
+
+int a, b, d, e, g, h;
+static int c = 1, f[5];
+
+int
+fn1 (int p1, int p2)
+{
+  return p1 && p2 && p2;
+}
+
+void
+fn2 ()
+{
+  for (d = 0; d < 1; d++)
+{
+  g = f[0];
+  e = 0;
+  h = fn1 (1, (a && c) ^ b);
+}
+  for (; e < 5; e++)
+f[e] = 1;
+}
+
+int
+main ()
+{
+  fn2 ();
+  return 0;
+}

Index: gcc/tree-vrp.c
===
--- gcc/tree-vrp.c (revision 211137)
+++ gcc/tree-vrp.c (working copy)
@@ -9794,7 +9794,7 @@ execute_vrp (void)

   scev_finalize ();
   loop_optimizer_finalize ();
-  return 0;
+  return TODO_rebuild_frequencies;
 }

 namespace {


Re: Patch for builtins.h restructuring [2/2]

2014-06-02 Thread Ian Lance Taylor
On Mon, Jun 2, 2014 at 8:26 AM, Andrew MacLeod  wrote:
>
> GO changes can now be directly checked in, is that right Ian?

To be pedantically clear, it's always been OK to directly in changes
to the files in gcc/go, but not to the files in gcc/go/gofrontend.
That is still true.  What has changed recently is that the files in
gcc/go/gofrontend do not #include any GCC header files, so all general
GCC changes now only affect the files in gcc/go but not the ones in
gcc/go/gofrontend, and are therefore fine to check in directly.

In any case, this patch is fine from a Go frontend point of view.

Ian


Re: [PATCH, Pointer Bounds Checker 19/x] Support bounds in expand

2014-06-02 Thread Michael Matz
Hi,

On Mon, 2 Jun 2014, Ilya Enkovich wrote:

> This patch adds support for input bounds, call bounds args and returned 
> bounds in expand pass.
> 
>   * expr.h (store_expr): Add param for bounds target.

There is exactly one place (except for the self-recursive ones) where you 
call the new store_expr with a non-null argument for bounds target, and it 
seems to be only necessary for when some sub-expression of the RHS is a 
call.  Can you somehow arrange to move that handling to the single place 
in expand_assignment() so that you don't need to change the signature of 
store_expr?


Ciao,
Michael.


[PATCH] Add patch for debugging compiler ICEs

2014-06-02 Thread Maxim Ostapenko

Hi,

A years ago there was a discussion 
(https://gcc.gnu.org/ml/gcc-patches/2004-01/msg02437.html) about debugging 
compiler ICEs that resulted in a patch from Jakub, which dumps
useful information into temporary file, but for some reasons this patch wasn't 
applied to trunk.

This is the resurrected patch with added GCC version information into generated 
repro file.

-Maxim

2014-06-02  Jakub Jelinek  
	Max Ostapenko  

	* diagnostic.c (diagnostic_action_after_output): Exit with
	ICE_EXIT_CODE instead of FATAL_EXIT_CODE.
	* gcc.c (execute): Don't free first string early, but at the end
	of the function.  Call retry_ice if compiler exited with
	ICE_EXIT_CODE.
	(main): Factor out common code.
	(print_configuration): New function.
	(try_fork): Likewise.
	(redirect_stdout_stderr): Likewise.
	(files_equal_p): Likewise.
	(check_repro): Likewise.
	(run_attempt): Likewise.
	(generate_preprocessed_code): Likewise.
	(append_text): Likewise.
	(try_generate_repro): Likewise.

diff --git a/gcc/diagnostic.c b/gcc/diagnostic.c
index 0cc7593..67b8c5b 100644
--- a/gcc/diagnostic.c
+++ b/gcc/diagnostic.c
@@ -492,7 +492,7 @@ diagnostic_action_after_output (diagnostic_context *context,
 	real_abort ();
   diagnostic_finish (context);
   fnotice (stderr, "compilation terminated.\n");
-  exit (FATAL_EXIT_CODE);
+  exit (ICE_EXIT_CODE);
 
 default:
   gcc_unreachable ();
diff --git a/gcc/gcc.c b/gcc/gcc.c
index 9ac18e6..86dce03 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -43,6 +43,13 @@ compilation is specified by a string called a "spec".  */
 #include "params.h"
 #include "vec.h"
 #include "filenames.h"
+#ifdef HAVE_UNISTD_H
+#include 
+#endif
+
+#if !(defined (__MSDOS__) || defined (OS2) || defined (VMS))
+#define RETRY_ICE_SUPPORTED
+#endif
 
 /* By default there is no special suffix for target executables.  */
 /* FIXME: when autoconf is fixed, remove the host check - dj */
@@ -253,6 +260,9 @@ static void init_gcc_specs (struct obstack *, const char *, const char *,
 static const char *convert_filename (const char *, int, int);
 #endif
 
+#ifdef RETRY_ICE_SUPPORTED
+static void try_generate_repro (const char *prog, const char **argv);
+#endif
 static const char *getenv_spec_function (int, const char **);
 static const char *if_exists_spec_function (int, const char **);
 static const char *if_exists_else_spec_function (int, const char **);
@@ -2797,7 +2807,7 @@ execute (void)
 	}
 	}
 
-  if (string != commands[i].prog)
+  if (i && string != commands[i].prog)
 	free (CONST_CAST (char *, string));
 }
 
@@ -2850,6 +2860,16 @@ execute (void)
 	else if (WIFEXITED (status)
 		 && WEXITSTATUS (status) >= MIN_FATAL_STATUS)
 	  {
+#ifdef RETRY_ICE_SUPPORTED
+	/* For ICEs in cc1, cc1obj, cc1plus see if it is
+	   reproducible or not.  */
+	const char *p;
+	if (WEXITSTATUS (status) == ICE_EXIT_CODE
+		&& i == 0
+		&& (p = strrchr (commands[0].argv[0], DIR_SEPARATOR))
+		&& ! strncmp (p + 1, "cc1", 3))
+	  try_generate_repro (commands[0].prog, commands[0].argv);
+#endif
 	if (WEXITSTATUS (status) > greatest_status)
 	  greatest_status = WEXITSTATUS (status);
 	ret_code = -1;
@@ -2907,6 +2927,9 @@ execute (void)
 	  }
   }
 
+   if (commands[0].argv[0] != commands[0].prog)
+ free (CONST_CAST (char *, commands[0].argv[0]));
+
 return ret_code;
   }
 }
@@ -6098,6 +6121,342 @@ give_switch (int switchnum, int omit_first_word)
   switches[switchnum].validated = true;
 }
 
+static void
+print_configuration (void)
+{
+  int n;
+  const char *thrmod;
+
+  fnotice (stderr, "Target: %s\n", spec_machine);
+  fnotice (stderr, "Configured with: %s\n", configuration_arguments);
+
+#ifdef THREAD_MODEL_SPEC
+  /* We could have defined THREAD_MODEL_SPEC to "%*" by default,
+  but there's no point in doing all this processing just to get
+  thread_model back.  */
+  obstack_init (&obstack);
+  do_spec_1 (THREAD_MODEL_SPEC, 0, thread_model);
+  obstack_1grow (&obstack, '\0');
+  thrmod = XOBFINISH (&obstack, const char *);
+#else
+  thrmod = thread_model;
+#endif
+
+  fnotice (stderr, "Thread model: %s\n", thrmod);
+
+  /* compiler_version is truncated at the first space when initialized
+  from version string, so truncate version_string at the first space
+  before comparing.  */
+  for (n = 0; version_string[n]; n++)
+if (version_string[n] == ' ')
+  break;
+
+  if (! strncmp (version_string, compiler_version, n)
+  && compiler_version[n] == 0)
+fnotice (stderr, "gcc version %s %s\n\n", version_string,
+ pkgversion_string);
+  else
+fnotice (stderr, "gcc driver version %s %sexecuting gcc version %s\n\n",
+ version_string, pkgversion_string, compiler_version);
+}
+
+#ifdef RETRY_ICE_SUPPORTED
+#define RETRY_ICE_ATTEMPTS 3
+
+static int
+try_fork ()
+{
+  int pid, retries, sleep_interval;
+  sleep_interval = 1;
+  pid = -1;
+  for (retries = 0; retries < 4; retries++)
+{
+  pid = fork ();
+  if (pid >= 0)
+

Patch for builtins.h restructuring [2/2]

2014-06-02 Thread Andrew MacLeod
This is the second set of patches which updates the #includes required 
for compilation. I've reduced it to the base required set, except for 
the target config files... Most seem to require it, so in the interest 
of not breaking a target, I simply include builtins.h in all target 
config files that included tree.h or expr.h.


GO changes can now be directly checked in, is that right Ian?

Andrew
	* asan.c: Include builtins.h.
	* cfgexpand.c: Likewise.
	* convert.c: Likewise.
	* emit-rtl.c: Likewise.
	* except.c: Likewise.
	* expr.c: Likewise.
	* fold-const.c: Likewise.
	* gimple-fold.c: Likewise.
	* gimple-ssa-strength-reduction.c: Likewise.
	* gimplify.c: Likewise.
	* ipa-inline.c: Likewise.
	* ipa-prop.c: Likewise.
	* lto-streamer-out.c: Likewise.
	* stmt.c: Likewise.
	* tree-inline.c: Likewise.
	* tree-object-size.c: Likewise.
	* tree-sra.c: Likewise.
	* tree-ssa-ccp.c: Likewise.
	* tree-ssa-forwprop.c: Likewise.
	* tree-ssa-loop-ivcanon.c: Likewise.
	* tree-ssa-loop-ivopts.c: Likewise.
	* tree-ssa-math-opts.c: Likewise.
	* tree-ssa-reassoc.c: Likewise.
	* tree-ssa-threadedge.c: Likewise.
	* tree-streamer-in.c: Likewise.
	* tree-vect-data-refs.c: Likewise.
	* tree-vect-patterns.c: Likewise.
	* tree-vect-stmts.c: Likewise.

	c
	* c-decl.c: Include builtins.h.
	* c-parser.c: Likewise.

	cp
	* decl.c: Include builtins.h.
	* semantics.c: Likewise.

	go
	* go-gcc.cc: Include builtins.h.

	lto
	* lto-symtab.c: Include builtins.h.

	config
	* aarch64/aarch64.c: Include builtins.h.
	* alpha/alpha.c: Likewise.
	* arc/arc.c: Likewise.
	* arm/arm.c: Likewise.
	* avr/avr.c: Likewise.
	* bfin/bfin.c: Likewise.
	* c6x/c6x.c: Likewise.
	* cr16/cr16.c: Likewise.
	* cris/cris.c: Likewise.
	* epiphany/epiphany.c: Likewise.
	* fr30/fr30.c: Likewise.
	* frv/frv.c: Likewise.
	* h8300/h8300.c: Likewise.
	* i386/i386.c: Likewise.
	* i386/winnt.c: Likewise.
	* ia64/ia64.c: Likewise.
	* iq2000/iq2000.c: Likewise.
	* lm32/lm32.c: Likewise.
	* m32c/m32c.c: Likewise.
	* m32r/m32r.c: Likewise.
	* m68k/m68k.c: Likewise.
	* mcore/mcore.c: Likewise.
	* mep/mep.c: Likewise.
	* microblaze/microblaze.c: Likewise.
	* mips/mips.c: Likewise.
	* mmix/mmix.c: Likewise.
	* mn10300/mn10300.c: Likewise.
	* moxie/moxie.c: Likewise.
	* msp430/msp430.c: Likewise.
	* nds32/nds32.c: Likewise.
	* pa/pa.c: Likewise.
	* pdp11/pdp11.c: Likewise.
	* picochip/picochip.c: Likewise.
	* rl78/rl78.c: Likewise.
	* rs6000/rs6000.c: Likewise.
	* rx/rx.c: Likewise.
	* s390/s390.c: Likewise.
	* score/score.c: Likewise.
	* sh/sh.c: Likewise.
	* sparc/sparc.c: Likewise.
	* spu/spu.c: Likewise.
	* stormy16/stormy16.c: Likewise.
	* tilegx/tilegx.c: Likewise.
	* tilepro/tilepro.c: Likewise.
	* v850/v850.c: Likewise.
	* vax/vax.c: Likewise.
	* xtensa/xtensa.c: Likewise.

Index: asan.c
===
*** asan.c	(revision 211131)
--- asan.c	(working copy)
*** along with GCC; see the file COPYING3.
*** 54,59 
--- 54,60 
  #include "ubsan.h"
  #include "predict.h"
  #include "params.h"
+ #include "builtins.h"
  
  /* AddressSanitizer finds out-of-bounds and use-after-free bugs
 with <2x slowdown on average.
Index: cfgexpand.c
===
*** cfgexpand.c	(revision 211131)
--- cfgexpand.c	(working copy)
*** along with GCC; see the file COPYING3.
*** 73,78 
--- 73,79 
  #include "tree-ssa-address.h"
  #include "recog.h"
  #include "output.h"
+ #include "builtins.h"
  
  /* Some systems use __main in a way incompatible with its use in gcc, in these
 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
Index: convert.c
===
*** convert.c	(revision 211131)
--- convert.c	(working copy)
*** along with GCC; see the file COPYING3.
*** 32,37 
--- 32,38 
  #include "diagnostic-core.h"
  #include "target.h"
  #include "langhooks.h"
+ #include "builtins.h"
  #include "ubsan.h"
  
  /* Convert EXPR to some pointer or reference type TYPE.
Index: emit-rtl.c
===
*** emit-rtl.c	(revision 211131)
--- emit-rtl.c	(working copy)
*** along with GCC; see the file COPYING3.
*** 57,62 
--- 57,63 
  #include "df.h"
  #include "params.h"
  #include "target.h"
+ #include "builtins.h"
  
  struct target_rtl default_target_rtl;
  #if SWITCHABLE_TARGET
Index: except.c
===
*** except.c	(revision 211131)
--- except.c	(working copy)
*** along with GCC; see the file COPYING3.
*** 141,146 
--- 141,147 
  #include "tree-pass.h"
  #include "pointer-set.h"
  #include "cfgloop.h"
+ #include "builtins.h"
  
  /* Provide defaults for stuff that may not be defined when using
 sjlj exceptions.  */
Index: expr.c
===
*** expr.c	(r

Patch for builtins.h restructuring [1/2]

2014-06-02 Thread Andrew MacLeod
Furthering the include file restructuring, this patch fixes the header 
files for builtins.h. The prototypes were spread between tree.h, expr.h 
and fold-const.h.


 * There were 5 build_* routines in builtins.c that really should be in 
tree.c. They are used all over the place.  The prototypes were already 
in tree.h.
 * There were 3 routines in builtins.c that belonged in targhooks.c.  
The prototypes were already in targhooks.h


* fold-const.c uses do_mpc_arg2() which is defined in builtins.c, so the 
prototype should be in builtins.h. The prototype utilizes type 
mpc_srcptr from  which means that every file which includes 
builtins.h would also require #include . That is likely the 
reason the prototype was placed into realmpfr.h.  I added #include 
 to builtins.h.  Normally we're trying not to do that until we 
can rebuild a decent module structure, but I think that rule only makes 
sense for include files within gcc's source base...


* Finally, fortran/trans.c was calling fold_builtin_call_array directly. 
That means it would have needed builtins.h which caused issues since 
builtins.h defines struct target_builtins and uses 
FIRST_PSEUDO_REGISTER... which is defined within the target config 
file... something I dont think we really want to expose to the fortran 
front end :-P.  Anyway, looking aorund, it turns out 
fold-const.c::fold_build_call_array_loc is really a wrapper for a call 
to fold_builtin_call_array, with some extra checking code before and 
after the call protected by ENABLE_FOLD_CHECKING.  I'd think that should 
be OK since its what other front ends call...


Bootstraps on x86_64-unknown-linux-gnu with no regressions. I also ran 
it through a full set of target builds for compilation, with no new 
failures there.


The second set of patches are the updated #includes required for 
compilation.


OK for trunk?

Andrew


	* expr.h: Remove prototypes of functions defined in builtins.c.
	* tree.h: (build_call_expr_*, build_string_literal): Add prototypes.
	Remove prototypes of functions defined in builtins.c.
	* builtins.h: Update prototype list to include all exported functions.
	* builtins.c: (default_libc_has_function, gnu_libc_has_function,
	no_c99_libc_has_function): Move to targhooks.c
	(build_string_literal, build_call_expr_loc_array,
	build_call_expr_loc_vec, build_call_expr_loc, build_call_expr): Move
	to tree.c.
	(expand_builtin_object_size, fold_builtin_object_size): Make static.
	* targhooks.c (default_libc_has_function, gnu_libc_has_function,
	no_c99_libc_has_function): Relocate from builtins.c.
	* tree.c: Include builtins.h.
	(build_call_expr_loc_array, build_call_expr_loc_vec,
	build_call_expr_loc, build_call_expr, build_string_literal): Relocate
	from builtins.c.
	* fold-const.h (fold_fma): Move prototype to builtins.h.
	* realmpfr.h (do_mpc_arg2): Move prototype to builtins.h.

	* fortran/trans.c (trans_runtime_error_vararg): Call
	fold_build_call_array_loc instead of fold_builtin_call_array.

Index: expr.h
===
*** expr.h	(revision 211131)
--- expr.h	(working copy)
*** extern unsigned HOST_WIDE_INT choose_mul
*** 252,271 
  		 int, unsigned HOST_WIDE_INT *,
  		 int *, int *);
  
- /* Functions from builtins.c:  */
- extern rtx expand_builtin (tree, rtx, rtx, enum machine_mode, int);
- extern tree std_build_builtin_va_list (void);
- extern tree std_fn_abi_va_list (tree);
- extern tree std_canonical_va_list_type (tree);
- 
- extern void std_expand_builtin_va_start (tree, rtx);
- extern rtx default_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
- extern void expand_builtin_setjmp_setup (rtx, rtx);
- extern void expand_builtin_setjmp_receiver (rtx);
- extern rtx expand_builtin_saveregs (void);
- extern void expand_builtin_trap (void);
- extern rtx builtin_strncpy_read_str (void *, HOST_WIDE_INT, enum machine_mode);
- 
  /* Functions from expr.c:  */
  
  /* This is run during target initialization to set up which modes can be
--- 252,257 
Index: tree.h
===
*** tree.h	(revision 211131)
--- tree.h	(working copy)
*** extern tree build_call_valist (tree, tre
*** 3624,3629 
--- 3624,3634 
 build_call_array_loc (UNKNOWN_LOCATION, T1, T2, N, T3)
  extern tree build_call_array_loc (location_t, tree, tree, int, const tree *);
  extern tree build_call_vec (tree, tree, vec *);
+ extern tree build_call_expr_loc_array (location_t, tree, int, tree *);
+ extern tree build_call_expr_loc_vec (location_t, tree, vec *);
+ extern tree build_call_expr_loc (location_t, tree, int, ...);
+ extern tree build_call_expr (tree, int, ...);
+ extern tree build_string_literal (int, const char *);
  
  /* Construct various nodes representing data types.  */
  
*** extern tree get_inner_reference (tree, H
*** 4745,4790 
 EXP, an ARRAY_REF or an ARRAY_RANGE_REF.  */
  extern tree array_ref_low_bound

[PATCH, Pointer Bounds Checker 21/x] Weakrefs output

2014-06-02 Thread Ilya Enkovich
Hi,

This patch prevents output of both instrumented and not instrumented weakref 
variants.

Thanks,
Ilya
--
gcc/

2014-06-02  Ilya Enkovich  

* cgraphunit.c (output_weakrefs): If there are both
instrumented and original versions, output only one
of them.


diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c
index c5c..ae9e699 100644
--- a/gcc/cgraphunit.c
+++ b/gcc/cgraphunit.c
@@ -2111,9 +2111,13 @@ static void
 output_weakrefs (void)
 {
   symtab_node *node;
+  cgraph_node *cnode;
   FOR_EACH_SYMBOL (node)
 if (node->alias
 && !TREE_ASM_WRITTEN (node->decl)
+   && (!(cnode = dyn_cast  (node))
+   || !cnode->instrumented_version
+   || !TREE_ASM_WRITTEN (cnode->instrumented_version->decl))
&& node->weakref)
   {
tree target;


Re: [C/C++ PATCH] Add -Wlogical-not-parentheses (PR c/49706)

2014-06-02 Thread Marek Polacek
On Mon, Jun 02, 2014 at 10:08:24AM -0400, Jason Merrill wrote:
> On 06/02/2014 02:50 AM, Marek Polacek wrote:
> >+  && TREE_CODE (arg1.value) == EQ_EXPR)
> ...
> >+  && TREE_CODE (current.lhs) == EQ_EXPR
> 
> It seems like your version only warns about ==, while the clang version
> warns about all comparisons.
 
Actually it warns about all tcc_comparison cases; the reason for EQ_EXPR
checks above was that we convert the LHS from e.g. "!x" into "x == 0"
(at least in the C FE this is done in c_objc_common_truthvalue_conversion
+ invert_truthvalue), so I checked that.  But it's useless, so I dropped
those checks.

> >+  && (complain_flags (decltype_p) & tf_warning)
> 
> Let's not call complain_flags multiple times in the function.  In fact this
> will always be true, so you could just drop it.
 
Good, I dropped that check too.

> >Also for C++, I think we don't want this warning to trigger when the
> >operator (==, !=, >, <, <=, >=) is overloaded.  But I admit
> >I haven't even tried that, and I don't know how to detect overloaded
> >operators except DECL_OVERLOADED_OPERATOR_P.
> 
> Overloaded operators have the same precedence, so I think it's appropriate
> to give the warning whether or not the operators are overloaded.

Thanks.

2014-06-02  Marek Polacek  

PR c/49706
* doc/invoke.texi: Document -Wlogical-not-parentheses.
c-family/
* c-common.c (warn_logical_not_parentheses): New function.
* c-common.h (warn_logical_not_parentheses): Declare.
* c.opt (Wlogical-not-parentheses): New option.
c/
* c-typeck.c (parser_build_binary_op): Warn when logical not is used
on the left hand side operand of a comparison. 
cp/
* parser.c (cp_parser_binary_expression): Warn when logical not is
used on the left hand side operand of a comparison.
testsuite/
* c-c++-common/pr49706.c: New test.

diff --git gcc/c-family/c-common.c gcc/c-family/c-common.c
index 6ec14fc..650afaf 100644
--- gcc/c-family/c-common.c
+++ gcc/c-family/c-common.c
@@ -1722,6 +1722,25 @@ warn_logical_operator (location_t location, enum 
tree_code code, tree type,
 }
 }
 
+/* Warn about logical not used on the left hand side operand of a comparison.
+   This function assumes that the LHS is inside of TRUTH_NOT_EXPR.
+   Do not warn if the LHS or RHS is of a boolean or a vector type.  */
+
+void
+warn_logical_not_parentheses (location_t location, enum tree_code code,
+ tree lhs, tree rhs)
+{
+  if (TREE_CODE_CLASS (code) != tcc_comparison
+  || TREE_CODE (TREE_TYPE (lhs)) == BOOLEAN_TYPE
+  || TREE_CODE (TREE_TYPE (rhs)) == BOOLEAN_TYPE
+  || VECTOR_TYPE_P (TREE_TYPE (lhs))
+  || VECTOR_TYPE_P (TREE_TYPE (rhs)))
+return;
+
+  warning_at (location, OPT_Wlogical_not_parentheses,
+ "logical not is only applied to the left hand side of "
+ "comparison");
+}
 
 /* Warn if EXP contains any computations whose results are not used.
Return true if a warning is printed; false otherwise.  LOCUS is the
diff --git gcc/c-family/c-common.h gcc/c-family/c-common.h
index 0d34004..83d5dee 100644
--- gcc/c-family/c-common.h
+++ gcc/c-family/c-common.h
@@ -772,6 +772,8 @@ extern void overflow_warning (location_t, tree);
 extern bool warn_if_unused_value (const_tree, location_t);
 extern void warn_logical_operator (location_t, enum tree_code, tree,
   enum tree_code, tree, enum tree_code, tree);
+extern void warn_logical_not_parentheses (location_t, enum tree_code, tree,
+ tree);
 extern void check_main_parameter_types (tree decl);
 extern bool c_determine_visibility (tree);
 extern bool vector_types_compatible_elements_p (tree, tree);
diff --git gcc/c-family/c.opt gcc/c-family/c.opt
index c586e65..d51c890 100644
--- gcc/c-family/c.opt
+++ gcc/c-family/c.opt
@@ -490,6 +490,10 @@ Wlogical-op
 C ObjC C++ ObjC++ Var(warn_logical_op) Init(0) Warning 
 Warn when a logical operator is suspiciously always evaluating to true or false
 
+Wlogical-not-parentheses
+C ObjC C++ ObjC++ Var(warn_logical_not_paren) Warning
+Warn when logical not is used on the left hand side operand of a comparison
+
 Wlong-long
 C ObjC C++ ObjC++ Var(warn_long_long) Init(-1) Warning
 Do not warn about using \"long long\" when -pedantic
diff --git gcc/c/c-typeck.c gcc/c/c-typeck.c
index 6ca584b..e98224e 100644
--- gcc/c/c-typeck.c
+++ gcc/c/c-typeck.c
@@ -3401,6 +3401,10 @@ parser_build_binary_op (location_t location, enum 
tree_code code,
 warn_logical_operator (location, code, TREE_TYPE (result.value),
   code1, arg1.value, code2, arg2.value);
 
+  if (warn_logical_not_paren
+  && code1 == TRUTH_NOT_EXPR)
+warn_logical_not_parentheses (location, code, arg1.value, arg2.value);
+
   /* Warn about comparisons against string literals, with the exception
  of testing for equality or inequality of a string literal with NULL.  */
   if

[PATCH, Pointer Bounds Checker 20/x] Follow transparent alias chains

2014-06-02 Thread Ilya Enkovich
Hi,

In the most case we follow transparent alias chains wne assemble names.  But in 
some cases it is not performed.  For instrumented functions it is critical and 
following patch fixes that.  It also adds a visibility inheritance for 
instrtumented functions.

Bootstrapped and tested on linux-x86_64.

Thanks,
Ilya
--
gcc/

2014-06-02  Ilya Enkovich  

* varasm.c: Include tree-chkp.h.
(ultimate_transparent_alias_target): Move up.
(make_decl_rtl): For instrumented function use
name of the original decl.
(assemble_start_function): Mark function as global
in case it is instrumentation clone of the global
function.
(do_assemble_alias): Follow transparent alias chain
for identifier.  Check if original alias is public.
(maybe_assemble_visibility): Use visibility of the
original function for instrumented version.
(default_unique_section): Likewise.


diff --git a/gcc/varasm.c b/gcc/varasm.c
index fcae2fa..d473bc7 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -54,6 +54,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "pointer-set.h"
 #include "asan.h"
 #include "basic-block.h"
+#include "tree-chkp.h"
 
 #ifdef XCOFF_DEBUGGING_INFO
 #include "xcoffout.h"  /* Needed for external data
@@ -1200,6 +1201,30 @@ use_blocks_for_decl_p (tree decl)
   return targetm.use_blocks_for_decl_p (decl);
 }
 
+/* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
+   until we find an identifier that is not itself a transparent alias.
+   Modify the alias passed to it by reference (and all aliases on the
+   way to the ultimate target), such that they do not have to be
+   followed again, and return the ultimate target of the alias
+   chain.  */
+
+static inline tree
+ultimate_transparent_alias_target (tree *alias)
+{
+  tree target = *alias;
+
+  if (IDENTIFIER_TRANSPARENT_ALIAS (target))
+{
+  gcc_assert (TREE_CHAIN (target));
+  target = ultimate_transparent_alias_target (&TREE_CHAIN (target));
+  gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target)
+ && ! TREE_CHAIN (target));
+  *alias = target;
+}
+
+  return target;
+}
+
 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL.  DECL should
have static storage duration.  In other words, it should not be an
automatic variable, including PARM_DECLs.
@@ -1214,6 +1239,7 @@ make_decl_rtl (tree decl)
 {
   const char *name = 0;
   int reg_number;
+  tree id;
   rtx x;
 
   /* Check that we are not being given an automatic variable.  */
@@ -1271,7 +1297,12 @@ make_decl_rtl (tree decl)
   return;
 }
 
-  name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
+  id = DECL_ASSEMBLER_NAME (decl);
+  if (TREE_CODE (decl) == FUNCTION_DECL
+  && cgraph_get_node (decl)
+  && cgraph_get_node (decl)->instrumentation_clone)
+ultimate_transparent_alias_target (&id);
+  name = IDENTIFIER_POINTER (id);
 
   if (name[0] != '*' && TREE_CODE (decl) != FUNCTION_DECL
   && DECL_REGISTER (decl))
@@ -1699,7 +1730,10 @@ assemble_start_function (tree decl, const char *fnname)
 
   /* Make function name accessible from other files, if appropriate.  */
 
-  if (TREE_PUBLIC (decl))
+  if (TREE_PUBLIC (decl)
+  || (cgraph_get_node (decl)->instrumentation_clone
+ && cgraph_get_node (decl)->instrumented_version
+ && TREE_PUBLIC (cgraph_get_node (decl)->instrumented_version->decl)))
 {
   notice_global_symbol (decl);
 
@@ -2386,30 +2420,6 @@ mark_decl_referenced (tree decl)
 }
 
 
-/* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
-   until we find an identifier that is not itself a transparent alias.
-   Modify the alias passed to it by reference (and all aliases on the
-   way to the ultimate target), such that they do not have to be
-   followed again, and return the ultimate target of the alias
-   chain.  */
-
-static inline tree
-ultimate_transparent_alias_target (tree *alias)
-{
-  tree target = *alias;
-
-  if (IDENTIFIER_TRANSPARENT_ALIAS (target))
-{
-  gcc_assert (TREE_CHAIN (target));
-  target = ultimate_transparent_alias_target (&TREE_CHAIN (target));
-  gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target)
- && ! TREE_CHAIN (target));
-  *alias = target;
-}
-
-  return target;
-}
-
 /* Output to FILE (an assembly file) a reference to NAME.  If NAME
starts with a *, the rest of NAME is output verbatim.  Otherwise
NAME is transformed in a target-specific way (usually by the
@@ -5544,6 +5554,9 @@ vec *alias_pairs;
 void
 do_assemble_alias (tree decl, tree target)
 {
+  tree orig_decl = decl;
+  tree id;
+
   /* Emulated TLS had better not get this var.  */
   gcc_assert (!(!targetm.have_tls
&& TREE_CODE (decl) == VAR_DECL
@@ -5552,12 +5565,21 @@ do_assemble_alias (tree decl, tree target)
   if (TREE_ASM_WRITTEN (decl))
 return;
 
+  if (TREE_CODE (decl) == FUNCTION_DECL
+  && cgrap

Re: [PATCH, Pointer Bounds Checker 14/x] Pointer Bounds Checker passes

2014-06-02 Thread Ilya Enkovich
2014-06-02 17:37 GMT+04:00 Richard Biener :
> On Mon, Jun 2, 2014 at 2:44 PM, Ilya Enkovich  wrote:
>> 2014-06-02 15:35 GMT+04:00 Richard Biener :
>>> On Fri, May 30, 2014 at 2:25 PM, Ilya Enkovich  
>>> wrote:
 Hi,

 This patch adds Pointer Bounds Checker passes.  Versioning happens before 
 early local passes.  Earply local passes are split into 3 stages to have 
 everything instrumented before any optimization applies.
>>>
>>> That looks artificial to me.  If you need to split up early_local_passes
>>> then do that - nesting three IPA pass groups inside it looks odd to me.
>>> Btw - doing this in three "IPA phases" makes things possibly slower
>>> due to cache effects.  It might be worth pursuing to move the early
>>> stage completely to the lowering pipeline.
>>
>> Early local passes is some special case because these passes are
>> executed separately for new functions. I did not want to get three
>> special passes instead and therefore made split inside.
>
> Yeah, but all passes are already executed via execute_early_local_passes,
> so it would be only an implementation detail.
>
>> If you prefer split pass itself, I suppose pass_early_local_passes may
>> be replaced with something like pass_build_ssa_passes +
>> pass_chkp_instrumentation_passes + pass_ipa_chkp_produce_thunks +
>> pass_local_optimization_passes. execute_early_local_passes would
>> execute gimple passes lists of pass_build_ssa_passes,
>> pass_chkp_instrumentation_passes and pass_local_optimization_passes.
>>
>> I think we cannot have the first stage moved into lowering passes
>> because it should be executed for newly created functions.
>
> Well, let's defer that then.
>
>>>
>>> Btw, fixup_cfg only needs to run once local_pure_const was run
>>> on a callee, thus it shouldn't be neccessary to run it from the
>>> first group.
>>
>> OK. Will try to remove it from the first group.
>>
>>>
>>>  void
>>>  pass_manager::execute_early_local_passes ()
>>>  {
>>> -  execute_pass_list (pass_early_local_passes_1->sub);
>>> +  execute_pass_list (pass_early_local_passes_1->sub->sub);
>>> +  execute_pass_list (pass_early_local_passes_1->sub->next->sub);
>>> +  execute_pass_list 
>>> (pass_early_local_passes_1->sub->next->next->next->sub);
>>>  }
>>>
>>> is gross - it should be enough to execute the early local pass list
>>> (obsolete comment with the suggestion above).
>>
>> This function should call only gimple passes for cfun. Therefore we
>> cannot call IPA passes here and has to execute each gimple passes list
>> separately.
>
> Ok, given a different split this would then become somewhat more sane
> anyway.

Sorry, didn't catch it. Should I try a different split or defer it? :)

Ilya

>
> Richard.
>
>> Ilya
>>>
>>> Richard.
>>>
 Bootstrapped and tested on linux-x86_64.

 Thanks,
 Ilya
 --
 gcc/

 2014-05-29  Ilya Enkovich  

 * tree-chkp.c: New.
 * tree-chkp.h: New.
 * rtl-chkp.c: New.
 * rtl-chkp.h: New.
 * Makefile.in (OBJS): Add tree-chkp.o, rtl-chkp.o.
 (GTFILES): Add tree-chkp.c.
 * c-family/c.opt (fchkp-check-incomplete-type): New.
 (fchkp-zero-input-bounds-for-main): New.
 (fchkp-first-field-has-own-bounds): New.
 (fchkp-narrow-bounds): New.
 (fchkp-narrow-to-innermost-array): New.
 (fchkp-optimize): New.
 (fchkp-use-fast-string-functions): New.
 (fchkp-use-nochk-string-functions): New.
 (fchkp-use-static-bounds): New.
 (fchkp-use-static-const-bounds): New.
 (fchkp-treat-zero-dynamic-size-as-infinite): New.
 (fchkp-check-read): New.
 (fchkp-check-write): New.
 (fchkp-store-bounds): New.
 (fchkp-instrument-calls): New.
 (fchkp-instrument-marked-only): New.
 * cppbuiltin.c (define_builtin_macros_for_compilation_flags): Add
 __CHKP__ macro when Pointer Bounds Checker is on.
 * passes.def (pass_ipa_chkp_versioning): New.
 (pass_before_local_optimization_passes): New.
 (pass_chkp_instrumentation_passes): New.
 (pass_ipa_chkp_produce_thunks): New.
 (pass_local_optimization_passes): New.
 (pass_chkp_opt): New.
 * toplev.c: include tree-chkp.h.
 (compile_file): Add chkp_finish_file call.
 * tree-pass.h (make_pass_ipa_chkp_versioning): New.
 (make_pass_ipa_chkp_produce_thunks): New.
 (make_pass_chkp): New.
 (make_pass_chkp_opt): New.
 (make_pass_before_local_optimization_passes): New.
 (make_pass_chkp_instrumentation_passes): New.
 (make_pass_local_optimization_passes): New.
 * tree.h (called_as_built_in): New.
 * builtins.c (called_as_built_in): Not static anymore.
 * passes.c (pass_manager::execute

Re: [C++11, C++14 PATCH 2/3] Support for SD-6: SG10 Feature Test Recommendations - c-family and testsuite

2014-06-02 Thread Ed Smith-Rowland

On 06/02/2014 10:31 AM, Jason Merrill wrote:

On 05/31/2014 02:30 AM, Marc Glisse wrote:

Also, I am pretty sure that gcc doesn't support the latest constexpr, we
shouldn't define those macros lightly.


That's correct.  We should leave __cpp_constexpr at 200704 for now.
Right...  That was a testing thing I left in by accident to make sure 
supercedance would work.  Commented out. ;-)



I think having __has_include for all languages is fine since it is
already in the implementation defined namespace.


Agreed.  These macros should be defined if the feature is supported.

I now have these for all C/C++ versions.  When I implemented these I 
thought "Why the heck hasn't the preprocessor had these for 20 years..."
Similarly, features of later standards that we implement in earlier 
conformance modes as extensions (specifically, init-captures and 
binary literals) should have the appropriate macros defined.

Very good idea...
I'll research these. unless someone has a little list somewhere...?


Jason






[PATCH, Pointer Bounds Checker 19/x] Support bounds in expand

2014-06-02 Thread Ilya Enkovich
Hi,

This patch adds support for input bounds, call bounds args and returned bounds 
in expand pass.

Bootstrapped and tested on linux-x86_64.

Thanks,
Ilya
--
gcc/

2014-06-02  Ilya Enkovich  

* calls.c: Include tree-chkp.h, rtl-chkp.h.
(arg_data): Add fields special_slot, pointer_arg and
pointer_offset.
(store_bounds): New.
(emit_call_1): Propagate instrumentation flag for CALL.
(initialize_argument_information): Compute pointer_arg,
pointer_offset and special_slot for pointer bounds arguments.
(finalize_must_preallocate): Preallocate when storing bounds
in bounds table.
(compute_argument_addresses): Skip pointer bounds.
(expand_call): Store bounds into tables separately.  Return
result joined with resulting bounds.
* cfgexpand.c: Include tree-chkp.h, rtl-chkp.h.
(expand_call_stmt): Propagate bounds flag for CALL_EXPR.
(expand_return): Add returned bounds arg.  Handle returned bounds.
(expand_gimple_stmt_1): Adjust to new expand_return signature.
(gimple_expand_cfg): Reset rtx bounds map.
* expr.h (store_expr): Add param for bounds target.
* expr.c: Include tree-chkp.h, rtl-chkp.h.
(expand_assignment): Handle returned bounds.
(store_expr): Add bounds target argument.  Handle
bounds returned by calls.
(store_constructor): Adjust to new store_expr signature.
(store_field): Likewise.
(expand_expr_real_2): Likewise.
(expand_expr_real_1): Likewise.
* function.c: Include tree-chkp.h, rtl-chkp.h.
(bounds_parm_data): New.
(use_register_for_decl): Do not registerize decls used for bounds
stores and loads.
(assign_parms_augmented_arg_list): Add bounds of the result
structure pointer as the second argument.
(assign_parm_find_entry_rtl): Mark bounds are never passed on
the stack.
(assign_parm_is_stack_parm): Likewise.
(assign_parm_load_bounds): New.
(assign_bounds): New.
(assign_parms): Load bounds and determine a location for
returned bounds.
(diddle_return_value_1): New.
(diddle_return_value): Handle returned bounds.
* function.h (rtl_data): Add field for returned bounds.
* tree-outof-ssa.c (insert_value_copy_on_edge): Adjust to new
store_expr signature.


diff --git a/gcc/calls.c b/gcc/calls.c
index e1dc8eb..140ceb4 100644
--- a/gcc/calls.c
+++ b/gcc/calls.c
@@ -44,11 +44,14 @@ along with GCC; see the file COPYING3.  If not see
 #include "tm_p.h"
 #include "timevar.h"
 #include "sbitmap.h"
+#include "bitmap.h"
 #include "langhooks.h"
 #include "target.h"
 #include "cgraph.h"
 #include "except.h"
 #include "dbgcnt.h"
+#include "tree-chkp.h"
+#include "rtl-chkp.h"
 
 /* Like PREFERRED_STACK_BOUNDARY but in units of bytes, not bits.  */
 #define STACK_BYTES (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT)
@@ -76,6 +79,15 @@ struct arg_data
   /* If REG is a PARALLEL, this is a copy of VALUE pulled into the correct
  form for emit_group_move.  */
   rtx parallel_value;
+  /* If value is passed in neither reg nor stack, this field holds a number
+ of a special slot to be used.  */
+  rtx special_slot;
+  /* For pointer bounds hold an index of parm bounds are bound to.  -1 if
+ there is no such pointer.  */
+  int pointer_arg;
+  /* If pointer_arg refers a structure, then pointer_offset holds an offset
+ of a pointer in this structure.  */
+  int pointer_offset;
   /* If REG was promoted from the actual mode of the argument expression,
  indicates whether the promotion is sign- or zero-extended.  */
   int unsignedp;
@@ -133,6 +145,7 @@ static void emit_call_1 (rtx, tree, tree, tree, 
HOST_WIDE_INT, HOST_WIDE_INT,
 HOST_WIDE_INT, rtx, rtx, int, rtx, int,
 cumulative_args_t);
 static void precompute_register_parameters (int, struct arg_data *, int *);
+static void store_bounds (struct arg_data *, struct arg_data *);
 static int store_one_arg (struct arg_data *, rtx, int, int, int);
 static void store_unaligned_arguments_into_pseudos (struct arg_data *, int);
 static int finalize_must_preallocate (int, int, struct arg_data *,
@@ -396,6 +409,10 @@ emit_call_1 (rtx funexp, tree fntree ATTRIBUTE_UNUSED, 
tree fndecl ATTRIBUTE_UNU
   && MEM_EXPR (funmem) != NULL_TREE)
 set_mem_expr (XEXP (call, 0), MEM_EXPR (funmem));
 
+  /* Mark instrumented calls.  */
+  if (call && fntree)
+CALL_EXPR_WITH_BOUNDS_P (call) = CALL_WITH_BOUNDS_P (fntree);
+
   /* Put the register usage information there.  */
   add_function_usage_to (call_insn, call_fusage);
 
@@ -1141,18 +1158,84 @@ initialize_argument_information (int num_actuals 
ATTRIBUTE_UNUSED,
   /* First fill in the actual arguments in the ARGS array, splitting
  complex arguments if necessary.  */
   {
-int j = i;
+int j = i, ptr_arg = -1;
 call_ex

[PATCH, i386, Pointer Bounds Checker 18/x] Expand instrumented builtin function calls

2014-06-02 Thread Ilya Enkovich
Hi,

This patch adds support for normal builtin function calls (target ones are not 
instrumented).  The basic idea of the patch is to make call expr copy with no 
bounds and expand it instead.  If expr is going to be emitted as a function 
call then original instrumented expr takes place.  Handle string function 
separately because they are of high interest for the checker.

Bootstrapped and tested on linux-x86_64.

Thanks,
Ilya
--
gcc/

2014-06-02  Ilya Enkovich  

* builtins.c: Include rtl-chkp.h, tree-chkp.h.
(expand_builtin_mempcpy_args): Add orig exp as argument.
Support BUILT_IN_CHKP_MEMPCPY_NOBND_NOCHK.
(expand_builtin_mempcpy): Adjust expand_builtin_mempcpy_args call.
(expand_builtin_stpcpy): Likewise.
(expand_builtin_memset_args): Support BUILT_IN_CHKP_MEMSET_NOBND_NOCHK.
(std_expand_builtin_va_start): Initialize bounds for va_list.
(expand_builtin): Support instrumented calls.


diff --git a/gcc/builtins.c b/gcc/builtins.c
index 7357124..c0140e1 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -59,6 +59,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "builtins.h"
 #include "ubsan.h"
 #include "cilk.h"
+#include "tree-chkp.h"
+#include "rtl-chkp.h"
 
 
 static tree do_mpc_arg1 (tree, tree, int (*)(mpc_ptr, mpc_srcptr, mpc_rnd_t));
@@ -124,7 +126,7 @@ static rtx builtin_memcpy_read_str (void *, HOST_WIDE_INT, 
enum machine_mode);
 static rtx expand_builtin_memcpy (tree, rtx);
 static rtx expand_builtin_mempcpy (tree, rtx, enum machine_mode);
 static rtx expand_builtin_mempcpy_args (tree, tree, tree, rtx,
-   enum machine_mode, int);
+   enum machine_mode, int, tree);
 static rtx expand_builtin_strcpy (tree, rtx);
 static rtx expand_builtin_strcpy_args (tree, tree, rtx);
 static rtx expand_builtin_stpcpy (tree, rtx, enum machine_mode);
@@ -3284,7 +3286,8 @@ expand_builtin_mempcpy (tree exp, rtx target, enum 
machine_mode mode)
   tree src = CALL_EXPR_ARG (exp, 1);
   tree len = CALL_EXPR_ARG (exp, 2);
   return expand_builtin_mempcpy_args (dest, src, len,
- target, mode, /*endp=*/ 1);
+ target, mode, /*endp=*/ 1,
+ exp);
 }
 }
 
@@ -3296,10 +3299,23 @@ expand_builtin_mempcpy (tree exp, rtx target, enum 
machine_mode mode)
 
 static rtx
 expand_builtin_mempcpy_args (tree dest, tree src, tree len,
-rtx target, enum machine_mode mode, int endp)
+rtx target, enum machine_mode mode, int endp,
+tree orig_exp)
 {
+  tree fndecl = get_callee_fndecl (orig_exp);
+
 /* If return value is ignored, transform mempcpy into memcpy.  */
-  if (target == const0_rtx && builtin_decl_implicit_p (BUILT_IN_MEMCPY))
+  if (target == const0_rtx
+  && DECL_FUNCTION_CODE (fndecl) == BUILT_IN_CHKP_MEMPCPY_NOBND_NOCHK
+  && builtin_decl_implicit_p (BUILT_IN_CHKP_MEMCPY_NOBND_NOCHK))
+{
+  tree fn = builtin_decl_implicit (BUILT_IN_CHKP_MEMCPY_NOBND_NOCHK);
+  tree result = build_call_nofold_loc (UNKNOWN_LOCATION, fn, 3,
+  dest, src, len);
+  return expand_expr (result, target, mode, EXPAND_NORMAL);
+}
+  else if (target == const0_rtx
+  && builtin_decl_implicit_p (BUILT_IN_MEMCPY))
 {
   tree fn = builtin_decl_implicit (BUILT_IN_MEMCPY);
   tree result = build_call_nofold_loc (UNKNOWN_LOCATION, fn, 3,
@@ -3484,7 +3500,8 @@ expand_builtin_stpcpy (tree exp, rtx target, enum 
machine_mode mode)
 
   lenp1 = size_binop_loc (loc, PLUS_EXPR, len, ssize_int (1));
   ret = expand_builtin_mempcpy_args (dst, src, lenp1,
-target, mode, /*endp=*/2);
+target, mode, /*endp=*/2,
+exp);
 
   if (ret)
return ret;
@@ -3778,7 +3795,8 @@ expand_builtin_memset_args (tree dest, tree val, tree len,
  do_libcall:
   fndecl = get_callee_fndecl (orig_exp);
   fcode = DECL_FUNCTION_CODE (fndecl);
-  if (fcode == BUILT_IN_MEMSET)
+  if (fcode == BUILT_IN_MEMSET
+  || fcode == BUILT_IN_CHKP_MEMSET_NOBND_NOCHK)
 fn = build_call_nofold_loc (EXPR_LOCATION (orig_exp), fndecl, 3,
dest, val, len);
   else if (fcode == BUILT_IN_BZERO)
@@ -4330,6 +4348,13 @@ std_expand_builtin_va_start (tree valist, rtx nextarg)
 {
   rtx va_r = expand_expr (valist, NULL_RTX, VOIDmode, EXPAND_WRITE);
   convert_move (va_r, nextarg, 0);
+
+  /* We do not have any valid bounds for the pointer, so
+ just store zero bounds for it.  */
+  if (chkp_function_instrumented_p (current_function_decl))
+chkp_expand_bounds_reset_for_mem (valist,
+ make_tree (TREE_TYPE (valist),
+  

Re: [C++11, C++14 PATCH 2/3] Support for SD-6: SG10 Feature Test Recommendations - c-family and testsuite

2014-06-02 Thread Jason Merrill

On 05/31/2014 02:30 AM, Marc Glisse wrote:

Also, I am pretty sure that gcc doesn't support the latest constexpr, we
shouldn't define those macros lightly.


That's correct.  We should leave __cpp_constexpr at 200704 for now.


I think having __has_include for all languages is fine since it is
already in the implementation defined namespace.


Agreed.  These macros should be defined if the feature is supported.

Similarly, features of later standards that we implement in earlier 
conformance modes as extensions (specifically, init-captures and binary 
literals) should have the appropriate macros defined.


Jason



Re: [PATCH 3/4] New attribute lookup function addition

2014-06-02 Thread Martin Liška


On 05/30/2014 06:37 PM, Jeff Law wrote:

On 05/30/14 00:49, Martin Liška wrote:

Hi,
this patch introduces a new function lookup_attribute_starting that
can find all attributes starting with a specified string. Purpose of the
function is to be able to identify e.g. if a function has any 'omp'
attribute.

Bootstrapped and tested on x86_64-linux.
OK for trunk?

Thanks,
Martin

2014-05-29  Martin Liska  

 * tree.h (private_lookup_attribute_starting): New function.
 (lookup_attribute_starting): Likewise.
 * tree.c (private_lookup_attribute_starting): Likewise.

private_lookup_attribute_starting needs a block comment.


Added.




+tree
+private_lookup_attribute_starting (const char *attr_name, size_t
attr_len, tree list)

Long line needs to be wrapped?   Please review the patch for lines that need 
wrapping at 80 columns.

Fixed too.


So it's really a lookup by prefix, so I'd probably use a name like
lookup_attribute_by_prefix.  Why "private_" in the function name?

I used the same construction as for function 'private_is_attribute_p'; I hope 
the construction is fine?



It appears it just returns the first attribute from LIST with the given prefix. 
 Presumably you use it iteratively.


+/* Given an attribute name ATTR_NAME and a list of attributes LIST,
+   return a pointer to the attribute's list element if the attribute
+   starts with ATTR_NAME. ATTR_NAME must be in the form 'text' (not
+   '__text__').  */
+
+static inline tree
+lookup_attribute_starting (const char *attr_name, tree list)
+{
+  gcc_checking_assert (attr_name[0] != '_');
+  /* In most cases, list is NULL_TREE.  */
+  if (list == NULL_TREE)
+return NULL_TREE;
+  else
+return private_lookup_attribute_starting (attr_name, strlen
(attr_name), list);
+}

So again, I prefer "prefix" rather than "starting".  Similarly this is meant to 
be called iteratively since you only get the first attribute with the given prefix, right?

I added a comment that it returns just such first argument.

Is the reworked patch OK for trunk?

Martin


OK with the nit fixes mentioned above.


Jeff


>From be3ab469ee70ff3de434f5326c1a2eabf07da3ed Mon Sep 17 00:00:00 2001
Message-Id: 
In-Reply-To: 
References: 
From: mliska 
Date: Thu, 29 May 2014 17:18:34 +0200
Subject: [PATCH 3/4] New attribute lookup function addition
To: gcc-patches@gcc.gnu.org

Hi,
   this patch introduces a new function lookup_attribute_starting that can find all attributes starting with a specified string. Purpose of the function is to be able to identify e.g. if a function has any 'omp' attribute.

Bootstrapped and tested on x86_64-linux.
OK for trunk?

Thanks,
Martin

2014-05-29  Martin Liska  

	* tree.h (private_lookup_attribute_starting): New function.
	(lookup_attribute_starting): Likewise.
	* tree.c (private_lookup_attribute_starting): Likewise.

diff --git a/gcc/tree.c b/gcc/tree.c
index cf7e362..f983408 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -5758,6 +5758,44 @@ private_lookup_attribute (const char *attr_name, size_t attr_len, tree list)
   return list;
 }
 
+/* Given an attribute name ATTR_NAME and a list of attributes LIST,
+   return a pointer to the attribute's list first element if the attribute
+   starts with ATTR_NAME. ATTR_NAME must be in the form 'text' (not
+   '__text__').  */
+
+tree
+private_lookup_attribute_by_prefix (const char *attr_name, size_t attr_len,
+tree list)
+{
+  while (list)
+{
+  size_t ident_len = IDENTIFIER_LENGTH (get_attribute_name (list));
+
+  if (attr_len > ident_len)
+	{
+	  list = TREE_CHAIN (list);
+	  continue;
+	}
+
+  const char *p = IDENTIFIER_POINTER (get_attribute_name (list));
+
+  if (strncmp (attr_name, p, attr_len) == 0)
+	break;
+
+  /* TODO: If we made sure that attributes were stored in the
+	 canonical form without '__...__' (ie, as in 'text' as opposed
+	 to '__text__') then we could avoid the following case.  */
+  if (p[0] == '_' && p[1] == '_' &&
+	  strncmp (attr_name, p + 2, attr_len) == 0)
+	break;
+
+  list = TREE_CHAIN (list);
+}
+
+  return list;
+}
+
+
 /* A variant of lookup_attribute() that can be used with an identifier
as the first argument, and where the identifier can be either
'text' or '__text__'.
diff --git a/gcc/tree.h b/gcc/tree.h
index 9fe7360..e592280 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -3731,6 +3731,10 @@ extern tree merge_type_attributes (tree, tree);
and you should never call it directly.  */
 extern tree private_lookup_attribute (const char *, size_t, tree);
 
+/* This function is a private implementation detail
+   of lookup_attribute_by_prefix() and you should never call it directly.  */
+extern tree private_lookup_attribute_by_prefix (const char *, size_t, tree);
+
 /* Given an attribute name ATTR_NAME and a list of attributes LIST,
return a pointer to the attribute's list element if the attribute
is part of the list, or NULL_TREE if not found.  If the attribute
@@ -3753,6 +3757,24 @@ lookup_attribute

Re: [PATCH 2/4] Enhancement of call graph API

2014-06-02 Thread Martin Liška


On 05/30/2014 06:42 PM, Jeff Law wrote:

On 05/30/14 00:47, Martin Liška wrote:

Hello,
this patch enhances callgraph API to enable more precise control of
expand_thunk; another function becomes global.

Bootstrapped and tested on x86_64-linux.
OK for trunk?

Thanks,
Martin

2014-05-29  Martin Liska  

 * cgraph.h (expand_thunk): New argument added.
 (address_taken_from_non_vtable_p): New global function.
 * ipa-visibility.c (address_taken_from_non_vtable_p): Likewise.
 * cgraphclones.c (duplicate_thunk_for_node): Argument added to call.
 * cgraphunit.c (analyze_function): Likewise.
 (assemble_thunks_and_aliases): Argument added to call.
 (expand_thunk): New argument forces to produce GIMPLE thunk.

Only concern here is the location of the prototype for 
address_taken_from_non_vtable_p.  Though I guess other things form 
ipa-visibility.c are prototyped in cgraph.h.

Can you put the prototype here in cgraph.h:


/* In ipa-visibility.c */
bool cgraph_local_node_p (struct cgraph_node *);

Otherwise OK.

Real curious to see the meat of the optimization now :-)


Hello,
   thanks too. It was really a wrong place for the declaration.

Yeah, the optimization will be juicy :)

Martin



jeff





Re: [PATCH 1/4] Make coverage_compute_cfg_checksum callable with an argument

2014-06-02 Thread Martin Liška


On 05/30/2014 06:28 PM, Jeff Law wrote:

On 05/30/14 00:47, Martin Liška wrote:

Hello,
   this is a small patchset that prepares API for new IPA Identical code
folding pass. The patch adds an argument for coverage_compute_cfg_checksum.

Bootstrapped and tested on x86_64-linux.
OK for trunk?

Thanks,
Martin

2014-05-29  Martin Liska  

 * coverage.h (coverage_compute_cfg_checksum): Argument added.
 * coverage.c (coverage_compute_cfg_checksum): Likewise.
 * profile.c (branch_prob): Likewise.

The block comment for coverage_compute_cfg_checksum needs to be updated.  We're 
no longer computing the checksum for the current function (cfun), but instead 
computing the checksum for the argument FN.


Hi,
   thank you for your feedback, I've just fixed the patch and will commit soon.

Martin




Otherwise OK for the trunk.

jeff




[PATCH] Fix part of PR61383

2014-06-02 Thread Richard Biener

In comment #3 it's noted that ifcombine happily hoists possibly
trapping stmts ... oops.

Fixed like the following, bootstrap and regtest running on 
x86_64-unknown-linux-gnu.

Richard.

2014-06-02  Richard Biener  

PR tree-optimization/61383
* tree-ssa-ifcombine.c (bb_no_side_effects_p): Make sure
stmts can't trap.

* gcc.dg/torture/pr61383-1.c: New testcase.

Index: gcc/tree-ssa-ifcombine.c
===
*** gcc/tree-ssa-ifcombine.c(revision 211125)
--- gcc/tree-ssa-ifcombine.c(working copy)
*** bb_no_side_effects_p (basic_block bb)
*** 128,133 
--- 128,134 
gimple stmt = gsi_stmt (gsi);
  
if (gimple_has_side_effects (stmt)
+ || gimple_could_trap_p (stmt)
  || gimple_vuse (stmt))
return false;
  }
Index: gcc/testsuite/gcc.dg/torture/pr61383-1.c
===
*** gcc/testsuite/gcc.dg/torture/pr61383-1.c(revision 0)
--- gcc/testsuite/gcc.dg/torture/pr61383-1.c(working copy)
***
*** 0 
--- 1,35 
+ /* { dg-do run } */
+ 
+ int a, b = 1, c, d, e, f, g;
+ 
+ int
+ fn1 ()
+ {
+   int h;
+   for (;;)
+ {
+   g = b;
+   g = g ? 0 : 1 % g;
+   e = a + 1;
+   for (; d < 1; d = e)
+   {
+ if (f == 0)
+   h = 0;
+ else
+   h = 1 % f;
+ if (f < 1)
+   c = 0;
+ else if (h)
+   break;
+   }
+   if (b)
+   return 0;
+ }
+ }
+ 
+ int
+ main ()
+ {
+   fn1 ();
+   return 0;
+ }


Re: [C/C++ PATCH] Add -Wlogical-not-parentheses (PR c/49706)

2014-06-02 Thread Jason Merrill

On 06/02/2014 02:50 AM, Marek Polacek wrote:

+  && TREE_CODE (arg1.value) == EQ_EXPR)

...

+ && TREE_CODE (current.lhs) == EQ_EXPR


It seems like your version only warns about ==, while the clang version 
warns about all comparisons.



+ && (complain_flags (decltype_p) & tf_warning)


Let's not call complain_flags multiple times in the function.  In fact 
this will always be true, so you could just drop it.



Also for C++, I think we don't want this warning to trigger when the
operator (==, !=, >, <, <=, >=) is overloaded.  But I admit
I haven't even tried that, and I don't know how to detect overloaded
operators except DECL_OVERLOADED_OPERATOR_P.


Overloaded operators have the same precedence, so I think it's 
appropriate to give the warning whether or not the operators are overloaded.


Jason



Re: [PATCH] Fix PR54733 Optimize endian independent load/store

2014-06-02 Thread Christophe Lyon
On 29 May 2014 11:58, Thomas Preud'homme  wrote:
>> From: Andreas Schwab [mailto:sch...@linux-m68k.org]
>> "Thomas Preud'homme"  writes:
>>
>> > By the way, I couldn't understand how you reached the value
>> > 0x44434241. Can you explain me?
>>
>> Each byte is composed of the first 7 bits of the original byte.
>
> Sorry, it seems I wasn't very awake when I checked that. Makes sense now.
> Thanks.
>
> Does the patch solve the problem you had? What about you Christophe?
>
> Best regards,
>
> Thomas
>

Hi Thomas,

After a quick test, it looks OK to me.

Thanks

Christophe.


Re: [PATCHv3 2/2] libstdc++: Add std::aligned_union.

2014-06-02 Thread Jonathan Wakely

On 16/04/14 17:47 +0200, Rüdiger Sonderfeld wrote:

Of course I forgot to replace one _M_ instance.  This should work now.
Sorry about this.

-- 8< - >8 --

C++11: [meta.trans.other]

* libstdc++-v3/testsuite/20_util/aligned_union/1.cc: New file.
* libstdc++-v3/include/std/type_traits (__strictest_alignment): New
 helper struct.
 (aligned_union): New struct (C++11).
 (aligned_union_t): New type alias (C++14).


Hi,

I've fixed up the patch to meet the coding standards, define the
static member aligned_union::alignment_value, check the precondition,
update the docs and fix a test failure.

Tested x86_64-linux, committed to trunk.

Thanks for adding this missing piece!

commit 7018ff5142ba1413b140d9d69c7263565ecae000
Author: Jonathan Wakely 
Date:   Sun Jun 1 23:33:29 2014 +0100

2014-06-02  R??diger Sonderfeld  
	Jonathan Wakely  

	* libstdc++-v3/include/std/type_traits (__strictest_alignment): New
	helper struct.
	(aligned_union): New struct (C++11).
	(aligned_union_t): New type alias (C++14).
	* doc/xml/manual/status_cxx2011.xml: Update.
	* libstdc++-v3/testsuite/20_util/aligned_union/1.cc: New file.
	* testsuite/20_util/declval/requirements/1_neg.cc: Adjust dg-error
	line number.

diff --git a/libstdc++-v3/doc/xml/manual/status_cxx2011.xml b/libstdc++-v3/doc/xml/manual/status_cxx2011.xml
index b3c24d8..cad4111 100644
--- a/libstdc++-v3/doc/xml/manual/status_cxx2011.xml
+++ b/libstdc++-v3/doc/xml/manual/status_cxx2011.xml
@@ -871,11 +871,10 @@ particular release.
   
 
 
-  
   20.9.7.6
   Other transformations
-  Partial
-  Missing aligned_union.
+  Y
+  
 
 
   20.10
diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
index 1ff2e62..da8a95f 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -1870,6 +1870,52 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   };
 };
 
+  template 
+struct __strictest_alignment
+{
+  static const size_t _S_alignment = 0;
+  static const size_t _S_size = 0;
+};
+
+  template 
+struct __strictest_alignment<_Tp, _Types...>
+{
+  static const size_t _S_alignment =
+alignof(_Tp) > __strictest_alignment<_Types...>::_S_alignment
+	? alignof(_Tp) : __strictest_alignment<_Types...>::_S_alignment;
+  static const size_t _S_size =
+sizeof(_Tp) > __strictest_alignment<_Types...>::_S_size
+	? sizeof(_Tp) : __strictest_alignment<_Types...>::_S_size;
+};
+
+  /**
+   *  @brief Provide aligned storage for types.
+   *
+   *  [meta.trans.other]
+   *
+   *  Provides aligned storage for any of the provided types of at
+   *  least size _Len.
+   *
+   *  @see aligned_storage
+   */
+  template 
+struct aligned_union
+{
+private:
+  static_assert(sizeof...(_Types) != 0, "At least one type is required");
+
+  using __strictest = __strictest_alignment<_Types...>;
+  static const size_t _S_len = _Len > __strictest::_S_size
+	? _Len : __strictest::_S_size;
+public:
+  /// The value of the strictest alignment of _Types.
+  static const size_t alignment_value = __strictest::_S_alignment;
+  /// The storage.
+  typedef typename aligned_storage<_S_len, alignment_value>::type type;
+};
+
+  template 
+const size_t aligned_union<_Len, _Types...>::alignment_value;
 
   // Decay trait for arrays and functions, used for perfect forwarding
   // in make_pair, make_tuple, etc.
@@ -2206,6 +2252,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	__alignof__(typename __aligned_storage_msa<_Len>::__type)>
 using aligned_storage_t = typename aligned_storage<_Len, _Align>::type;
 
+  template 
+using aligned_union_t = typename aligned_union<_Len, _Types...>::type;
+
   /// Alias template for decay
   template
 using decay_t = typename decay<_Tp>::type;
diff --git a/libstdc++-v3/testsuite/20_util/aligned_union/1.cc b/libstdc++-v3/testsuite/20_util/aligned_union/1.cc
new file mode 100644
index 000..5285bb0
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/aligned_union/1.cc
@@ -0,0 +1,72 @@
+// { dg-options " -std=gnu++11 " }
+// { dg-do compile }
+
+// 2014-04-16 R??diger Sonderfeld  
+
+// Copyright (C) 2014 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License as published by the Free Software
+// Foundation; either version 3, or (at your option) any later
+// version.
+
+// This library is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with thi

[PATCH, testsuite]: Add -mno-avx2 to some i386 XOP tests

2014-06-02 Thread Uros Bizjak
Hello!

With targets that default to AVX2, these tests vectorize via 256bit
paths, where different insns are emitted.

2014-06-02  Uros Bizjak  

* gcc.target/i386/xop-rotate1-vector.c (dg-options): Add -mno-avx2.
* gcc.target/i386/xop-rotate2-vector.c (dg-options): Ditto.
* gcc.target/i386/xop-rotate3-vector.c (dg-options): Ditto.
* gcc.target/i386/xop-imul32widen-vector.c (dg-options): Ditto.
* gcc.target/i386/xop-imul64-vector.c (dg-options): Ditto.
* gcc.target/i386/xop-shift1-vector.c (dg-options): Ditto.
* gcc.target/i386/xop-shift2-vector.c (dg-options): Ditto.
* gcc.target/i386/xop-shift3-vector.c (dg-options): Ditto.

Tested on x86_64-pc-linux-gnu {,-m32} and committed to mainline SVN.

Uros.
Index: gcc.target/i386/xop-rotate1-vector.c
===
--- gcc.target/i386/xop-rotate1-vector.c(revision 211125)
+++ gcc.target/i386/xop-rotate1-vector.c(working copy)
@@ -2,7 +2,7 @@
into prot on XOP systems.  */
 
 /* { dg-do compile { target { ! { ia32 } } } } */
-/* { dg-options "-O2 -mxop -ftree-vectorize" } */
+/* { dg-options "-O2 -mxop -mno-avx2 -ftree-vectorize" } */
 
 extern void exit (int);
 
Index: gcc.target/i386/xop-rotate2-vector.c
===
--- gcc.target/i386/xop-rotate2-vector.c(revision 211125)
+++ gcc.target/i386/xop-rotate2-vector.c(working copy)
@@ -2,7 +2,7 @@
into prot on XOP systems.  */
 
 /* { dg-do compile { target { ! { ia32 } } } } */
-/* { dg-options "-O2 -mxop -ftree-vectorize" } */
+/* { dg-options "-O2 -mxop -mno-avx2 -ftree-vectorize" } */
 
 extern void exit (int);
 
Index: gcc.target/i386/xop-imul32widen-vector.c
===
--- gcc.target/i386/xop-imul32widen-vector.c(revision 211125)
+++ gcc.target/i386/xop-imul32widen-vector.c(working copy)
@@ -3,7 +3,7 @@
 
 /* { dg-do compile } */
 /* { dg-require-effective-target lp64 } */
-/* { dg-options "-O2 -mxop -ftree-vectorize" } */
+/* { dg-options "-O2 -mxop -mno-avx2 -ftree-vectorize" } */
 
 extern void exit (int);
 
Index: gcc.target/i386/xop-rotate3-vector.c
===
--- gcc.target/i386/xop-rotate3-vector.c(revision 211125)
+++ gcc.target/i386/xop-rotate3-vector.c(working copy)
@@ -2,7 +2,7 @@
into prot on XOP systems.  */
 
 /* { dg-do compile { target { ! { ia32 } } } } */
-/* { dg-options "-O2 -mxop -ftree-vectorize" } */
+/* { dg-options "-O2 -mxop -mno-avx2 -ftree-vectorize" } */
 
 extern void exit (int);
 
Index: gcc.target/i386/xop-imul64-vector.c
===
--- gcc.target/i386/xop-imul64-vector.c (revision 211125)
+++ gcc.target/i386/xop-imul64-vector.c (working copy)
@@ -3,7 +3,7 @@
 
 /* { dg-do compile } */
 /* { dg-require-effective-target lp64 } */
-/* { dg-options "-O2 -mxop -ftree-vectorize" } */
+/* { dg-options "-O2 -mxop -mno-avx2 -ftree-vectorize" } */
 
 extern void exit (int);
 
Index: gcc.target/i386/xop-shift1-vector.c
===
--- gcc.target/i386/xop-shift1-vector.c (revision 211125)
+++ gcc.target/i386/xop-shift1-vector.c (working copy)
@@ -2,7 +2,7 @@
psha/pshl on XOP systems.  */
 
 /* { dg-do compile { target { ! { ia32 } } } } */
-/* { dg-options "-O2 -mxop -ftree-vectorize" } */
+/* { dg-options "-O2 -mxop -mno-avx2 -ftree-vectorize" } */
 
 extern void exit (int);
 
Index: gcc.target/i386/xop-shift2-vector.c
===
--- gcc.target/i386/xop-shift2-vector.c (revision 211125)
+++ gcc.target/i386/xop-shift2-vector.c (working copy)
@@ -2,7 +2,7 @@
psha/pshl on XOP systems.  */
 
 /* { dg-do compile { target { ! { ia32 } } } } */
-/* { dg-options "-O2 -mxop -ftree-vectorize" } */
+/* { dg-options "-O2 -mxop -mno-avx2 -ftree-vectorize" } */
 
 extern void exit (int);
 
Index: gcc.target/i386/xop-shift3-vector.c
===
--- gcc.target/i386/xop-shift3-vector.c (revision 211125)
+++ gcc.target/i386/xop-shift3-vector.c (working copy)
@@ -2,7 +2,7 @@
psha/pshl on XOP systems.  */
 
 /* { dg-do compile { target { ! { ia32 } } } } */
-/* { dg-options "-O2 -mxop -ftree-vectorize" } */
+/* { dg-options "-O2 -mxop -mno-avx2 -ftree-vectorize" } */
 
 extern void exit (int);
 


Re: [PATCH 2/3] PR other/61321 - demangler crash on casts in template parameters

2014-06-02 Thread Jason Merrill

On 05/27/2014 07:57 AM, Pedro Alves wrote:

And after the fix for 59195, due to:

  static void
  d_print_cast (struct d_print_info *dpi, int options,
   const struct demangle_component *dc)
  {
  ...
/* For a cast operator, we need the template parameters from
   the enclosing template in scope for processing the type.  */
if (dpi->current_template != NULL)
  {
dpt.next = dpi->templates;
dpi->templates = &dpt;
dpt.template_decl = dpi->current_template;
  }

when printing the template argument list of A (what should be ""), the template parameter 0 (that is, "T_", the '**' above) now
refers to the first parameter of the the template argument list of the
'A' template (the '*' above), exactly what we were already trying to
print.  This leads to infinite recursion, and stack exaustion.  The
template parameter 0 should actually refer to the first parameter of
the 'function_temp' template.


It seems that the problem here is more general; a template argument list 
is not in scope within that same template argument list.  Can't we fix 
that without special-casing conversion ops?


Jason



Re: [PATCHv2/AARCH64 3/3] Support ILP32 multi-lib

2014-06-02 Thread Marcus Shawcroft
On 26 February 2014 02:25, Andrew Pinski  wrote:
> Hi,
>   This is the final patch which adds support for the dynamic linker and
> multi-lib directories for ILP32.  I did not change multi-arch support as
> I did not know what it should be changed to and internally here at Cavium,
> we don't use multi-arch.  Updated for the new names that were decided on.
>
>
> OK?  Build and tested for aarch64-linux-gnu with and without 
> --with-multilib-list=lp64,ilp32.
>
> Thanks,
> Andrew Pinski
>
> * config/aarch64/aarch64-linux.h (GLIBC_DYNAMIC_LINKER): 
> /lib/ld-linux-aarch64_ilp32.so.1
> is used for ILP32.
> (LINUX_TARGET_LINK_SPEC): Update linker script for ILP32.
> file whose name depends on -mabi= and -mbig-endian.
> * config/aarch64/t-aarch64-linux (MULTILIB_OSDIRNAMES): Handle LP64 
> better
> and handle ilp32 too.
> (MULTILIB_OPTIONS): Delete.
> (MULTILIB_DIRNAMES): Delete.

Hi, This is OK, thanks  /Marcus


Re: [PATCH v2 3/3] mangler/demangler dogfooding

2014-06-02 Thread Jason Merrill

On 05/28/2014 06:31 PM, Pedro Alves wrote:

Some failures might be
+   demangler bugs, others unknown mangler bugs, and others known
+   mangler bugs fixed with a higher -fabi-version that the
+   demangler doesn't have a workaround for.


You can avoid the latter by skipping demangling if G.need_abi_warning is 
set.  If you do that, are there still any failures?


Jason



Re: [PATCH, Pointer Bounds Checker 14/x] Pointer Bounds Checker passes

2014-06-02 Thread Richard Biener
On Mon, Jun 2, 2014 at 2:44 PM, Ilya Enkovich  wrote:
> 2014-06-02 15:35 GMT+04:00 Richard Biener :
>> On Fri, May 30, 2014 at 2:25 PM, Ilya Enkovich  
>> wrote:
>>> Hi,
>>>
>>> This patch adds Pointer Bounds Checker passes.  Versioning happens before 
>>> early local passes.  Earply local passes are split into 3 stages to have 
>>> everything instrumented before any optimization applies.
>>
>> That looks artificial to me.  If you need to split up early_local_passes
>> then do that - nesting three IPA pass groups inside it looks odd to me.
>> Btw - doing this in three "IPA phases" makes things possibly slower
>> due to cache effects.  It might be worth pursuing to move the early
>> stage completely to the lowering pipeline.
>
> Early local passes is some special case because these passes are
> executed separately for new functions. I did not want to get three
> special passes instead and therefore made split inside.

Yeah, but all passes are already executed via execute_early_local_passes,
so it would be only an implementation detail.

> If you prefer split pass itself, I suppose pass_early_local_passes may
> be replaced with something like pass_build_ssa_passes +
> pass_chkp_instrumentation_passes + pass_ipa_chkp_produce_thunks +
> pass_local_optimization_passes. execute_early_local_passes would
> execute gimple passes lists of pass_build_ssa_passes,
> pass_chkp_instrumentation_passes and pass_local_optimization_passes.
>
> I think we cannot have the first stage moved into lowering passes
> because it should be executed for newly created functions.

Well, let's defer that then.

>>
>> Btw, fixup_cfg only needs to run once local_pure_const was run
>> on a callee, thus it shouldn't be neccessary to run it from the
>> first group.
>
> OK. Will try to remove it from the first group.
>
>>
>>  void
>>  pass_manager::execute_early_local_passes ()
>>  {
>> -  execute_pass_list (pass_early_local_passes_1->sub);
>> +  execute_pass_list (pass_early_local_passes_1->sub->sub);
>> +  execute_pass_list (pass_early_local_passes_1->sub->next->sub);
>> +  execute_pass_list (pass_early_local_passes_1->sub->next->next->next->sub);
>>  }
>>
>> is gross - it should be enough to execute the early local pass list
>> (obsolete comment with the suggestion above).
>
> This function should call only gimple passes for cfun. Therefore we
> cannot call IPA passes here and has to execute each gimple passes list
> separately.

Ok, given a different split this would then become somewhat more sane
anyway.

Richard.

> Ilya
>>
>> Richard.
>>
>>> Bootstrapped and tested on linux-x86_64.
>>>
>>> Thanks,
>>> Ilya
>>> --
>>> gcc/
>>>
>>> 2014-05-29  Ilya Enkovich  
>>>
>>> * tree-chkp.c: New.
>>> * tree-chkp.h: New.
>>> * rtl-chkp.c: New.
>>> * rtl-chkp.h: New.
>>> * Makefile.in (OBJS): Add tree-chkp.o, rtl-chkp.o.
>>> (GTFILES): Add tree-chkp.c.
>>> * c-family/c.opt (fchkp-check-incomplete-type): New.
>>> (fchkp-zero-input-bounds-for-main): New.
>>> (fchkp-first-field-has-own-bounds): New.
>>> (fchkp-narrow-bounds): New.
>>> (fchkp-narrow-to-innermost-array): New.
>>> (fchkp-optimize): New.
>>> (fchkp-use-fast-string-functions): New.
>>> (fchkp-use-nochk-string-functions): New.
>>> (fchkp-use-static-bounds): New.
>>> (fchkp-use-static-const-bounds): New.
>>> (fchkp-treat-zero-dynamic-size-as-infinite): New.
>>> (fchkp-check-read): New.
>>> (fchkp-check-write): New.
>>> (fchkp-store-bounds): New.
>>> (fchkp-instrument-calls): New.
>>> (fchkp-instrument-marked-only): New.
>>> * cppbuiltin.c (define_builtin_macros_for_compilation_flags): Add
>>> __CHKP__ macro when Pointer Bounds Checker is on.
>>> * passes.def (pass_ipa_chkp_versioning): New.
>>> (pass_before_local_optimization_passes): New.
>>> (pass_chkp_instrumentation_passes): New.
>>> (pass_ipa_chkp_produce_thunks): New.
>>> (pass_local_optimization_passes): New.
>>> (pass_chkp_opt): New.
>>> * toplev.c: include tree-chkp.h.
>>> (compile_file): Add chkp_finish_file call.
>>> * tree-pass.h (make_pass_ipa_chkp_versioning): New.
>>> (make_pass_ipa_chkp_produce_thunks): New.
>>> (make_pass_chkp): New.
>>> (make_pass_chkp_opt): New.
>>> (make_pass_before_local_optimization_passes): New.
>>> (make_pass_chkp_instrumentation_passes): New.
>>> (make_pass_local_optimization_passes): New.
>>> * tree.h (called_as_built_in): New.
>>> * builtins.c (called_as_built_in): Not static anymore.
>>> * passes.c (pass_manager::execute_early_local_passes): Execute
>>> early passes in three steps.
>>> (pass_data_before_local_optimization_passes): New.
>>> (pass_before_local_optimization_passes): New.
>>> (pass_data_chkp_instrumentation_passes): New.
>>> 

Re: [GSoC][match-and-simplify] add bitwise patterns to match.pd

2014-06-02 Thread Richard Biener
On Mon, Jun 2, 2014 at 2:53 PM, Richard Biener
 wrote:
> On Mon, Jun 2, 2014 at 1:33 PM, Prathamesh Kulkarni
>  wrote:
>> Hi,
>>   I have tried to add few bitwise patterns from
>> tree-ssa-forwprop.c:simplify_bitwise_binary and the patterns
>> mentioned in Simplifications wiki (https://gcc.gnu.org/wiki/Simplifications).
>>
>> How to write a test-case to match multiple gimple statements ?
>> Example: For the pattern: ~x | ~y -> ~(x & y)
>>
>> test-case:
>> int f(int x, int y)
>> {
>>   int t1 = ~x;
>>   int t2 = ~y;
>>   return t1 | t2;
>> }
>>
>> fdump-tree-forwprop-details output:
>> gimple_match_and_simplified to _5 = ~_7;
>> f (int x, int y)
>> {
>>   int t2;
>>   int t1;
>>   int _5;
>>   int _7;
>>
>>   :
>>   t1_2 = ~x_1(D);
>>   t2_4 = ~y_3(D);
>>   _7 = x_1(D) & y_3(D);
>>   _5 = ~_7;
>>   return _5;
>>
>> }
>>
>> I suppose we want to look for matching both:
>>  _7 = x_1(D) & y_3(D);
>>   _5 = ~_7;
>>
>> so only matching on "gimple_match_and_simplified to _5 = ~_7" won't
>> be correct ?
>
> Yeah, that's a forwprop debugging dump issue and/or of the API
> it uses.  The gimple_match_and_simplify overload using a
> gimple_stmt_iterator * inserts the other stmts before it instead
> of delaying that to the caller (and gives it the chance to dump it).
>
> You can do the old-school testing by scanning for the IL itself,
> not some gimple_match_and_simplified dump.  Thus in addition
> to the above also scan for
>
> { dg-final { scan-tree-dump "\[xy\]_\\d\+\\(D\\) & \[xy\]_\\d\+\\(D\\)" } }
>
>> The patterns for x & 0 -> 0 and x & -1 -> x don't get fired from forwprop.
>> I tried:
>> int f1(int x)
>> {
>>   int t1 = 0;
>>   return x & t1;
>> }
>>
>> fdump-tree-forwprop-details shows following:
>> ;; Function f1 (f1, funcdef_no=0, decl_uid=1743, symbol_order=0)
>>
>> f1 (int x)
>> {
>>   int t1;
>>
>>   :
>>   return 0;
>>
>> }
>
> That's because constant propagation (which runs before forwprop)
> already simplified the statement.
>
> I have a patch to make use of match-and-simplify from
> gimple_fold_stmt_to_constant but I have to clean it up.
> I'll give writing testcases a thought there (hopefully will
> post and commit a patch later today).

Btw,

/* x & 0 -> 0 */
(match_and_simplify
  (bit_and @0 @1)
  if (INTEGRAL_TYPE_P (TREE_TYPE (@0)) && @1 == integer_zero_node)
  { integer_zero_node; })

/* x & -1 -> x */
(match_and_simplify
  (bit_and @0 @1)
  if (INTEGRAL_TYPE_P (TREE_TYPE (@0)) && @1 == integer_minus_one_node)
  @0)

are too restrictive due to comparing @1 against very special tree nodes.
The patch I just committed uses integer_zerop and integer_all_onesp
instead.

I have simplfied some of the if-exprs, operands are guaranteed
to match.  Also if we settle on the solution of providing 'type'
as the type of the outermost expression we can simplify them
as bitwise expressions don't change types.

Most of the patterns would also apply in commutated form, thus
I guess thinking of a good solution for that is next on the list
after the decision tree stuff.

/* ((a & b) & ~a) & ~b -> 0 */
(match_and_simplify
  (bit_and (bit_and (bit_and @0 @1) (bit_not @0)) (bit_not @1))
  if (INTEGRAL_TYPE_P (TREE_TYPE (@0)) && INTEGRAL_TYPE_P (TREE_TYPE (@1)))
  { integer_zero_node; })

isn't this too complex and instead already (a & b) & ~a is 0?  Also
that would be still doing two steps in one as we already have
a & ~a -> 0 so the pattern (if wanted) should only do the association
(a & b) & ~a -> (a & ~a) & b?  (note that generally this is something
for a reassociation pass, not for simple pattern matching)

I have applied the patch with these changes.

Richard.


> Richard.
>
>>
>> [gcc]
>> * match.pd: Add few patterns from simplify_bitwise_binary.
>>
>> [gcc/testsuite]
>> * gcc.dg/tree-ssa/match-2.c: Add more test-cases.
>>
>> Thanks and Regards,
>> Prathamesh


[PING**2] [PATCH, FORTRAN] Fix PR fortran/60718

2014-06-02 Thread Bernd Edlinger
Hello,

Ping**2...

this is patch still pending:

see https://gcc.gnu.org/ml/gcc-patches/2014-04/msg00774.html
for the latest version.

Thanks,
Bernd.


> Date: Wed, 30 Apr 2014 15:17:51 +0200
>
> Ping...
>
>> Date: Tue, 15 Apr 2014 13:49:37 +0200
>>
>> Hi Tobias,
>>
>> On Fri, 11 Apr 2014 16:04:51, Tobias Burnus wrote:
>>>
>>> Hi Tobias,
>>>
>>> On Fri, Apr 11, 2014 at 02:39:57PM +0200, Bernd Edlinger wrote:
 On Fri, 11 Apr 2014 13:37:46, Tobias Burnus wrote:
 Hmm,

 I was hoping somehow that only that test case is broken,
 and needs to be fixed. The target attribute is somehow simple,
 it implies intent(in) and the actual value will in most cases
 be a pointer, as in the example.
>>>
>>> I think that passing another nonpointer TARGET to a dummy argument
>>> which has a TARGET attribute is at least as common as passing a
>>> POINTER to a TARGET.
>>>
>>> TARGET is roughtly the opposite to the restrict qualifier. By default
>>> any nonpointer variable does not alias with something else, unless
>>> it has the TARGET attribute; if it has, it (its address) can then
>>> be assigned to a pointer. POINTER intrinsically alias and cannot
>>> have the TARGET attribute.
>>>
> Pointer -> Nonalloc
> Allocatable -> Noalloc
> Nonallocatable*/Allocatable* -> Pointer with intent(in)

 Well, this approach does not handle intent(inout) at all.
>>>
>>>
>>
>> Now I have created a test case for the different aliasing issues
>> with may arise with scalar objects.
>>
>> As you pointed out, also conversions of allocatable -> nonalloc,
>> allocatable -> pointer and nonalloc -> pointer turn out to
>> violate the strict aliasing rules. However, conversions of
>> arrays of objects with different attributes seem to be safe.
>>
>> I have not been able to find an example where it would be
>> necessary to write the modified class object back to the original
>> location. But I am not really a Fortran expert.
>>
>> Unfortunately there are also conversions of optional allocatable ->
>> optional pointer, which complicate the whole thing quite a lot.
>> I have found these in class_optional_2.f90.
>>
>> Boot-strapped and regression-tested on x86_64-linux-gnu.
>> OK for trunk?
>>
>>
>> Thanks
>> Bernd.
>>
>
  

[PATCH, i386]: Fix PR 61239, ICE in decompose, at rtl.h when compiling vshuf-v16hi.c using -mavx2

2014-06-02 Thread Uros Bizjak
Hello!

2014-06-02  Uros Bizjak  

PR target/61239
* config/i386/i386.c (ix86_expand_vec_perm) [case V32QImode]: Use
GEN_INT (-128) instead of GEN_INT (128) to set MSB of QImode constant.

Tested on x86_64-pc-linux-gnu with "make check-gcc
RUNTESTFLAGS='--target_board=unix\{-msse2,-msse4,-mavx,-mavx2\}
dg-torture.exp=vshuf*.c'" and committed to mainline SVN.

Uros.

Index: config/i386/i386.c
===
--- config/i386/i386.c  (revision 211125)
+++ config/i386/i386.c  (working copy)
@@ -21541,7 +21541,7 @@ ix86_expand_vec_perm (rtx operands[])
  t1 = gen_reg_rtx (V32QImode);
  t2 = gen_reg_rtx (V32QImode);
  t3 = gen_reg_rtx (V32QImode);
- vt2 = GEN_INT (128);
+ vt2 = GEN_INT (-128);
  for (i = 0; i < 32; i++)
vec[i] = vt2;
  vt = gen_rtx_CONST_VECTOR (V32QImode, gen_rtvec_v (32, vec));


[PATCH][match-and-simplify]

2014-06-02 Thread Richard Biener

This is a patch I worked on last week - it makes 
gimple_fold_stmt_to_constant[_1] use gimple_match_and_simplify
(and avoid building trees we throw away because they are not
gimple values).  It also adds basic constant folding patterns
(and comments on what is missing in match.pd - the actual
patch I was using was comparing the result from both simplification
methods and errors if they don't agree).

The patch below (which has been committed) keeps the "old"
path to not regress due to missing patterns.

Committed to the branch.

Richard.

2014-06-02  Richard Biener  

* gimple-fold.c (gimple_fold_stmt_to_constant_1): Rename to 
(gimple_fold_stmt_to_constant_2): ... this and make static.
(gimple_fold_stmt_to_constant_1): New wrapper using
gimple_match_and_simplify before falling back to
gimple_fold_stmt_to_constant_2.
* match.pd: Add basic constant folding patterns.  Add
two commutations.

Index: gcc/gimple-fold.c
===
--- gcc/gimple-fold.c   (revision 211131)
+++ gcc/gimple-fold.c   (working copy)
@@ -2524,8 +2524,8 @@ maybe_fold_or_comparisons (enum tree_cod
privatized with the single valueize function used in the various TUs
to avoid the indirect function call overhead.  */
 
-tree
-gimple_fold_stmt_to_constant_1 (gimple stmt, tree (*valueize) (tree))
+static tree
+gimple_fold_stmt_to_constant_2 (gimple stmt, tree (*valueize) (tree))
 {
   location_t loc = gimple_location (stmt);
   switch (gimple_code (stmt))
@@ -2803,6 +2803,30 @@ gimple_fold_stmt_to_constant_1 (gimple s
 }
 }
 
+tree
+gimple_fold_stmt_to_constant_1 (gimple stmt, tree (*valueize) (tree))
+{
+  tree lhs = gimple_get_lhs (stmt);
+  if (lhs)
+{
+  tree res = gimple_match_and_simplify (lhs, NULL, valueize);
+  if (res)
+   {
+ if (dump_file && dump_flags & TDF_DETAILS)
+   {
+ fprintf (dump_file, "Match-and-simplified definition of ");
+ print_generic_expr (dump_file, lhs, 0);
+ fprintf (dump_file, " to ");
+ print_generic_expr (dump_file, res, 0);
+ fprintf (dump_file, "\n");
+   }
+ return res;
+   }
+}
+  /* ???  For now, to avoid regressions.  */
+  return gimple_fold_stmt_to_constant_2 (stmt, valueize);
+}
+
 /* Fold STMT to a constant using VALUEIZE to valueize SSA names.
Returns NULL_TREE if folding to a constant is not possible, otherwise
returns a constant according to is_gimple_min_invariant.  */
Index: gcc/match.pd
===
--- gcc/match.pd(revision 211131)
+++ gcc/match.pd(working copy)
@@ -21,6 +21,95 @@ You should have received a copy of the G
 along with GCC; see the file COPYING3.  If not see
 .  */
 
+/* Simple constant foldings to substitute gimple_fold_stmt_to_constant_2.  */
+(match_and_simplify
+  (plus @0 integer_zerop)
+  @0)
+(match_and_simplify
+  (pointer_plus @0 integer_zerop)
+  @0)
+(match_and_simplify
+  (minus @0 integer_zerop)
+  @0)
+(match_and_simplify
+  (minus @0 @0)
+  { build_zero_cst (type); })
+(match_and_simplify
+  (mult @0 integer_zerop@1)
+  @1)
+(match_and_simplify
+  (mult @0 integer_onep)
+  @0)
+(match_and_simplify
+  (trunc_div @0 integer_onep)
+  @0)
+/* It's hard to preserve non-folding of / 0 which is done by a
+   positional check in fold-const.c (to preserve warnings).  The
+   issue here is that we fold too early in frontends.
+   Also fold happilt folds 0 / x to 0 (even if x turns out to be zero later). 
*/
+(match_and_simplify
+  (trunc_div integer_zerop@0 @1)
+  @0)
+(match_and_simplify
+  (trunc_div @0 @0)
+  { build_one_cst (type); })
+(match_and_simplify
+  (trunc_mod @0 integer_onep)
+  { build_zero_cst (type); })
+(match_and_simplify
+  (trunc_mod integer_zerop@0 @1)
+  @0)
+(match_and_simplify
+  (trunc_mod @0 @0)
+  { build_zero_cst (type); })
+(match_and_simplify
+  (bit_ior @0 integer_zerop)
+  @0)
+(match_and_simplify
+  (bit_ior @0 integer_all_onesp@1)
+  @1)
+(match_and_simplify
+  (bit_and @0 integer_all_onesp)
+  @0)
+(match_and_simplify
+  (bit_and @0 integer_zerop@1)
+  @1)
+(match_and_simplify
+  (bit_xor @0 integer_zerop)
+  @0)
+(match_and_simplify
+  (bit_xor @0 @0)
+  { build_zero_cst (type); })
+/* tree-ssa/ifc-pr44710.c requires a < b ? c : d to fold to 1.
+   ???  probably runs into issue of recursive folding of a < b op0.  */
+/* tree-ssa/ssa-ccp-16.c wants to fold "hello"[i_2] to 0
+   (fold_const_aggregate_ref_1).  */
+/* tree-ssa/ssa-ccp-19.c wants to fold &a1_3->i to &MEM[(void *)&a]
+   (get_addr_base_and_unit_offset_1). */
+/* tree-ssa/ssa-ccp-22.c wants to fold b_2(D) <= t_1 to 1.
+   We are missing compare constant folding to type boundaries.  */
+
+/* The following is simplification done by gimple_fold_stmt_to_constant_1
+   to aid propagation engines, producing is_gimple_min_invariants from

Re: [GSoC][match-and-simplify] add bitwise patterns to match.pd

2014-06-02 Thread Richard Biener
On Mon, Jun 2, 2014 at 1:33 PM, Prathamesh Kulkarni
 wrote:
> Hi,
>   I have tried to add few bitwise patterns from
> tree-ssa-forwprop.c:simplify_bitwise_binary and the patterns
> mentioned in Simplifications wiki (https://gcc.gnu.org/wiki/Simplifications).
>
> How to write a test-case to match multiple gimple statements ?
> Example: For the pattern: ~x | ~y -> ~(x & y)
>
> test-case:
> int f(int x, int y)
> {
>   int t1 = ~x;
>   int t2 = ~y;
>   return t1 | t2;
> }
>
> fdump-tree-forwprop-details output:
> gimple_match_and_simplified to _5 = ~_7;
> f (int x, int y)
> {
>   int t2;
>   int t1;
>   int _5;
>   int _7;
>
>   :
>   t1_2 = ~x_1(D);
>   t2_4 = ~y_3(D);
>   _7 = x_1(D) & y_3(D);
>   _5 = ~_7;
>   return _5;
>
> }
>
> I suppose we want to look for matching both:
>  _7 = x_1(D) & y_3(D);
>   _5 = ~_7;
>
> so only matching on "gimple_match_and_simplified to _5 = ~_7" won't
> be correct ?

Yeah, that's a forwprop debugging dump issue and/or of the API
it uses.  The gimple_match_and_simplify overload using a
gimple_stmt_iterator * inserts the other stmts before it instead
of delaying that to the caller (and gives it the chance to dump it).

You can do the old-school testing by scanning for the IL itself,
not some gimple_match_and_simplified dump.  Thus in addition
to the above also scan for

{ dg-final { scan-tree-dump "\[xy\]_\\d\+\\(D\\) & \[xy\]_\\d\+\\(D\\)" } }

> The patterns for x & 0 -> 0 and x & -1 -> x don't get fired from forwprop.
> I tried:
> int f1(int x)
> {
>   int t1 = 0;
>   return x & t1;
> }
>
> fdump-tree-forwprop-details shows following:
> ;; Function f1 (f1, funcdef_no=0, decl_uid=1743, symbol_order=0)
>
> f1 (int x)
> {
>   int t1;
>
>   :
>   return 0;
>
> }

That's because constant propagation (which runs before forwprop)
already simplified the statement.

I have a patch to make use of match-and-simplify from
gimple_fold_stmt_to_constant but I have to clean it up.
I'll give writing testcases a thought there (hopefully will
post and commit a patch later today).

Richard.

>
> [gcc]
> * match.pd: Add few patterns from simplify_bitwise_binary.
>
> [gcc/testsuite]
> * gcc.dg/tree-ssa/match-2.c: Add more test-cases.
>
> Thanks and Regards,
> Prathamesh


Re: [PATCH, Pointer Bounds Checker 14/x] Pointer Bounds Checker passes

2014-06-02 Thread Ilya Enkovich
2014-06-02 15:35 GMT+04:00 Richard Biener :
> On Fri, May 30, 2014 at 2:25 PM, Ilya Enkovich  wrote:
>> Hi,
>>
>> This patch adds Pointer Bounds Checker passes.  Versioning happens before 
>> early local passes.  Earply local passes are split into 3 stages to have 
>> everything instrumented before any optimization applies.
>
> That looks artificial to me.  If you need to split up early_local_passes
> then do that - nesting three IPA pass groups inside it looks odd to me.
> Btw - doing this in three "IPA phases" makes things possibly slower
> due to cache effects.  It might be worth pursuing to move the early
> stage completely to the lowering pipeline.

Early local passes is some special case because these passes are
executed separately for new functions. I did not want to get three
special passes instead and therefore made split inside.

If you prefer split pass itself, I suppose pass_early_local_passes may
be replaced with something like pass_build_ssa_passes +
pass_chkp_instrumentation_passes + pass_ipa_chkp_produce_thunks +
pass_local_optimization_passes. execute_early_local_passes would
execute gimple passes lists of pass_build_ssa_passes,
pass_chkp_instrumentation_passes and pass_local_optimization_passes.

I think we cannot have the first stage moved into lowering passes
because it should be executed for newly created functions.

>
> Btw, fixup_cfg only needs to run once local_pure_const was run
> on a callee, thus it shouldn't be neccessary to run it from the
> first group.

OK. Will try to remove it from the first group.

>
>  void
>  pass_manager::execute_early_local_passes ()
>  {
> -  execute_pass_list (pass_early_local_passes_1->sub);
> +  execute_pass_list (pass_early_local_passes_1->sub->sub);
> +  execute_pass_list (pass_early_local_passes_1->sub->next->sub);
> +  execute_pass_list (pass_early_local_passes_1->sub->next->next->next->sub);
>  }
>
> is gross - it should be enough to execute the early local pass list
> (obsolete comment with the suggestion above).

This function should call only gimple passes for cfun. Therefore we
cannot call IPA passes here and has to execute each gimple passes list
separately.

Ilya
>
> Richard.
>
>> Bootstrapped and tested on linux-x86_64.
>>
>> Thanks,
>> Ilya
>> --
>> gcc/
>>
>> 2014-05-29  Ilya Enkovich  
>>
>> * tree-chkp.c: New.
>> * tree-chkp.h: New.
>> * rtl-chkp.c: New.
>> * rtl-chkp.h: New.
>> * Makefile.in (OBJS): Add tree-chkp.o, rtl-chkp.o.
>> (GTFILES): Add tree-chkp.c.
>> * c-family/c.opt (fchkp-check-incomplete-type): New.
>> (fchkp-zero-input-bounds-for-main): New.
>> (fchkp-first-field-has-own-bounds): New.
>> (fchkp-narrow-bounds): New.
>> (fchkp-narrow-to-innermost-array): New.
>> (fchkp-optimize): New.
>> (fchkp-use-fast-string-functions): New.
>> (fchkp-use-nochk-string-functions): New.
>> (fchkp-use-static-bounds): New.
>> (fchkp-use-static-const-bounds): New.
>> (fchkp-treat-zero-dynamic-size-as-infinite): New.
>> (fchkp-check-read): New.
>> (fchkp-check-write): New.
>> (fchkp-store-bounds): New.
>> (fchkp-instrument-calls): New.
>> (fchkp-instrument-marked-only): New.
>> * cppbuiltin.c (define_builtin_macros_for_compilation_flags): Add
>> __CHKP__ macro when Pointer Bounds Checker is on.
>> * passes.def (pass_ipa_chkp_versioning): New.
>> (pass_before_local_optimization_passes): New.
>> (pass_chkp_instrumentation_passes): New.
>> (pass_ipa_chkp_produce_thunks): New.
>> (pass_local_optimization_passes): New.
>> (pass_chkp_opt): New.
>> * toplev.c: include tree-chkp.h.
>> (compile_file): Add chkp_finish_file call.
>> * tree-pass.h (make_pass_ipa_chkp_versioning): New.
>> (make_pass_ipa_chkp_produce_thunks): New.
>> (make_pass_chkp): New.
>> (make_pass_chkp_opt): New.
>> (make_pass_before_local_optimization_passes): New.
>> (make_pass_chkp_instrumentation_passes): New.
>> (make_pass_local_optimization_passes): New.
>> * tree.h (called_as_built_in): New.
>> * builtins.c (called_as_built_in): Not static anymore.
>> * passes.c (pass_manager::execute_early_local_passes): Execute
>> early passes in three steps.
>> (pass_data_before_local_optimization_passes): New.
>> (pass_before_local_optimization_passes): New.
>> (pass_data_chkp_instrumentation_passes): New.
>> (pass_chkp_instrumentation_passes): New.
>> (pass_data_local_optimization_passes): New.
>> (pass_local_optimization_passes): New.
>> (make_pass_before_local_optimization_passes): New.
>> (make_pass_chkp_instrumentation_passes): New.
>> (make_pass_local_optimization_passes): New.


Re: [PING*2][PATCH] Extend mode-switching to support toggle (1/2)

2014-06-02 Thread Christian Bruel
Hello,

Any feedback for this ? I'd like to commit only when OK for Epiphany.

many thanks,

Christian

On 05/26/2014 05:32 PM, Christian Bruel wrote:
>> On 04/28/2014 10:08 AM, Christian Bruel wrote:
>> Hello,
>>
>> I'd like to ping the following patches
>>
>> [Hookize mode-switching]
>> http://gcc.gnu.org/ml/gcc-patches/2014-04/msg01003.html
>>
>> [Add new hooks to support toggle and SH4A fpchg instruction]
>> http://gcc.gnu.org/ml/gcc-patches/2014-04/msg01005.html
>>> Sorry, I only saw the first part and thought I' d need to wait till I
>>> see the second part - and I somehow missed that.
>>>
>>> I think the previous known mode should be passed to the
>>> TARGET_MODE_EMIT hook - no need to have extra hooks
>>> for toggling, and, as I mentioned earlier, fixating on the toggle is
>>> actually an SH artifact - other ports have multi-way
>>> modes settings that can benefit from knowing the previous mode.
>> OK I'll change the bool toggle parameter by the previous mode in
>> TARGET_MODE_EMIT and remove the bool XOR hooks in the SH description.
>>
> Hello,
>
> This is the interface for targets that could use the previous mode for
> switching. TARGET_MODE_EMIT now takes a new prev_mode parameter. If the
> previous mode cannot be determined, MODE_NONE (value depends on  the
> entity) is used.
>
> The implementation is less trivial than just supporting a boolean toggle
> bit, as the previous modes information have to be carried along the
> edges. For this I recycle the auxiliary edge field that is made
> unnecessary by the removal of make_pred_opaque and a change in the
> implementation to call LCM for every modes from every identity
> simultaneously. This idea was suggested by Joern in PR29349.  Another
> speed improvement is that we process the modes to no_mode instead of
> max_num_modes for each entity.
> Thanks to all this, the only additional data to support prev_mode is
> that for each BB, the avin/avout lcm computation are cached inside the
> bb_info mode_in/mode_out fields,  the xor toggle bit handling  could
> have been removed.
>
> bootstrapped/regtested for x86 and sh4, sh4a, sh4a-single,
> epiphany build is OK. testsuite not ran.
>
> Joern, is this new target macro interface OK with you ? Jeff, (or other
> RTL maintainer) since this is a new implementation for
> optimize_mode_switching I suppose your previous approval doesn't held
> anymore... is this new one OK for trunk as well ?
> No change for x86/sh4/2a interfaces.
>
> Many thanks
>
> Christian
>
>



Re: [AARCH64, PATCH] Fix ICE in aarch64_float_const_representable_p

2014-06-02 Thread Marcus Shawcroft
On 30 May 2014 09:14, Tom de Vries  wrote:
> Marcus,
>
> when building for aarch64-linux-gnu with --enable-checking=yes,rtl, I run
> into the following error:

OK, thanks Tom.  /Marcus


Re: [PATCH, Pointer Bounds Checker 13/x] Early versioning

2014-06-02 Thread Ilya Enkovich
2014-06-02 15:56 GMT+04:00 Richard Biener :
> On Mon, Jun 2, 2014 at 12:48 PM, Ilya Enkovich  wrote:
>> On 30 May 10:59, Jeff Law wrote:
>>> On 05/29/14 05:05, Ilya Enkovich wrote:
>>> >Hi,
>>> >
>>> >This patch allows to perform function versioning when some structures are 
>>> >not available yet.  It is required to make clones for Pointer Bounds 
>>> >Checker right after SSA build.
>>> >
>>> >Bootstrapped and tested on linux-x86_64.
>>> >
>>> >Thanks,
>>> >Ilya
>>> >--
>>> >gcc/
>>> >
>>> >2014-05-29  Ilya Enkovich  
>>> >
>>> > * tree-inline.c (copy_cfg_body): Check loop tree
>>> > existence before accessing it.
>>> > (tree_function_versioning): Check DF info existence
>>> > before accessing it.
>>> >
>>> >diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c
>>> >index 4293241..23fef90 100644
>>> >--- a/gcc/tree-inline.c
>>> >+++ b/gcc/tree-inline.c
>>> >@@ -2544,7 +2544,8 @@ copy_cfg_body (copy_body_data * id, gcov_type count, 
>>> >int frequency_scale,
>>> >
>>> >/* If the loop tree in the source function needed fixup, mark the
>>> >   destination loop tree for fixup, too.  */
>>> >-  if (loops_for_fn (src_cfun)->state & LOOPS_NEED_FIXUP)
>>> >+  if (loops_for_fn (src_cfun)
>>> >+  && loops_for_fn (src_cfun)->state & LOOPS_NEED_FIXUP)
>>> >  loops_state_set (LOOPS_NEED_FIXUP);
>>> Hmm, so if I understand things correctly, src_fun has no loop
>>> structures attached, thus there's nothing to copy.  Presumably at
>>> some later point we build loop structures for the copy from scratch?
>> I suppose it is just a simple bug with absent NULL pointer check.  Here is 
>> original code:
>>
>>   /* Duplicate the loop tree, if available and wanted.  */
>>   if (loops_for_fn (src_cfun) != NULL
>>   && current_loops != NULL)
>> {
>>   copy_loops (id, entry_block_map->loop_father,
>>   get_loop (src_cfun, 0));
>>   /* Defer to cfgcleanup to update loop-father fields of basic-blocks.  
>> */
>>   loops_state_set (LOOPS_NEED_FIXUP);
>> }
>>
>>   /* If the loop tree in the source function needed fixup, mark the
>>  destination loop tree for fixup, too.  */
>>   if (loops_for_fn (src_cfun)->state & LOOPS_NEED_FIXUP)
>> loops_state_set (LOOPS_NEED_FIXUP);
>>
>> As you may see we have check for absent loops structure in the first 
>> if-statement and no check in the second one.  I hit segfault and added the 
>> check.
>
> Actually after SSA is built we always have loops (loops are built once
> we build the CFG which happens earlier).  So all the above checks
> are no longer necessary now.
>
>>>
>>> Similarly for the PTA info, we just build it from scratch in the
>>> copy at some point?
>>
>> Here we also have conditional access like
>>
>> /* Reset the escaped solution.  */
>> if (cfun->gimple_df)
>>   pt_solution_reset (&cfun->gimple_df->escaped);
>>
>> and following unconditional I've fixed.
>
> Likewise.  The init_data_structures pass initializes this (init_tree_ssa).
>
> So I'm not sure why you need all this given we are in SSA form?

Instrumentation clones are created before we are in SSA form. I do it
before early local passes.

Ilya
>
> Richard.
>
>>>
>>> Assuming the answers to both are yes, then this patch is OK for the
>>> trunk when the rest of the patches are approved.  It's not great,
>>> bit it's OK.
>>
>> Thanks!
>> Ilya
>>
>>>
>>> jeff
>>>


Re: [PATCH, Pointer Bounds Checker 13/x] Early versioning

2014-06-02 Thread Richard Biener
On Mon, Jun 2, 2014 at 12:48 PM, Ilya Enkovich  wrote:
> On 30 May 10:59, Jeff Law wrote:
>> On 05/29/14 05:05, Ilya Enkovich wrote:
>> >Hi,
>> >
>> >This patch allows to perform function versioning when some structures are 
>> >not available yet.  It is required to make clones for Pointer Bounds 
>> >Checker right after SSA build.
>> >
>> >Bootstrapped and tested on linux-x86_64.
>> >
>> >Thanks,
>> >Ilya
>> >--
>> >gcc/
>> >
>> >2014-05-29  Ilya Enkovich  
>> >
>> > * tree-inline.c (copy_cfg_body): Check loop tree
>> > existence before accessing it.
>> > (tree_function_versioning): Check DF info existence
>> > before accessing it.
>> >
>> >diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c
>> >index 4293241..23fef90 100644
>> >--- a/gcc/tree-inline.c
>> >+++ b/gcc/tree-inline.c
>> >@@ -2544,7 +2544,8 @@ copy_cfg_body (copy_body_data * id, gcov_type count, 
>> >int frequency_scale,
>> >
>> >/* If the loop tree in the source function needed fixup, mark the
>> >   destination loop tree for fixup, too.  */
>> >-  if (loops_for_fn (src_cfun)->state & LOOPS_NEED_FIXUP)
>> >+  if (loops_for_fn (src_cfun)
>> >+  && loops_for_fn (src_cfun)->state & LOOPS_NEED_FIXUP)
>> >  loops_state_set (LOOPS_NEED_FIXUP);
>> Hmm, so if I understand things correctly, src_fun has no loop
>> structures attached, thus there's nothing to copy.  Presumably at
>> some later point we build loop structures for the copy from scratch?
> I suppose it is just a simple bug with absent NULL pointer check.  Here is 
> original code:
>
>   /* Duplicate the loop tree, if available and wanted.  */
>   if (loops_for_fn (src_cfun) != NULL
>   && current_loops != NULL)
> {
>   copy_loops (id, entry_block_map->loop_father,
>   get_loop (src_cfun, 0));
>   /* Defer to cfgcleanup to update loop-father fields of basic-blocks.  */
>   loops_state_set (LOOPS_NEED_FIXUP);
> }
>
>   /* If the loop tree in the source function needed fixup, mark the
>  destination loop tree for fixup, too.  */
>   if (loops_for_fn (src_cfun)->state & LOOPS_NEED_FIXUP)
> loops_state_set (LOOPS_NEED_FIXUP);
>
> As you may see we have check for absent loops structure in the first 
> if-statement and no check in the second one.  I hit segfault and added the 
> check.

Actually after SSA is built we always have loops (loops are built once
we build the CFG which happens earlier).  So all the above checks
are no longer necessary now.

>>
>> Similarly for the PTA info, we just build it from scratch in the
>> copy at some point?
>
> Here we also have conditional access like
>
> /* Reset the escaped solution.  */
> if (cfun->gimple_df)
>   pt_solution_reset (&cfun->gimple_df->escaped);
>
> and following unconditional I've fixed.

Likewise.  The init_data_structures pass initializes this (init_tree_ssa).

So I'm not sure why you need all this given we are in SSA form?

Richard.

>>
>> Assuming the answers to both are yes, then this patch is OK for the
>> trunk when the rest of the patches are approved.  It's not great,
>> bit it's OK.
>
> Thanks!
> Ilya
>
>>
>> jeff
>>


Re: [PATCH, i386, Pointer Bounds Checker 10/x] Partitions

2014-06-02 Thread Ilya Enkovich
On 30 May 11:10, Jeff Law wrote:
> On 05/28/14 10:06, Ilya Enkovich wrote:
> >Hi,
> >
> >This patch keeps instrumented and original versions together and preserve 
> >tranparent alias chain during symbol name privatization.
> >
> >Bootstrapped and tested on linux-x86_64.
> >
> >Thanks,
> >Ilya
> >--
> >gcc/
> >
> >2013-05-28  Ilya Enkovich  
> >
> > * lto/lto-partition.c (add_symbol_to_partition_1): Keep original
> > and instrumented versions together.
> This part is OK.  Note lto/ has its own ChangeLog, so put the
> ChangeLog entry there and don't use the "lto/" prefix in the
> ChangeLog entry.
> 
> > (privatize_symbol_name): Restore transparent alias chain if required.
> What exactly are you doing here?  The comment in the code doesn't
> really make it clear what you are doing or why.
> 
> >+  /* We could change name which is a target of transparent alias
> >+ chain of instrumented function name.  Fix alias chain if so  .*/
> So are you saying that we want to change the name?  Or that it could
> have been changed and we have to adjust something because it was
> changed?
> 
> I'm certainly not as familiar with the LTO stuff as I should be --
> what is the purpose behing chaining the DECL_ASSEMBLER_NAME nodes?

I'm just adjusting renaming to support alias chains.  LTO renames functions to 
avoid two static functions with the same assembler name.  Instrumented 
functions have names chained with original names using 
IDENTIFIER_TRANSPARENT_ALIAS.  If name of the original function is privatized, 
then IDENTIFIER_TRANSPARENT_ALIAS still points to the old name which is wrong.  
My patch fixes it.

> 
> jeff
> 

Here is fixed ChangeLog.

Thanks,
Ilya
--
gcc/lto

2014-06-02  Ilya Enkovich  

* lto-partition.c (add_symbol_to_partition_1): Keep original
and instrumented versions together.
(privatize_symbol_name): Restore transparent alias chain if required.


Re: [PATCH, i386, Pointer Bounds Checker 10/x] Partitions

2014-06-02 Thread Richard Biener
On Fri, May 30, 2014 at 7:10 PM, Jeff Law  wrote:
> On 05/28/14 10:06, Ilya Enkovich wrote:
>>
>> Hi,
>>
>> This patch keeps instrumented and original versions together and preserve
>> tranparent alias chain during symbol name privatization.
>>
>> Bootstrapped and tested on linux-x86_64.
>>
>> Thanks,
>> Ilya
>> --
>> gcc/
>>
>> 2013-05-28  Ilya Enkovich  
>>
>> * lto/lto-partition.c (add_symbol_to_partition_1): Keep original
>> and instrumented versions together.
>
> This part is OK.  Note lto/ has its own ChangeLog, so put the ChangeLog
> entry there and don't use the "lto/" prefix in the ChangeLog entry.
>
>
>> (privatize_symbol_name): Restore transparent alias chain if
>> required.
>
> What exactly are you doing here?  The comment in the code doesn't really
> make it clear what you are doing or why.
>
>
>> +  /* We could change name which is a target of transparent alias
>> + chain of instrumented function name.  Fix alias chain if so  .*/
>
> So are you saying that we want to change the name?  Or that it could have
> been changed and we have to adjust something because it was changed?
>
> I'm certainly not as familiar with the LTO stuff as I should be -- what is
> the purpose behing chaining the DECL_ASSEMBLER_NAME nodes?

Something gross:

/* Nonzero in an IDENTIFIER_NODE if the name is a local alias, whose
   uses are to be substituted for uses of the TREE_CHAINed identifier.  */
#define IDENTIFIER_TRANSPARENT_ALIAS(NODE) \
  (IDENTIFIER_NODE_CHECK (NODE)->base.deprecated_flag)

this should be all moved to the symbol table level.  (and IDENTIFIER_NODE
shouldn't have to have tree_common.chain and thus become smaller).

Richard.


> jeff
>


  1   2   >