]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Backport PRs 80122, 80222, 80334, 80539
authorRichard Biener <rguenther@suse.de>
Wed, 10 May 2017 07:53:45 +0000 (07:53 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 10 May 2017 07:53:45 +0000 (07:53 +0000)
2017-05-10  Richard Biener  <rguenther@suse.de>

Backport from mainline
2017-03-21  Richard Biener  <rguenther@suse.de>

PR tree-optimization/80122
* tree-inline.c (copy_bb): Do not expans va-arg packs or
va_arg_pack_len when the inlined call stmt requires pack
expansion itself.
* tree-inline.h (struct copy_body_data): Make call_stmt a gcall *.

* gcc.dg/torture/pr80122.c: New testcase.

2017-03-28  Richard Biener  <rguenther@suse.de>

PR middle-end/80222
* gimple-fold.c (gimple_fold_indirect_ref): Do not touch
TYPE_REF_CAN_ALIAS_ALL references.
* fold-const.c (fold_indirect_ref_1): Likewise.

* g++.dg/pr80222.C: New testcase.

2017-04-06  Richard Biener  <rguenther@suse.de>

PR tree-optimization/80334
* tree-ssa-loop-ivopts.c (rewrite_use_address): Properly
preserve alignment of accesses.

* g++.dg/torture/pr80334.C: New testcase.

2017-04-27  Richard Biener  <rguenther@suse.de>

PR middle-end/80539
* tree-chrec.c (chrec_fold_plus_poly_poly): Deal with not
being in loop-closed SSA form conservatively.
(chrec_fold_multiply_poly_poly): Likewise.

* gcc.dg/torture/pr80539.c: New testcase.

From-SVN: r247827

12 files changed:
gcc/ChangeLog
gcc/fold-const.c
gcc/gimple-fold.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/pr80222.C [new file with mode: 0644]
gcc/testsuite/g++.dg/torture/pr80334.C [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/pr80122.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/pr80539.c [new file with mode: 0644]
gcc/tree-chrec.c
gcc/tree-inline.c
gcc/tree-inline.h
gcc/tree-ssa-loop-ivopts.c

index 8058a1b4c6efedd73ed1a6c399e886d6dfb05bc6..9d509b935b1e6f7b40ed597c34fe3fb484bd5db7 100644 (file)
@@ -1,3 +1,34 @@
+2017-05-10  Richard Biener  <rguenther@suse.de>
+
+       Backport from mainline
+       2017-03-21  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/80122
+       * tree-inline.c (copy_bb): Do not expans va-arg packs or
+       va_arg_pack_len when the inlined call stmt requires pack
+       expansion itself.
+       * tree-inline.h (struct copy_body_data): Make call_stmt a gcall *.
+
+       2017-03-28  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/80222
+       * gimple-fold.c (gimple_fold_indirect_ref): Do not touch
+       TYPE_REF_CAN_ALIAS_ALL references.
+       * fold-const.c (fold_indirect_ref_1): Likewise.
+
+       2017-04-06  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/80334
+       * tree-ssa-loop-ivopts.c (rewrite_use_address): Properly
+       preserve alignment of accesses.
+
+       2017-04-27  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/80539
+       * tree-chrec.c (chrec_fold_plus_poly_poly): Deal with not
+       being in loop-closed SSA form conservatively.
+       (chrec_fold_multiply_poly_poly): Likewise.
+
 2016-05-08  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
 
        Backport from mainline
index 7adefba83cbc1244dbcff239bf785654cc07a08c..48b32532421db536f60c0c8195f00d40de209dae 100644 (file)
@@ -15876,7 +15876,8 @@ fold_indirect_ref_1 (location_t loc, tree type, tree op0)
 
   STRIP_NOPS (sub);
   subtype = TREE_TYPE (sub);
-  if (!POINTER_TYPE_P (subtype))
+  if (!POINTER_TYPE_P (subtype)
+      || TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (op0)))
     return NULL_TREE;
 
   if (TREE_CODE (sub) == ADDR_EXPR)
index 7950cb627fd05f8652104ba512142387685c4394..81dc92064e2471a77b647d3cd7c707e04316a208 100644 (file)
@@ -5910,8 +5910,8 @@ gimple_val_nonnegative_real_p (tree val)
   return false;
 }
 
-/* Given a pointer value OP0, return a simplified version of an
-   indirection through OP0, or NULL_TREE if no simplification is
+/* Given a pointer value T, return a simplified version of an
+   indirection through T, or NULL_TREE if no simplification is
    possible.  Note that the resulting type may be different from
    the type pointed to in the sense that it is still compatible
    from the langhooks point of view. */
@@ -5925,7 +5925,8 @@ gimple_fold_indirect_ref (tree t)
 
   STRIP_NOPS (sub);
   subtype = TREE_TYPE (sub);
