]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
2014-02-07 Richard Biener <rguenther@suse.de>
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 7 Feb 2014 09:33:23 +0000 (09:33 +0000)
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 7 Feb 2014 09:33:23 +0000 (09:33 +0000)
PR middle-end/60092
* builtin-types.def (BT_FN_INT_PTRPTR_SIZE_SIZE): Add.
* builtins.def (BUILT_IN_POSIX_MEMALIGN): Likewise.
* tree-ssa-structalias.c (find_func_aliases_for_builtin_call):
Handle BUILT_IN_POSIX_MEMALIGN.
(find_func_clobbers): Likewise.
* tree-ssa-alias.c (ref_maybe_used_by_call_p_1): Likewise.
(call_may_clobber_ref_p_1): Likewise.

* gcc.dg/tree-ssa/alias-30.c: New testcase.
* gcc.dg/tree-ssa/alias-31.c: Likewise.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@207595 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/builtin-types.def
gcc/builtins.def
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/alias-30.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/alias-31.c [new file with mode: 0644]
gcc/tree-ssa-alias.c
gcc/tree-ssa-structalias.c

index 0a0674f473851abf5ca5811a4a513ce8d53d3657..07625f575c66e1fff3408ce671957b6f06130aa8 100644 (file)
@@ -1,3 +1,14 @@
+2014-02-07  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/60092
+       * builtin-types.def (BT_FN_INT_PTRPTR_SIZE_SIZE): Add.
+       * builtins.def (BUILT_IN_POSIX_MEMALIGN): Likewise.
+       * tree-ssa-structalias.c (find_func_aliases_for_builtin_call):
+       Handle BUILT_IN_POSIX_MEMALIGN.
+       (find_func_clobbers): Likewise.
+       * tree-ssa-alias.c (ref_maybe_used_by_call_p_1): Likewise.
+       (call_may_clobber_ref_p_1): Likewise.
+
 2014-02-06  Jan Hubicka  <hubicka@ucw.cz>
 
        PR ipa/59918
