]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
builtins.c (fold_builtin_memory_op): Use the alias oracle to query if the memory...
authorRichard Guenther <rguenther@suse.de>
Mon, 31 Aug 2009 12:52:17 +0000 (12:52 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 31 Aug 2009 12:52:17 +0000 (12:52 +0000)
2009-08-31  Richard Guenther  <rguenther@suse.de>

* builtins.c (fold_builtin_memory_op): Use the alias oracle
to query if the memory regions for memmove overlap.
* tree-ssa-alias.c (ptr_deref_may_alias_decl_p): Relax the
asserts on pointers, instead deal with odd trees.
(ptr_derefs_may_alias_p): Likewise.
(refs_may_alias_p_1): Constructor bases also never alias.

From-SVN: r151241

gcc/ChangeLog
gcc/builtins.c
gcc/tree-ssa-alias.c

index edb982c0256ce87e390ff2b9fbfd9934bb4a69f8..928235524fabd8b82e52dc9ac95869fc854e3003 100644 (file)
@@ -1,3 +1,12 @@
+2009-08-31  Richard Guenther  <rguenther@suse.de>
+
+       * builtins.c (fold_builtin_memory_op): Use the alias oracle
+       to query if the memory regions for memmove overlap.
+       * tree-ssa-alias.c (ptr_deref_may_alias_decl_p): Relax the
+       asserts on pointers, instead deal with odd trees.
+       (ptr_derefs_may_alias_p): Likewise.
+       (refs_may_alias_p_1): Constructor bases also never alias.
+
 2009-08-31  Gerald Pfeifer  <gerald@pfeifer.com>
 
        * doc/install.texi (Final install): Adjust reference on where to
index 1a9e96653df90c381d79852c2a6711d052f5926f..ed97d485167c60a43e9c4ddc95475bd3733f4d06 100644 (file)
@@ -8990,6 +8990,8 @@ fold_builtin_memory_op (location_t loc, tree dest, tree src,
 
       if (endp == 3)
        {
+         ao_ref srcref, destref;
+
          src_align = get_pointer_alignment (src, BIGGEST_ALIGNMENT);
          dest_align = get_pointer_alignment (dest, BIGGEST_ALIGNMENT);
 
@@ -9012,62 +9014,16 @@ fold_builtin_memory_op (location_t loc, tree dest, tree src,
            }
 
          /* If *src and *dest can't overlap, optimize into memcpy as well.  */
-         srcvar = build_fold_indirect_ref_loc (loc, src);
-         destvar = build_fold_indirect_ref_loc (loc, dest);
-         if (srcvar
-             && !TREE_THIS_VOLATILE (srcvar)
-             && destvar
-             && !TREE_THIS_VOLATILE (destvar))
+         ao_ref_init_from_ptr_and_size (&srcref, src, len);
+         ao_ref_init_from_ptr_and_size (&destref, dest, len);
+         if (!refs_may_alias_p_1 (&srcref, &destref, false))
            {
-             tree src_base, dest_base, fn;
-             HOST_WIDE_INT src_offset = 0, dest_offset = 0;
-             HOST_WIDE_INT size = -1;
-             HOST_WIDE_INT maxsize = -1;
-
-             src_base = srcvar;
-             if (handled_component_p (src_base))
-               src_base = get_ref_base_and_extent (src_base, &src_offset,
-                                                   &size, &maxsize);
-             dest_base = destvar;
-             if (handled_component_p (dest_base))
-               dest_base = get_ref_base_and_extent (dest_base, &dest_offset,
-                                                    &size, &maxsize);
-             if (host_integerp (len, 1))
-               {
-                 maxsize = tree_low_cst (len, 1);
-                 if (maxsize
-                     > INTTYPE_MAXIMUM (HOST_WIDE_INT) / BITS_PER_UNIT)
-                   maxsize = -1;
-                 else
-                   maxsize *= BITS_PER_UNIT;
-               }
-             else
-               maxsize = -1;
-             if (SSA_VAR_P (src_base)
-                 && SSA_VAR_P (dest_base))
-               {
-                 if (operand_equal_p (src_base, dest_base, 0)
-                     && ranges_overlap_p (src_offset, maxsize,
-                                          dest_offset, maxsize))
-                   return NULL_TREE;
-               }
-             else if (TREE_CODE (src_base) == INDIRECT_REF
-                      && TREE_CODE (dest_base) == INDIRECT_REF)
-               {
-                 if (! operand_equal_p (TREE_OPERAND (src_base, 0),
-                                        TREE_OPERAND (dest_base, 0), 0)
-                     || ranges_overlap_p (src_offset, maxsize,
-                                          dest_offset, maxsize))
-                   return NULL_TREE;
-               }
-             else
-               return NULL_TREE;
-
-             fn = implicit_built_in_decls[BUILT_IN_MEMCPY];
+             tree fn = implicit_built_in_decls[BUILT_IN_MEMCPY];
              if (!fn)
                return NULL_TREE;
              return build_call_expr_loc (loc, fn, 3, dest, src, len);
            }
+
          return NULL_TREE;
        }
 
index 7e83a84b82ce063dac09d617b5aa1c082bd8c269..14f1fb47006f422d0d42672a9dd5d216afd3c60b 100644 (file)
@@ -168,12 +168,9 @@ ptr_deref_may_alias_decl_p (tree ptr, tree decl)
 {
   struct ptr_info_def *pi;
 
-  gcc_assert ((TREE_CODE (ptr) == SSA_NAME
-              || TREE_CODE (ptr) == ADDR_EXPR
-              || TREE_CODE (ptr) == INTEGER_CST)
-             && (TREE_CODE (decl) == VAR_DECL
-                 || TREE_CODE (decl) == PARM_DECL
-                 || TREE_CODE (decl) == RESULT_DECL));
+  gcc_assert (TREE_CODE (decl) == VAR_DECL
+             || TREE_CODE (decl) == PARM_DECL
+             || TREE_CODE (decl) == RESULT_DECL);
 
   /* Non-aliased variables can not be pointed to.  */
   if (!may_be_aliased (decl))
@@ -197,9 +194,9 @@ ptr_deref_may_alias_decl_p (tree ptr, tree decl)
        return true;
     }
 
-  /* We can end up with dereferencing constant pointers.
+  /* We can end up with dereferencing non-SSA name pointers.
      Just bail out in this case.  */
-  if (TREE_CODE (ptr) == INTEGER_CST)
+  if (TREE_CODE (ptr) != SSA_NAME)
     return true;
 
   /* If we do not have useful points-to information for this pointer
@@ -220,13 +217,6 @@ ptr_derefs_may_alias_p (tree ptr1, tree ptr2)
 {
   struct ptr_info_def *pi1, *pi2;
 
-  gcc_assert ((TREE_CODE (ptr1) == SSA_NAME
-              || TREE_CODE (ptr1) == ADDR_EXPR
-              || TREE_CODE (ptr1) == INTEGER_CST)
-             && (TREE_CODE (ptr2) == SSA_NAME
-                 || TREE_CODE (ptr2) == ADDR_EXPR
-                 || TREE_CODE (ptr2) == INTEGER_CST));
-
   /* ADDR_EXPR pointers either just offset another pointer or directly
      specify the pointed-to set.  */
   if (TREE_CODE (ptr1) == ADDR_EXPR)
@@ -254,10 +244,10 @@ ptr_derefs_may_alias_p (tree ptr1, tree ptr2)
        return true;
     }
 
-  /* We can end up with dereferencing constant pointers.
+  /* We can end up with dereferencing non-SSA name pointers.
      Just bail out in this case.  */
-  if (TREE_CODE (ptr1) == INTEGER_CST
-      || TREE_CODE (ptr2) == INTEGER_CST)
+  if (TREE_CODE (ptr1) != SSA_NAME 
+      || TREE_CODE (ptr2) != SSA_NAME)
     return true;
 
   /* We may end up with two empty points-to solutions for two same pointers.
@@ -781,7 +771,9 @@ refs_may_alias_p_1 (ao_ref *ref1, ao_ref *ref2, bool tbaa_p)
   if (TREE_CODE (base1) == SSA_NAME
       || TREE_CODE (base2) == SSA_NAME
       || is_gimple_min_invariant (base1)
-      || is_gimple_min_invariant (base2))
+      || is_gimple_min_invariant (base2)
+      || TREE_CODE (base1) == CONSTRUCTOR
+      || TREE_CODE (base2) == CONSTRUCTOR)
     return false;
 
   /* Defer to simple offset based disambiguation if we have