public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Tom de Vries <Tom_deVries@mentor.com>
To: Richard Biener <rguenther@suse.de>, Sebastian Pop <sebpop@gmail.com>
Cc: "gcc-patches@gnu.org" <gcc-patches@gnu.org>
Subject: Re: [PATCH, PR69110] Don't return NULL access_fns in dr_analyze_indices
Date: Tue, 26 Jan 2016 12:13:00 -0000	[thread overview]
Message-ID: <56A762CA.6020005@mentor.com> (raw)
In-Reply-To: <A4CB99CC-FB58-4A68-8820-4537B57477DC@suse.de>

[-- Attachment #1: Type: text/plain, Size: 2469 bytes --]

On 24/01/16 09:04, Richard Biener wrote:
> On January 23, 2016 7:44:23 PM GMT+01:00, Sebastian Pop <sebpop@gmail.com> wrote:
>> On Sat, Jan 23, 2016 at 12:28 PM, Tom de Vries <Tom_deVries@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



[-- Attachment #2: 0001-Handle-DR_NUM_DIMENSIONS-0-in-initialize_data_dependence_relation.patch --]
[-- Type: text/x-patch, Size: 2988 bytes --]

Handle DR_NUM_DIMENSIONS == 0 in initialize_data_dependence_relation

2016-01-12  Tom de Vries  <tom@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	other threads:[~2016-01-26 12:13 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-12 10:04 Tom de Vries
2016-01-12 11:22 ` Richard Biener
2016-01-12 12:51   ` Tom de Vries
2016-01-12 13:05     ` Richard Biener
2016-01-12 18:18       ` Tom de Vries
2016-01-13  8:42         ` Richard Biener
2016-01-15 10:16           ` Tom de Vries
2016-01-15 10:18             ` Richard Biener
2016-01-21 23:48           ` Tom de Vries
     [not found]             ` <CAFk3UF9uMs4i4S5S9GdhMOBr-PY-E5PESJUVpCPDEQ2shDCE9Q@mail.gmail.com>
2016-01-23 18:28               ` Tom de Vries
2016-01-23 18:45                 ` Sebastian Pop
2016-01-24  8:05                   ` Richard Biener
2016-01-26 12:13                     ` Tom de Vries [this message]
2016-01-26 16:59                       ` Sebastian Pop
2016-01-27 11:34                         ` Tom de Vries

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56A762CA.6020005@mentor.com \
    --to=tom_devries@mentor.com \
    --cc=gcc-patches@gnu.org \
    --cc=rguenther@suse.de \
    --cc=sebpop@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).