The following removes safelen handling from LIM - it is not really
useful information to it and it was used to derive incorrect conclusions
about dependences.

Bootstrapped and tested on x86_64-unknown-linux-gnu.

I'll commit this on Monday to leave some time for comments (but many
are already in the PR).

Richard.

2017-12-15  Richard Biener  <rguent...@suse.de>

        PR tree-optimization/81877
        * tree-ssa-loop-im.c (ref_indep_loop_p): Remove safelen parameters.
        (outermost_indep_loop): Adjust.
        (ref_indep_loop_p_1): Likewise.  Remove safelen handling again.
        (can_sm_ref_p): Adjust.

        * g++.dg/torture/pr81877.C: New testcase.
        * g++.dg/vect/pr70729.cc: XFAIL.
        * g++.dg/vect/pr70729-nest.cc: XFAIL.

Index: gcc/tree-ssa-loop-im.c
===================================================================
--- gcc/tree-ssa-loop-im.c      (revision 255678)
+++ gcc/tree-ssa-loop-im.c      (working copy)
@@ -199,7 +199,7 @@ static struct
 static bitmap_obstack lim_bitmap_obstack;
 static obstack mem_ref_obstack;
 
-static bool ref_indep_loop_p (struct loop *, im_mem_ref *, struct loop *);
+static bool ref_indep_loop_p (struct loop *, im_mem_ref *);
 static bool ref_always_accessed_p (struct loop *, im_mem_ref *, bool);
 
 /* Minimum cost of an expensive expression.  */
@@ -548,10 +548,10 @@ outermost_indep_loop (struct loop *outer
        aloop != loop;
        aloop = superloop_at_depth (loop, loop_depth (aloop) + 1))
     if ((!ref->stored || !bitmap_bit_p (ref->stored, aloop->num))
-       && ref_indep_loop_p (aloop, ref, loop))
+       && ref_indep_loop_p (aloop, ref))
       return aloop;
 
-  if (ref_indep_loop_p (loop, ref, loop))
+  if (ref_indep_loop_p (loop, ref))
     return loop;
   else
     return NULL;
@@ -2150,20 +2150,13 @@ record_dep_loop (struct loop *loop, im_m
 }
 
 /* Returns true if REF is independent on all other memory
-   references in LOOP.  REF_LOOP is where REF is accessed, SAFELEN is the
-   safelen to apply.  */
+   references in LOOP.  */
 
 static bool
