re PR target/65697 (__atomic memory barriers not strong enough for __sync builtins)
[gcc.git] / gcc / tree-data-ref.c
index 1d3efa67813fe00e82df07fc698a39c754f4c399..cc79a7f6fb58a09549aca36f37ba9bcb69f22afd 100644 (file)
@@ -1,5 +1,5 @@
 /* Data references and dependences detectors.
-   Copyright (C) 2003-2014 Free Software Foundation, Inc.
+   Copyright (C) 2003-2015 Free Software Foundation, Inc.
    Contributed by Sebastian Pop <pop@cri.ensmp.fr>
 
 This file is part of GCC.
@@ -76,14 +76,33 @@ along with GCC; see the file COPYING3.  If not see
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
+#include "alias.h"
+#include "symtab.h"
+#include "options.h"
 #include "tree.h"
+#include "fold-const.h"
+#include "tm.h"
+#include "hard-reg-set.h"
+#include "function.h"
+#include "rtl.h"
+#include "flags.h"
+#include "insn-config.h"
+#include "expmed.h"
+#include "dojump.h"
+#include "explow.h"
+#include "calls.h"
+#include "emit-rtl.h"
+#include "varasm.h"
+#include "stmt.h"
 #include "expr.h"
 #include "gimple-pretty-print.h"
+#include "predict.h"
+#include "dominance.h"
+#include "cfg.h"
 #include "basic-block.h"
 #include "tree-ssa-alias.h"
 #include "internal-fn.h"
 #include "gimple-expr.h"
-#include "is-a.h"
 #include "gimple.h"
 #include "gimple-iterator.h"
 #include "tree-ssa-loop-niter.h"
@@ -614,7 +633,7 @@ split_constant_offset_1 (tree type, tree op0, enum tree_code code, tree op1,
       {
        tree base, poffset;
        HOST_WIDE_INT pbitsize, pbitpos;
-       enum machine_mode pmode;
+       machine_mode pmode;
        int punsignedp, pvolatilep;
 
        op0 = TREE_OPERAND (op0, 0);
@@ -663,6 +682,9 @@ split_constant_offset_1 (tree type, tree op0, enum tree_code code, tree op1,
 
     case SSA_NAME:
       {
+       if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (op0))
+         return false;
+
        gimple def_stmt = SSA_NAME_DEF_STMT (op0);
        enum tree_code subcode;
 
@@ -759,7 +781,7 @@ dr_analyze_innermost (struct data_reference *dr, struct loop *nest)
   tree ref = DR_REF (dr);
   HOST_WIDE_INT pbitsize, pbitpos;
   tree base, poffset;
-  enum machine_mode pmode;
+  machine_mode pmode;
   int punsignedp, pvolatilep;
   affine_iv base_iv, offset_iv;
   tree init, dinit, step;
@@ -962,6 +984,7 @@ dr_analyze_indices (struct data_reference *dr, loop_p nest, loop_p loop)
          orig_type = TREE_TYPE (base);
          STRIP_USELESS_TYPE_CONVERSION (base);
          split_constant_offset (base, &base, &off);
+         STRIP_USELESS_TYPE_CONVERSION (base);
          /* Fold the MEM_REF offset into the evolutions initial
             value to make more bases comparable.  */
          if (!integer_zerop (memoff))
@@ -970,6 +993,22 @@ dr_analyze_indices (struct data_reference *dr, loop_p nest, loop_p loop)
                                fold_convert (ssizetype, memoff));
              memoff = build_int_cst (TREE_TYPE (memoff), 0);
            }
+         /* Adjust the offset so it is a multiple of the access type
+            size and thus we separate bases that can possibly be used
+            to produce partial overlaps (which the access_fn machinery
+            cannot handle).  */
+         wide_int rem;
+         if (TYPE_SIZE_UNIT (TREE_TYPE (ref))
+             && TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (ref))) == INTEGER_CST
+             && !integer_zerop (TYPE_SIZE_UNIT (TREE_TYPE (ref))))
+           rem = wi::mod_trunc (off, TYPE_SIZE_UNIT (TREE_TYPE (ref)), SIGNED);
+         else
+           /* If we can't compute the remainder simply force the initial
+              condition to zero.  */
+           rem = off;
+         off = wide_int_to_tree (ssizetype, wi::sub (off, rem));
+         memoff = wide_int_to_tree (TREE_TYPE (memoff), rem);
+         /* And finally replace the initial condition.  */
          access_fn = chrec_replace_initial_condition
              (access_fn, fold_convert (orig_type, off));
          /* ???  This is still not a suitable base object for
@@ -979,9 +1018,13 @@ dr_analyze_indices (struct data_reference *dr, loop_p nest, loop_p loop)
             guaranteed.
             As a band-aid, mark the access so we can special-case
             it in dr_may_alias_p.  */
