On 24/01/16 09:04, Richard Biener wrote:
On January 23, 2016 7:44:23 PM GMT+01:00, Sebastian Pop <seb...@gmail.com> 
wrote:
On Sat, Jan 23, 2016 at 12:28 PM, Tom de Vries <tom_devr...@mentor.com>
wrote:
That was my original patch, and Richard commented: 'I think avoiding
a NULL
access_fns is ok but it should be done unconditionally, not only for
the
DECL_P case'. In order words, he asked me to do the exact opposite of
the
change you now propose.


In the case of a DECL_P it is correct to say that it has an access
function of 0.
In the graphite testcase it is not correct to say that the access
function for a given data reference is zero:
we only initialize access_fns in the case of a polynomial chrec:

  if (TREE_CODE (ref) == MEM_REF)
    {
      op = TREE_OPERAND (ref, 0);
      access_fn = analyze_scalar_evolution (loop, op);
      access_fn = instantiate_scev (before_loop, loop, access_fn);
      if (TREE_CODE (access_fn) == POLYNOMIAL_CHREC)
        {
[...]
           access_fns.safe_push (access_fn);
        }
    }

In all other cases we may not have a representation of the access
functions.
It is incorrect to initialize to "A[0]" all those data references that
cannot be analyzed.

But does it matter as the base will not be equal with one that can be analyzed?


I'd like to propose a different fix.

I think the root cause of the problem is as follows:

The semantics of DDR_ARE_DEPENDENT is:
...
when "ARE_DEPENDENT == NULL_TREE", there exist a dependence
relation between A and B, and the description of this relation
is given in the SUBSCRIPTS array
...

When A and B have DR_NUM_DIMENSIONS == 0, initialize_data_dependence_relation can create a ddr with DDR_NUM_SUBSCRIPTS == 0, and in the case of our test-case, it does.

I think this is the root cause: initialize_data_dependence_relation creates a ddr with DDR_ARE_DEPENDENT (ddr) == NULL_TREE and DDR_NUM_SUBSCRIPTS (ddr) == 0, which violates the semantics of DDR_ARE_DEPENDENT (ddr) == NULL_TREE.

[ There is the case of non-loop dependence analysis (tested for by loop_nest.exists ()), where DR_NUM_DIMENSIONS == 0 for all data references, that seems to be an exception. ]

The patch fixes the root cause of the problem by handling DR_NUM_DIMENSIONS == 0 in initialize_data_dependence_relation.

OK for trunk, 5.0, 4.9, if bootstrap/reg-test succeeds?

Thanks,
- Tom


Handle DR_NUM_DIMENSIONS == 0 in initialize_data_dependence_relation

2016-01-12  Tom de Vries  <t...@codesourcery.com>

	* tree-data-ref.c (initialize_data_dependence_relation): Handle
	DR_NUM_DIMENSIONS == 0.

	* gcc.dg/autopar/pr69110.c: New test.

	* testsuite/libgomp.c/pr69110.c: New test.

---
 gcc/testsuite/gcc.dg/autopar/pr69110.c | 17 +++++++++++++++++
 gcc/tree-data-ref.c                    | 10 ++++++----
 libgomp/testsuite/libgomp.c/pr69110.c  | 26 ++++++++++++++++++++++++++
 3 files changed, 49 insertions(+), 4 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/autopar/pr69110.c b/gcc/testsuite/gcc.dg/autopar/pr69110.c
new file mode 100644
index 0000000..27cdae5
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/autopar/pr69110.c
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-options "-O1 -ftree-parallelize-loops=2 -fno-tree-loop-im -fdump-tree-parloops2-details" } */
+
+#define N 1000
+
+unsigned int i = 0;
+
+void
+foo (void)
+{
+  unsigned int z;
+  for (z = 0; z < N; ++z)
+    ++i;
+}
+
+/* { dg-final { scan-tree-dump-times "SUCCESS: may be parallelized" 0 "parloops2" } } */
+/* { dg-final { scan-tree-dump-times "FAILED: data dependencies exist across iterations" 1 "parloops2" } } */
diff --git a/gcc/tree-data-ref.c b/gcc/tree-data-ref.c
index a40f40d..4c29fc2 100644
--- a/gcc/tree-data-ref.c
+++ b/gcc/tree-data-ref.c
@@ -1510,8 +1510,9 @@ initialize_data_dependence_relation (struct data_reference *a,
   if (operand_equal_p (DR_REF (a), DR_REF (b), 0))
     {
      if (loop_nest.exists ()
-        && !object_address_invariant_in_loop_p (loop_nest[0],
-       					        DR_BASE_OBJECT (a)))
+	 && (!object_address_invariant_in_loop_p (loop_nest[0],
+						  DR_BASE_OBJECT (a))
+	     || DR_NUM_DIMENSIONS (a) == 0))
       {
         DDR_ARE_DEPENDENT (res) = chrec_dont_know;
         return res;
@@ -1548,8 +1549,9 @@ initialize_data_dependence_relation (struct data_reference *a,
      analyze it.  TODO -- in fact, it would suffice to record that there may
      be arbitrary dependences in the loops where the base object varies.  */
   if (loop_nest.exists ()
-      && !object_address_invariant_in_loop_p (loop_nest[0],
-     					      DR_BASE_OBJECT (a)))
+      && (!object_address_invariant_in_loop_p (loop_nest[0],
+					       DR_BASE_OBJECT (a))
+	  || DR_NUM_DIMENSIONS (a) == 0))
     {
       DDR_ARE_DEPENDENT (res) = chrec_dont_know;
       return res;
diff --git a/libgomp/testsuite/libgomp.c/pr69110.c b/libgomp/testsuite/libgomp.c/pr69110.c
new file mode 100644
index 0000000..0d9e5ca
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c/pr69110.c
@@ -0,0 +1,26 @@
+/* { dg-do run } */
+/* { dg-options "-ftree-parallelize-loops=2 -O1 -fno-tree-loop-im" } */
+
+#define N 1000
+
+unsigned int i = 0;
+
+static void __attribute__((noinline, noclone))
+foo (void)
+{
+  unsigned int z;
+  for (z = 0; z < N; ++z)
+    ++i;
+}
+
+extern void abort (void);
+
+int
+main (void)
+{
+  foo ();
+  if (i != N)
+    abort ();
+
+  return 0;
+}

Reply via email to