]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: [multiple changes]
authorRichard Biener <rguenther@suse.de>
Mon, 15 Oct 2018 10:50:57 +0000 (10:50 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 15 Oct 2018 10:50:57 +0000 (10:50 +0000)
2018-10-15  Richard Biener  <rguenther@suse.de>

Backport from mainline
2018-08-23  Richard Biener  <rguenther@suse.de>

PR middle-end/87024
* tree-inline.c (copy_bb): Drop unused __builtin_va_arg_pack_len
calls.

* gcc.dg/pr87024.c: New testcase.

2018-08-17  Richard Biener  <rguenther@suse.de>

PR middle-end/86505
* tree-inline.c (copy_bb): When inlining __builtin_va_arg_pack_len ()
across a va-arg-pack using call adjust its return value accordingly.

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

From-SVN: r265159

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr87024.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/pr86505.c [new file with mode: 0644]
gcc/tree-inline.c

index b764bdd47d4aa5a75bb7aa0b12085292aa1765d1..08148ea61e05adb9dafb6acdf9a6dd0382feabeb 100644 (file)
@@ -1,3 +1,18 @@
+2018-10-15  Richard Biener  <rguenther@suse.de>
+
+       Backport from mainline
+       2018-08-23  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/87024
+       * tree-inline.c (copy_bb): Drop unused __builtin_va_arg_pack_len
+       calls.
+
+       2018-08-17  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/86505
+       * tree-inline.c (copy_bb): When inlining __builtin_va_arg_pack_len ()
+       across a va-arg-pack using call adjust its return value accordingly.
+
 2018-10-12  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
index 3c3ff112cd21f598871f3c89a5a456c3e3630762..07ad379a64a14c31b67d49577b5e55ee4fed6a3f 100644 (file)
@@ -1,3 +1,16 @@
+2018-10-15  Richard Biener  <rguenther@suse.de>
+
+       Backport from mainline
+       2018-08-23  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/87024
+       * gcc.dg/pr87024.c: New testcase.
+
+       2018-08-17  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/86505
+       * gcc.dg/torture/pr86505.c: New testcase.
+
 2018-10-12  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
diff --git a/gcc/testsuite/gcc.dg/pr87024.c b/gcc/testsuite/gcc.dg/pr87024.c
new file mode 100644 (file)
index 0000000..a8a58aa
--- /dev/null
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fno-tree-dce" } */
+
+static inline void __attribute__((always_inline))
+mp ()
+{
+  (void) __builtin_va_arg_pack_len ();
+}
+
+void
+ui (void)
+{
+  mp ();
+}
diff --git a/gcc/testsuite/gcc.dg/torture/pr86505.c b/gcc/testsuite/gcc.dg/torture/pr86505.c
new file mode 100644 (file)
index 0000000..db102d3
--- /dev/null
@@ -0,0 +1,32 @@
+/* { dg-do run } */
+
+static inline __attribute__(( __always_inline__)) int 
+funA(unsigned int param, ...) 
+{ 
+  return __builtin_va_arg_pack_len(); 
+}
+
+static inline __attribute__(( __always_inline__)) int
+funB(unsigned int param, ...)
+{ 
+  return funA(param,  2, 4, __builtin_va_arg_pack()); 
+}
+
+int 
+testBuiltin(void) 
+{ 
+  int rc = funB(0,1,2); 
+  if (rc != 4)
+    return 1;
+  return 0;
+}
+
+int
+main()
+{
+  int rc = testBuiltin();
+  if (rc == 1)
+    __builtin_abort ();
+
+  return 0;
+}
index 607e70c382ff29da357db6c043c4f69c7e99be3f..d68d76fe3f03a341975b5741b901e55632510c27 100644 (file)
@@ -1925,8 +1925,7 @@ 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
-                  && ! gimple_call_va_arg_pack_p (id->call_stmt))
+                  && DECL_FUNCTION_CODE (decl) == BUILT_IN_VA_ARG_PACK_LEN)
            {
              /* __builtin_va_arg_pack_len () should be replaced by
                 the number of anonymous arguments.  */
@@ -1944,10 +1943,32 @@ copy_bb (copy_body_data *id, basic_block bb, int frequency_scale,
                if (POINTER_BOUNDS_P (gimple_call_arg (id->call_stmt, i)))
                  nargs--;
 
-             count = build_int_cst (integer_type_node, nargs);
-             new_stmt = gimple_build_assign (gimple_call_lhs (stmt), count);
-             gsi_replace (&copy_gsi, new_stmt, false);
-             stmt = new_stmt;
+             if (!gimple_call_lhs (stmt))
+               {
+                 /* Drop unused calls.  */
+                 gsi_remove (&copy_gsi, false);
+                 continue;
+               }
+             else if (!gimple_call_va_arg_pack_p (id->call_stmt))
+               {
+                 count = build_int_cst (integer_type_node, nargs);
+                 new_stmt = gimple_build_assign (gimple_call_lhs (stmt), count);
+                 gsi_replace (&copy_gsi, new_stmt, false);
+                 stmt = new_stmt;
+               }
+             else if (nargs != 0)
+               {
+                 tree newlhs;
+                 if (gimple_in_ssa_p (cfun))
+                   newlhs = make_ssa_name (integer_type_node, NULL);
+                 else
+                   newlhs = create_tmp_reg (integer_type_node);
+                 count = build_int_cst (integer_type_node, nargs);
+                 new_stmt = gimple_build_assign (gimple_call_lhs (stmt),
+                                                 PLUS_EXPR, newlhs, count);
+                 gimple_call_set_lhs (stmt, newlhs);
+                 gsi_insert_after (&copy_gsi, new_stmt, GSI_NEW_STMT);
+               }
            }
          else if (call_stmt
                   && id->call_stmt