public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Richard Biener <rguenth@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-7613] tree-optimization/104880 - update-address-taken and cmpxchg
Date: Fri, 11 Mar 2022 14:03:25 +0000 (GMT)	[thread overview]
Message-ID: <20220311140325.427C83858037@sourceware.org> (raw)

https://gcc.gnu.org/g:eb5edcf3f3ae008a1c55c88f08a886a5f350a759

commit r12-7613-geb5edcf3f3ae008a1c55c88f08a886a5f350a759
Author: Richard Biener <rguenther@suse.de>
Date:   Fri Mar 11 14:09:33 2022 +0100

    tree-optimization/104880 - update-address-taken and cmpxchg
    
    The following addresses optimistic non-addressable marking of
    an argument of __atomic_compare_exchange_n which broke when
    I added DECL_NOT_GIMPLE_REG_P since we cannot guarantee we can
    rewrite it when TREE_ADDRESSABLE is unset.  Instead we have to
    restore TREE_ADDRESSABLE in that case.
    
    2022-03-11  Richard Biener  <rguenther@suse.de>
    
            PR tree-optimization/104880
            * tree-ssa.cc (execute_update_address_taken): Remember if we
            optimistically made something not addressable and
            prepare to undo it.
    
            * g++.dg/opt/pr104880.cc: New testcase.

Diff:
---
 gcc/testsuite/g++.dg/opt/pr104880.cc | 43 ++++++++++++++++++++++++++++++++++++
 gcc/tree-ssa.cc                      | 16 +++++++++++---
 2 files changed, 56 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/g++.dg/opt/pr104880.cc b/gcc/testsuite/g++.dg/opt/pr104880.cc
new file mode 100644
index 00000000000..de56a5acfd4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/opt/pr104880.cc
@@ -0,0 +1,43 @@
+// { dg-do compile }
+// { dg-options "-O2 -Wno-pmf-conversions -fno-checking" }
+
+class c {
+  long b;
+};
+class B {
+public:
+  typedef void *d;
+};
+class aa {
+public:
+  aa(B::d);
+};
+class e : public B {
+public:
+  e();
+};
+unsigned int f;
+struct g {
+  struct h : c {
+    h(unsigned int &i) : c(reinterpret_cast<c &>(i)) {}
+    unsigned int ad();
+  };
+};
+class n : g {
+public:
+  n(int);
+  void j() {
+    unsigned int a;
+    h k(a);
+    __atomic_compare_exchange_n(&f, &a, k.ad(), true, 3, 0);
+  }
+};
+int l;
+class m : e {
+  void ar() {
+    n b(l);
+    b.j();
+  }
+  virtual void bd() { aa(d(&m::ar)); }
+};
+void o() { new m; }
diff --git a/gcc/tree-ssa.cc b/gcc/tree-ssa.cc
index 423dd871d9e..6dcb3142869 100644
--- a/gcc/tree-ssa.cc
+++ b/gcc/tree-ssa.cc
@@ -1742,6 +1742,7 @@ execute_update_addresses_taken (void)
   auto_bitmap addresses_taken;
   auto_bitmap not_reg_needs;
   auto_bitmap suitable_for_renaming;
+  bool optimistic_not_addressable = false;
   tree var;
   unsigned i;
 
@@ -1770,6 +1771,8 @@ execute_update_addresses_taken (void)
 		  gimple_call_set_arg (stmt, 1, null_pointer_node);
 		  gimple_ior_addresses_taken (addresses_taken, stmt);
 		  gimple_call_set_arg (stmt, 1, arg);
+		  /* Remember we have to check again below.  */
+		  optimistic_not_addressable = true;
 		}
 	      else if (is_asan_mark_p (stmt)
 		       || gimple_call_internal_p (stmt, IFN_GOMP_SIMT_ENTER))
@@ -1873,7 +1876,8 @@ execute_update_addresses_taken (void)
 
   /* Operand caches need to be recomputed for operands referencing the updated
      variables and operands need to be rewritten to expose bare symbols.  */
-  if (!bitmap_empty_p (suitable_for_renaming))
+  if (!bitmap_empty_p (suitable_for_renaming)
+      || optimistic_not_addressable)
     {
       FOR_EACH_BB_FN (bb, cfun)
 	for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);)
@@ -2064,12 +2068,18 @@ execute_update_addresses_taken (void)
 		if (optimize_atomic_compare_exchange_p (stmt))
 		  {
 		    tree expected = gimple_call_arg (stmt, 1);
-		    if (bitmap_bit_p (suitable_for_renaming,
-				      DECL_UID (TREE_OPERAND (expected, 0))))
+		    tree decl = TREE_OPERAND (expected, 0);
+		    if (bitmap_bit_p (suitable_for_renaming, DECL_UID (decl)))
 		      {
 			fold_builtin_atomic_compare_exchange (&gsi);
 			continue;
 		      }
+		    else if (!TREE_ADDRESSABLE (decl))
+		      /* If there are partial defs of the decl we may
+			 have cleared the addressable bit but set
+			 DECL_NOT_GIMPLE_REG_P.  We have to restore
+			 TREE_ADDRESSABLE here.  */
+		      TREE_ADDRESSABLE (decl) = 1;
 		  }
 		else if (is_asan_mark_p (stmt))
 		  {


                 reply	other threads:[~2022-03-11 14:03 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220311140325.427C83858037@sourceware.org \
    --to=rguenth@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).