+         tree old = ref;
          ref = fold_build2_loc (EXPR_LOCATION (ref),
                                 MEM_REF, TREE_TYPE (ref),
                                 base, memoff);
+         MR_DEPENDENCE_CLIQUE (ref) = MR_DEPENDENCE_CLIQUE (old);
+         MR_DEPENDENCE_BASE (ref) = MR_DEPENDENCE_BASE (old);
+         DR_UNCONSTRAINED_BASE (dr) = true;
          access_fns.safe_push (access_fn);
        }
     }
@@ -1388,12 +1431,19 @@ dr_may_alias_p (const struct data_reference *a, const struct data_reference *b,
        return false;
     }
 
+  if ((TREE_CODE (addr_a) == MEM_REF || TREE_CODE (addr_a) == TARGET_MEM_REF)
+      && (TREE_CODE (addr_b) == MEM_REF || TREE_CODE (addr_b) == TARGET_MEM_REF)
+      && MR_DEPENDENCE_CLIQUE (addr_a) == MR_DEPENDENCE_CLIQUE (addr_b)
+      && MR_DEPENDENCE_BASE (addr_a) != MR_DEPENDENCE_BASE (addr_b))
+    return false;
+
   /* If we had an evolution in a pointer-based MEM_REF BASE_OBJECT we
      do not know the size of the base-object.  So we cannot do any
      offset/overlap based analysis but have to rely on points-to
      information only.  */
   if (TREE_CODE (addr_a) == MEM_REF
-      && TREE_CODE (TREE_OPERAND (addr_a, 0)) == SSA_NAME)
+      && (DR_UNCONSTRAINED_BASE (a)
+         || TREE_CODE (TREE_OPERAND (addr_a, 0)) == SSA_NAME))
     {
       /* For true dependences we can apply TBAA.  */
       if (flag_strict_aliasing
@@ -1409,7 +1459,8 @@ dr_may_alias_p (const struct data_reference *a, const struct data_reference *b,
                                       build_fold_addr_expr (addr_b));
     }
   else if (TREE_CODE (addr_b) == MEM_REF
-          && TREE_CODE (TREE_OPERAND (addr_b, 0)) == SSA_NAME)
+          && (DR_UNCONSTRAINED_BASE (b)
+              || TREE_CODE (TREE_OPERAND (addr_b, 0)) == SSA_NAME))
     {
       /* For true dependences we can apply TBAA.  */
       if (flag_strict_aliasing
@@ -2088,7 +2139,7 @@ initialize_matrix_A (lambda_matrix A, tree chrec, unsigned index, int mult)
        return chrec_fold_op (TREE_CODE (chrec), chrec_type (chrec), op0, op1);
       }
 
-    case NOP_EXPR:
+    CASE_CONVERT:
       {
        tree op = initialize_matrix_A (A, TREE_OPERAND (chrec, 0), index, mult);
        return chrec_convert (chrec_type (chrec), op, NULL);
@@ -2351,18 +2402,6 @@ lambda_matrix_row_add (lambda_matrix mat, int n, int r1, int r2, int const1)
     mat[r2][i] += const1 * mat[r1][i];
 }
 
-/* Swap rows R1 and R2 in matrix MAT.  */
-
-static void
-lambda_matrix_row_exchange (lambda_matrix mat, int r1, int r2)
-{
-  lambda_vector row;
-
-  row = mat[r1];
-  mat[r1] = mat[r2];
-  mat[r2] = row;
-}
-
 /* Multiply vector VEC1 of length SIZE by a constant CONST1,
    and store the result in VEC2.  */
 
@@ -2443,10 +2482,10 @@ lambda_matrix_right_hermite (lambda_matrix A, int m, int n,
                  factor = sigma * (a / b);
 
                  lambda_matrix_row_add (S, n, i, i-1, -factor);
-                 lambda_matrix_row_exchange (S, i, i-1);
+                 std::swap (S[i], S[i-1]);
 
                  lambda_matrix_row_add (U, m, i, i-1, -factor);
-                 lambda_matrix_row_exchange (U, i, i-1);
+                 std::swap (U[i], U[i-1]);
                }
            }
        }
@@ -4387,7 +4426,8 @@ get_references_in_stmt (gimple stmt, vec<data_ref_loc, va_heap> *references)
        clobbers_memory = true;
     }
   else if (stmt_code == GIMPLE_ASM
-          && (gimple_asm_volatile_p (stmt) || gimple_vuse (stmt)))
+          && (gimple_asm_volatile_p (as_a <gasm *> (stmt))
+              || gimple_vuse (stmt)))
     clobbers_memory = true;
 
   if (!gimple_vuse (stmt))