index 30f06d208bcf15d712eabcee912a8b1fdecce4e4..fba9c7ddd80adfc7b8a7649e317b7324a3350fa4 100644 (file)
@@ -429,6 +429,7 @@ DEF_FUNCTION_TYPE_3 (BT_FN_VOID_VPTR_I2_INT, BT_VOID, BT_VOLATILE_PTR, BT_I2, BT
 DEF_FUNCTION_TYPE_3 (BT_FN_VOID_VPTR_I4_INT, BT_VOID, BT_VOLATILE_PTR, BT_I4, BT_INT)
 DEF_FUNCTION_TYPE_3 (BT_FN_VOID_VPTR_I8_INT, BT_VOID, BT_VOLATILE_PTR, BT_I8, BT_INT)
 DEF_FUNCTION_TYPE_3 (BT_FN_VOID_VPTR_I16_INT, BT_VOID, BT_VOLATILE_PTR, BT_I16, BT_INT)
+DEF_FUNCTION_TYPE_3 (BT_FN_INT_PTRPTR_SIZE_SIZE, BT_INT, BT_PTR_PTR, BT_SIZE, BT_SIZE)
 
 DEF_FUNCTION_TYPE_4 (BT_FN_SIZE_CONST_PTR_SIZE_SIZE_FILEPTR,
                     BT_SIZE, BT_CONST_PTR, BT_SIZE, BT_SIZE, BT_FILEPTR)
index 2443a45751b5bfc475a571b7ccc3268dea2fd03e..5a76ba3291ef7ea2d91e1dfb437871899271e0fa 100644 (file)
@@ -755,6 +755,7 @@ DEF_GCC_BUILTIN        (BUILT_IN_POPCOUNT, "popcount", BT_FN_INT_UINT, ATTR_CONS
 DEF_GCC_BUILTIN        (BUILT_IN_POPCOUNTIMAX, "popcountimax", BT_FN_INT_UINTMAX, ATTR_CONST_NOTHROW_LEAF_LIST)
 DEF_GCC_BUILTIN        (BUILT_IN_POPCOUNTL, "popcountl", BT_FN_INT_ULONG, ATTR_CONST_NOTHROW_LEAF_LIST)
 DEF_GCC_BUILTIN        (BUILT_IN_POPCOUNTLL, "popcountll", BT_FN_INT_ULONGLONG, ATTR_CONST_NOTHROW_LEAF_LIST)
+DEF_EXT_LIB_BUILTIN    (BUILT_IN_POSIX_MEMALIGN, "posix_memalign", BT_FN_INT_PTRPTR_SIZE_SIZE, ATTR_NOTHROW_NONNULL_LEAF)
 DEF_GCC_BUILTIN        (BUILT_IN_PREFETCH, "prefetch", BT_FN_VOID_CONST_PTR_VAR, ATTR_NOVOPS_LEAF_LIST)
 DEF_LIB_BUILTIN        (BUILT_IN_REALLOC, "realloc", BT_FN_PTR_PTR_SIZE, ATTR_NOTHROW_LEAF_LIST)
 DEF_GCC_BUILTIN        (BUILT_IN_RETURN, "return", BT_FN_VOID_PTR, ATTR_NORETURN_NOTHROW_LEAF_LIST)
index 45f215e239c79ec25d60cb24aaa47b9a54fca6f2..a75accc259d4811e8b1822a6c76218d154959146 100644 (file)
@@ -1,3 +1,9 @@
+2014-02-07  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/60092
+       * gcc.dg/tree-ssa/alias-30.c: New testcase.
+       * gcc.dg/tree-ssa/alias-31.c: Likewise.
+
 2014-02-06  Jan Hubicka  <hubicka@ucw.cz>
 
        PR ipa/59918
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/alias-30.c b/gcc/testsuite/gcc.dg/tree-ssa/alias-30.c
new file mode 100644 (file)
index 0000000..addf128
--- /dev/null
@@ -0,0 +1,22 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-fre-details" } */
+
+extern int posix_memalign(void **memptr,
+                         __SIZE_TYPE__ alignment, __SIZE_TYPE__ size);
+
+int foo (float *p)
+{
+  int res = *p;
+  int *q;
+  void *tem;
+  if (posix_memalign (&tem, 128, 128 * sizeof (int)) != 0)
+    return 0;
+  q = (int *)tem;
+  *q = 1;
+  return res + *p;
+}
+
+/* We should be able to CSE the load from *p in the return stmt.  */
+
+/* { dg-final { scan-tree-dump "Replaced \\\*p" "fre1" } } */
+/* { dg-final { cleanup-tree-dump "fre1" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/alias-31.c b/gcc/testsuite/gcc.dg/tree-ssa/alias-31.c
new file mode 100644 (file)
index 0000000..f1aefbd
--- /dev/null
@@ -0,0 +1,24 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-cddce1" } */
+
+extern int posix_memalign(void **memptr,
+                         __SIZE_TYPE__ alignment, __SIZE_TYPE__ size);
+
+int foo (float *p)
+{
+  int res = *p;
+  struct { void *q1; void *q2; } q;
+  if (posix_memalign (&q.q1, 128, 128 * sizeof (int)) != 0)
+    return 0;
+  if (posix_memalign (&q.q2, 128, 128 * sizeof (int)) != 0)
+    return 0;
+  *((int *)q.q1) = 1;
+  *((int *)q.q2) = 2;
+  return res + *p + *((int *)q.q1) + *((int *)q.q2);
+}
+
+/* There should be only one load from *p left.  All stores and all
+   other loads should be removed.  */
+
+/* { dg-final { scan-tree-dump-times "\\\*\[^ \]" 1 "cddce1" } } */
+/* { dg-final { cleanup-tree-dump "cddce1" } } */
index 2c3583be5f4d9b55f70e3cb0a1460569c4494c7e..e70627589cc6b3c7ab9fef1542357319ff65cfc1 100644 (file)
@@ -1515,6 +1515,7 @@ ref_maybe_used_by_call_p_1 (gimple call, ao_ref *ref)
        /* The following builtins do not read from memory.  */
        case BUILT_IN_FREE:
        case BUILT_IN_MALLOC:
+       case BUILT_IN_POSIX_MEMALIGN:
        case BUILT_IN_CALLOC:
        case BUILT_IN_ALLOCA:
        case BUILT_IN_ALLOCA_WITH_ALIGN:
@@ -1838,6 +1839,18 @@ call_may_clobber_ref_p_1 (gimple call, ao_ref *ref)
        case BUILT_IN_ALLOCA_WITH_ALIGN:
        case BUILT_IN_ASSUME_ALIGNED:
          return false;
+       /* But posix_memalign stores a pointer into the memory pointed to
+          by its first argument.  */
+       case BUILT_IN_POSIX_MEMALIGN:
+         {
+           tree ptrptr = gimple_call_arg (call, 0);
+           ao_ref dref;
+           ao_ref_init_from_ptr_and_size (&dref, ptrptr,
+                                          TYPE_SIZE_UNIT (ptr_type_node));
+           return (refs_may_alias_p_1 (&dref, ref, false)
+                   || (flag_errno_math
+                       && targetm.ref_may_alias_errno (ref)));
+         }
        /* Freeing memory kills the pointed-to memory.  More importantly
           the call has to serve as a barrier for moving loads and stores
           across it.  */
index 0ce134d9cb9894dcecaa537277ba0fae0b787056..402b3d1032df63b9888477b61eecfc1b000dee7e 100644 (file)
@@ -3982,7 +3982,7 @@ handle_lhs_call (gimple stmt, tree lhs, int flags, vec<ce_s> rhsc,
       struct constraint_expr tmpc;
       rhsc.create (0);
       vi = make_heapvar ("HEAP");
-      /* We marking allocated storage local, we deal with it becoming
+      /* We are marking allocated storage local, we deal with it becoming
          global by escaping and setting of vars_contains_escaped_heap.  */
       DECL_EXTERNAL (vi->decl) = 0;
       vi->is_global_var = 0;
@@ -4231,6 +4231,26 @@ find_func_aliases_for_builtin_call (gimple t)
          lhsc.release ();
          return true;
        }
+      case BUILT_IN_POSIX_MEMALIGN:
+        {
+         tree ptrptr = gimple_call_arg (t, 0);
+         get_constraint_for (ptrptr, &lhsc);
+         do_deref (&lhsc);
+         varinfo_t vi = make_heapvar ("HEAP");
+         /* We are marking allocated storage local, we deal with it becoming
+            global by escaping and setting of vars_contains_escaped_heap.  */
+         DECL_EXTERNAL (vi->decl) = 0;
+         vi->is_global_var = 0;
+         struct constraint_expr tmpc;
+         tmpc.var = vi->id;
+         tmpc.offset = 0;
+         tmpc.type = ADDRESSOF;
+         rhsc.safe_push (tmpc);
+         process_all_all_constraints (lhsc, rhsc);
+         lhsc.release ();
+         rhsc.release ();
+         return true;
+       }
       case BUILT_IN_ASSUME_ALIGNED:
        {
          tree res = gimple_call_lhs (t);
@@ -4960,6 +4980,7 @@ find_func_clobbers (gimple origt)
             its argument.  */
          case BUILT_IN_MEMSET:
          case BUILT_IN_MEMSET_CHK:
+         case BUILT_IN_POSIX_MEMALIGN:
            {
              tree dest = gimple_call_arg (t, 0);
              unsigned i;