diff mbox

[PR69110] Don't return NULL access_fns in dr_analyze_indices

Message ID 56A8AB3D.4060801@mentor.com
State New
Headers show

Commit Message

Tom de Vries Jan. 27, 2016, 11:34 a.m. UTC
On 26/01/16 17:59, Sebastian Pop wrote:
> Tom de Vries wrote:
>> 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))
>
> Also please fix the indentation of all this if stmt.
>

Done.

>>         {
>>           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;
>
> Let's check for DR_NUM_DIMENSIONS (a) == 0 independently of loop_nest.exists ().

Done.

> We check for the loop_nest because we need to access the outer loop loop_nest[0]
> to analyze the base object of a.
>
> Otherwise the change looks good to me.
>

Bootstrapped and reg-tested on x86_64.

Committed as attached to trunk, 5.0 and 4.9 (And fixed up pass number in 
testcases in 5.0 and 4.9).

Thanks,
- Tom
diff mbox

Patch

Handle DR_NUM_DIMENSIONS == 0 in initialize_data_dependence_relation

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

	PR tree-optimization/69110
	* 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                    | 21 +++++++++++----------
 libgomp/testsuite/libgomp.c/pr69110.c  | 26 ++++++++++++++++++++++++++
 3 files changed, 54 insertions(+), 10 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..d6d9ffc 100644
--- a/gcc/tree-data-ref.c
+++ b/gcc/tree-data-ref.c
@@ -1509,13 +1509,14 @@  initialize_data_dependence_relation (struct data_reference *a,
   /* The case where the references are exactly the same.  */
   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)))
-      {
-        DDR_ARE_DEPENDENT (res) = chrec_dont_know;
-        return res;
-      }
+      if ((loop_nest.exists ()
+	   && !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;
+	}
       DDR_AFFINE_P (res) = true;
       DDR_ARE_DEPENDENT (res) = NULL_TREE;
       DDR_SUBSCRIPTS (res).create (DR_NUM_DIMENSIONS (a));
@@ -1547,9 +1548,9 @@  initialize_data_dependence_relation (struct data_reference *a,
   /* If the base of the object is not invariant in the loop nest, we cannot
      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)))
+  if ((loop_nest.exists ()
+       && !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;
+}