public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-1203] data-ref: Improve non-loop disambiguation [PR106019]
@ 2022-06-22 10:28 Richard Sandiford
  0 siblings, 0 replies; only message in thread
From: Richard Sandiford @ 2022-06-22 10:28 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:038b077689bb5310386b04d40a2cea234f01e6aa

commit r13-1203-g038b077689bb5310386b04d40a2cea234f01e6aa
Author: Richard Sandiford <richard.sandiford@arm.com>
Date:   Wed Jun 22 11:27:15 2022 +0100

    data-ref: Improve non-loop disambiguation [PR106019]
    
    When dr_may_alias_p is called without a loop context, it tries
    to use the tree-affine interface to calculate the difference
    between the two addresses and use that difference to check whether
    the gap between the accesses is known at compile time.  However, as the
    example in the PR shows, this doesn't expand SSA_NAMEs and so can easily
    be defeated by things like reassociation.
    
    One fix would have been to use aff_combination_expand to expand the
    SSA_NAMEs, but we'd then need some way of maintaining the associated
    cache.  This patch instead reuses the innermost_loop_behavior fields
    (which exist even when no loop context is provided).
    
    It might still be useful to do the aff_combination_expand thing too,
    if an example turns out to need it.
    
    gcc/
            PR tree-optimization/106019
            * tree-data-ref.cc (dr_may_alias_p): Try using the
            innermost_loop_behavior to disambiguate non-loop queries.
    
    gcc/testsuite/
            PR tree-optimization/106019
            * gcc.dg/vect/bb-slp-pr106019.c: New test.

Diff:
---
 gcc/testsuite/gcc.dg/vect/bb-slp-pr106019.c | 15 +++++++++++++++
 gcc/tree-data-ref.cc                        | 19 +++++++++++++++++++
 2 files changed, 34 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/vect/bb-slp-pr106019.c b/gcc/testsuite/gcc.dg/vect/bb-slp-pr106019.c
new file mode 100644
index 00000000000..218d7cca33d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/bb-slp-pr106019.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+
+void f(double *p, long i)
+{
+    p[i+0] += 1;
+    p[i+1] += 1;
+}
+void g(double *p, long i)
+{
+    double *q = p + i;
+    q[0] += 1;
+    q[1] += 1;
+}
+
+/* { dg-final { scan-tree-dump-not "can't determine dependence" slp2 } } */
diff --git a/gcc/tree-data-ref.cc b/gcc/tree-data-ref.cc
index ae05fe74b95..ff9327f6deb 100644
--- a/gcc/tree-data-ref.cc
+++ b/gcc/tree-data-ref.cc
@@ -2968,6 +2968,25 @@ dr_may_alias_p (const struct data_reference *a, const struct data_reference *b,
      disambiguation.  */
   if (!loop_nest)
     {
+      tree tree_size_a = TYPE_SIZE_UNIT (TREE_TYPE (DR_REF (a)));
+      tree tree_size_b = TYPE_SIZE_UNIT (TREE_TYPE (DR_REF (b)));
+
+      if (DR_BASE_ADDRESS (a)
+	  && DR_BASE_ADDRESS (b)
+	  && operand_equal_p (DR_BASE_ADDRESS (a), DR_BASE_ADDRESS (b))
+	  && operand_equal_p (DR_OFFSET (a), DR_OFFSET (b))
+	  && poly_int_tree_p (tree_size_a)
+	  && poly_int_tree_p (tree_size_b)
+	  && !ranges_maybe_overlap_p (wi::to_widest (DR_INIT (a)),
+				      wi::to_widest (tree_size_a),
+				      wi::to_widest (DR_INIT (b)),
+				      wi::to_widest (tree_size_b)))
+	{
+	  gcc_assert (integer_zerop (DR_STEP (a))
+		      && integer_zerop (DR_STEP (b)));
+	  return false;
+	}
+
       aff_tree off1, off2;
       poly_widest_int size1, size2;
       get_inner_reference_aff (DR_REF (a), &off1, &size1);


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-06-22 10:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-22 10:28 [gcc r13-1203] data-ref: Improve non-loop disambiguation [PR106019] Richard Sandiford

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).