-  if (!POINTER_TYPE_P (subtype))
+  if (!POINTER_TYPE_P (subtype)
+      || TYPE_REF_CAN_ALIAS_ALL (ptype))
     return NULL_TREE;
 
   if (TREE_CODE (sub) == ADDR_EXPR)
index 0654ebc64114a8907ec60980db9b8ded93b4a2c5..d2b6972e15779862d98314425284094a9dfe9f94 100644 (file)
@@ -1,3 +1,26 @@
+2017-05-10  Richard Biener  <rguenther@suse.de>
+
+       Backport from mainline
+       2017-03-21  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/80122
+       * gcc.dg/torture/pr80122.c: New testcase.
+
+       2017-03-28  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/80222
+       * g++.dg/pr80222.C: New testcase.
+
+       2017-04-06  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/80334
+       * g++.dg/torture/pr80334.C: New testcase.
+
+       2017-04-27  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/80539
+       * gcc.dg/torture/pr80539.c: New testcase.
+
 2016-05-08  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
 
        Backport from mainline
diff --git a/gcc/testsuite/g++.dg/pr80222.C b/gcc/testsuite/g++.dg/pr80222.C
new file mode 100644 (file)
index 0000000..ed1b37f
--- /dev/null
@@ -0,0 +1,13 @@
+// { dg-do compile }
+// { dg-options "-O2 -fdump-tree-optimized" } */
+
+struct C { int i; }__attribute__((may_alias)) ;
+
+C a, b;
+
+int main()
+{
+  a = static_cast <C&> (b);
+}
+
+// { dg-final { scan-tree-dump "{ref-all}\\\)&b\];" "optimized" } } */
diff --git a/gcc/testsuite/g++.dg/torture/pr80334.C b/gcc/testsuite/g++.dg/torture/pr80334.C
new file mode 100644 (file)
index 0000000..ba990e7
--- /dev/null
@@ -0,0 +1,19 @@
+// { dg-do run }
+// { dg-additional-options "-std=c++11" }
+
+struct A { alignas(16) char c; };
+struct B { A unpacked; char d; } __attribute__((packed));
+
+char x;
+
+int
+main()
+{
+  alignas(__BIGGEST_ALIGNMENT__) B b[3];
+  for (int i = 0; i < 3; i++) b[i].unpacked.c = 'a' + i;
+  for (int i = 0; i < 3; i++)
+    {
+      auto a = new A(b[i].unpacked);
+      x = a->c;
+    }
+}
diff --git a/gcc/testsuite/gcc.dg/torture/pr80122.c b/gcc/testsuite/gcc.dg/torture/pr80122.c
new file mode 100644 (file)
index 0000000..a76d756
--- /dev/null
@@ -0,0 +1,52 @@
+/* { dg-do run } */
+
+#define __GNU_ALWAYS_INLINE inline __attribute__(( __always_inline__))
+
+#define DEVT_ALL    0
+
+#define CMD_ABI_DEVICES 100
+
+static __GNU_ALWAYS_INLINE int
+send_msg_to_gm_w_dev_t(int msg_type, unsigned int dev_msg_type,
+                      int devt, ...)
+{
+  char s[256];
+  int nArgs = __builtin_va_arg_pack_len();
+  if (nArgs != 2)
+    __builtin_abort ();
+  __builtin_sprintf (s, "%d", __builtin_va_arg_pack ());
+  if (__builtin_strcmp (s, "99") != 0)
+    __builtin_abort ();
+  /* do something with nArgs and ... */ 
+  return 0;
+}
+
+static __GNU_ALWAYS_INLINE int
+send_msg_to_gm(int msg_type, unsigned int dev_msg_type,
+              ...)
+{
+  int nArgs = __builtin_va_arg_pack_len();
+  if (nArgs != 2)
+    __builtin_abort ();
+  return send_msg_to_gm_w_dev_t(msg_type, dev_msg_type,
+                               DEVT_ALL, __builtin_va_arg_pack()); 
+}
+
+static __GNU_ALWAYS_INLINE int
+send_enable(unsigned int dev_msg_type, ...)
+{
+  int nArgs = __builtin_va_arg_pack_len();
+  if (nArgs != 2)
+    __builtin_abort ();
+  return send_msg_to_gm(CMD_ABI_DEVICES, dev_msg_type,  __builtin_va_arg_pack());
+}
+
+int 
+main(void)
+{
+  int mode = 99;
+
+  send_enable(1, mode, sizeof(mode));
+
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/torture/pr80539.c b/gcc/testsuite/gcc.dg/torture/pr80539.c
new file mode 100644 (file)
index 0000000..a667678
--- /dev/null
@@ -0,0 +1,22 @@
+/* { dg-do compile } */
+
+signed char a, b;
+void fn1()
+{
+  signed char c, e;
+  short d;
+  if (0) {
+      for (; d;) {
+l1:
+         for (c = 7; a; c++)
+           ;
+         e = 6;
+         for (; b; e++)
+           ;
+      }
+      c -= e;
+  }
+  if (d == 7)
+    goto l1;
+  a = c;
+}
index b4a8d821c56564a94b731bec9c7bdc65072f18fd..bbc05fbf9971e243caaf8dbfe782a77d817345ec 100644 (file)
@@ -167,7 +167,12 @@ chrec_fold_plus_poly_poly (enum tree_code code,
 
   /* This function should never be called for chrecs of loops that
      do not belong to the same loop nest.  */
-  gcc_assert (loop0 == loop1);
+  if (loop0 != loop1)
+    {
+      /* It still can happen if we are not in loop-closed SSA form.  */
+      gcc_assert (! loops_state_satisfies_p (LOOP_CLOSED_SSA));
+      return chrec_dont_know;
+    }
 
   if (code == PLUS_EXPR || code == POINTER_PLUS_EXPR)
     {
@@ -229,7 +234,12 @@ chrec_fold_multiply_poly_poly (tree type,
        chrec_fold_multiply (type, CHREC_LEFT (poly0), poly1),
        CHREC_RIGHT (poly0));
 
-  gcc_assert (loop0 == loop1);
+  if (loop0 != loop1)
+    {
+      /* It still can happen if we are not in loop-closed SSA form.  */
+      gcc_assert (! loops_state_satisfies_p (LOOP_CLOSED_SSA));
+      return chrec_dont_know;
+    }
 
   /* poly0 and poly1 are two polynomials in the same variable,
      {a, +, b}_x * {c, +, d}_x  ->  {a*c, +, a*d + b*c + b*d, +, 2*b*d}_x.  */
index 83fb5d3eb39aedf6951d56a826a9774fbb517090..71d9d239535a05a5c4922fe54cae833fd75e555f 100644 (file)
@@ -1852,7 +1852,8 @@ copy_bb (copy_body_data *id, basic_block bb, int frequency_scale,
          call_stmt = dyn_cast <gcall *> (stmt);
          if (call_stmt
              && gimple_call_va_arg_pack_p (call_stmt)
-             && id->call_stmt)
+             && id->call_stmt
+             && ! gimple_call_va_arg_pack_p (id->call_stmt))
            {
              /* __builtin_va_arg_pack () should be replaced by
                 all arguments corresponding to ... in the caller.  */
@@ -1932,7 +1933,8 @@ copy_bb (copy_body_data *id, basic_block bb, int frequency_scale,
                   && id->call_stmt
                   && (decl = gimple_call_fndecl (stmt))
                   && DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
-                  && DECL_FUNCTION_CODE (decl) == BUILT_IN_VA_ARG_PACK_LEN)
+                  && DECL_FUNCTION_CODE (decl) == BUILT_IN_VA_ARG_PACK_LEN
+                  && ! gimple_call_va_arg_pack_p (id->call_stmt))
            {
              /* __builtin_va_arg_pack_len () should be replaced by
                 the number of anonymous arguments.  */
@@ -4580,7 +4582,7 @@ expand_call_inline (basic_block bb, gimple stmt, copy_body_data *id)
   id->src_fn = fn;
   id->src_node = cg_edge->callee;
   id->src_cfun = DECL_STRUCT_FUNCTION (fn);
-  id->call_stmt = stmt;
+  id->call_stmt = call_stmt;
 
   gcc_assert (!id->src_cfun->after_inlining);
 
index f8b2ebfe2dde40d1f7bb9a7d10d42af366025500..b3f616cdeb7a42f61ed1fa0693755fa13f43b1ee 100644 (file)
@@ -101,7 +101,7 @@ struct copy_body_data
 
   /* GIMPLE_CALL if va arg parameter packs should be expanded or NULL
      is not.  */
-  gimple call_stmt;
+  gcall *call_stmt;
 
   /* Exception landing pad the inlined call lies in.  */
   int eh_lp_nr;
index 1d642610cb78db32f20456b2c10f026a92fefa91..0ef0ad55f164bd49dfb79c2dc2063d588c136a4d 100644 (file)
@@ -6628,7 +6628,11 @@ rewrite_use_address (struct ivopts_data *data,
     base_hint = var_at_stmt (data->current_loop, cand, use->stmt);
 
   iv = var_at_stmt (data->current_loop, cand, use->stmt);
-  ref = create_mem_ref (&bsi, TREE_TYPE (*use->op_p), &aff,
+  tree type = TREE_TYPE (*use->op_p);
+  unsigned int align = get_object_alignment (*use->op_p);
+  if (align != TYPE_ALIGN (type))
+    type = build_aligned_type (type, align);
+  ref = create_mem_ref (&bsi, type, &aff,
                        reference_alias_ptr_type (*use->op_p),
                        iv, base_hint, data->speed);
   copy_ref_info (ref, *use->op_p);