-ref_indep_loop_p_1 (int safelen, struct loop *loop, im_mem_ref *ref,
-                   bool stored_p, struct loop *ref_loop)
+ref_indep_loop_p_1 (struct loop *loop, im_mem_ref *ref, bool stored_p)
 {
   stored_p |= (ref->stored && bitmap_bit_p (ref->stored, loop->num));
 
-  if (loop->safelen > safelen
-      /* Check that REF is accessed inside LOOP.  */
-      && (loop == ref_loop || flow_loop_nested_p (loop, ref_loop)))
-    safelen = loop->safelen;
-
   bool indep_p = true;
   bitmap refs_to_check;
 
@@ -2174,32 +2167,6 @@ ref_indep_loop_p_1 (int safelen, struct
 
   if (bitmap_bit_p (refs_to_check, UNANALYZABLE_MEM_ID))
     indep_p = false;
-  else if (safelen > 1)
-    {
-      if (dump_file && (dump_flags & TDF_DETAILS))
-       {
-         fprintf (dump_file,"REF is independent due to safelen %d\n",
-                  safelen);
-         print_generic_expr (dump_file, ref->mem.ref, TDF_SLIM);
-         fprintf (dump_file, "\n");
-       }
-
-      /* We need to recurse to properly handle UNANALYZABLE_MEM_ID.  */
-      struct loop *inner = loop->inner;
-      while (inner)
-       {
-         if (!ref_indep_loop_p_1 (safelen, inner, ref, stored_p, ref_loop))
-           {
-             indep_p = false;
-             break;
-           }
-         inner = inner->next;
-       }
-
-      /* Avoid caching here as safelen depends on context and refs
-         are shared between different contexts.  */
-      return indep_p;
-    }
   else
     {
       if (bitmap_bit_p (&ref->indep_loop, LOOP_DEP_BIT (loop->num, stored_p)))
@@ -2210,7 +2177,7 @@ ref_indep_loop_p_1 (int safelen, struct
       struct loop *inner = loop->inner;
       while (inner)
        {
-         if (!ref_indep_loop_p_1 (safelen, inner, ref, stored_p, ref_loop))
+         if (!ref_indep_loop_p_1 (inner, ref, stored_p))
            {
              indep_p = false;
              break;
@@ -2264,14 +2231,14 @@ ref_indep_loop_p_1 (int safelen, struct
 }
 
 /* Returns true if REF is independent on all other memory references in
-   LOOP.  REF_LOOP is the loop where REF is accessed.  */
+   LOOP.  */
 
 static bool
-ref_indep_loop_p (struct loop *loop, im_mem_ref *ref, struct loop *ref_loop)
+ref_indep_loop_p (struct loop *loop, im_mem_ref *ref)
 {
   gcc_checking_assert (MEM_ANALYZABLE (ref));
 
-  return ref_indep_loop_p_1 (0, loop, ref, false, ref_loop);
+  return ref_indep_loop_p_1 (loop, ref, false);
 }
 
 /* Returns true if we can perform store motion of REF from LOOP.  */
@@ -2307,7 +2274,7 @@ can_sm_ref_p (struct loop *loop, im_mem_
 
   /* And it must be independent on all other memory references
      in LOOP.  */
-  if (!ref_indep_loop_p (loop, ref, loop))
+  if (!ref_indep_loop_p (loop, ref))
     return false;
 
   return true;
Index: gcc/testsuite/g++.dg/torture/pr81877.C
===================================================================
--- gcc/testsuite/g++.dg/torture/pr81877.C      (nonexistent)
+++ gcc/testsuite/g++.dg/torture/pr81877.C      (working copy)
@@ -0,0 +1,22 @@
+/* { dg-do run } */
+
+void __attribute__((noipa)) g(int p, int *out)
+{
+  int x = 0, y;
+#pragma GCC ivdep
+  for (int i = 0; i < 100; i++)
+    {
+      int &r = p ? x : y;
+      r = 42;
+      out[i] = x;
+    }
+}
+
+int main()
+{
+  int out[100] = { 0 };
+  g (1, out);
+  if (out[0] != 42)
+    __builtin_abort ();
+  return 0;
+}
Index: gcc/testsuite/g++.dg/vect/pr70729-nest.cc
===================================================================
--- gcc/testsuite/g++.dg/vect/pr70729-nest.cc   (revision 255684)
+++ gcc/testsuite/g++.dg/vect/pr70729-nest.cc   (working copy)
@@ -76,4 +76,4 @@ void Ss::foo (int n)
     }
 }
  
-// { dg-final { scan-tree-dump "LOOP VECTORIZED" "vect" { target x86_64-*-* 
i?86-*-* } } }
+// { dg-final { scan-tree-dump "LOOP VECTORIZED" "vect" { xfail *-*-* } } }
Index: gcc/testsuite/g++.dg/vect/pr70729.cc
===================================================================
--- gcc/testsuite/g++.dg/vect/pr70729.cc        (revision 255684)
+++ gcc/testsuite/g++.dg/vect/pr70729.cc        (working copy)
@@ -70,4 +70,4 @@ void Ss::foo (float *in, float w)
     }
 }
  
-// { dg-final { scan-tree-dump "LOOP VECTORIZED" "vect" { target x86_64-*-* 
i?86-*-* } } }
+// { dg-final { scan-tree-dump "LOOP VECTORIZED" "vect" { xfail *-*-* } } }

Reply via email to