From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id 427C83858037; Fri, 11 Mar 2022 14:03:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 427C83858037 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Richard Biener To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-7613] tree-optimization/104880 - update-address-taken and cmpxchg X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/master X-Git-Oldrev: 69619acd8d9b5856f5af6e5323d9c7c4ec9ad08f X-Git-Newrev: eb5edcf3f3ae008a1c55c88f08a886a5f350a759 Message-Id: <20220311140325.427C83858037@sourceware.org> Date: Fri, 11 Mar 2022 14:03:25 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Mar 2022 14:03:25 -0000 https://gcc.gnu.org/g:eb5edcf3f3ae008a1c55c88f08a886a5f350a759 commit r12-7613-geb5edcf3f3ae008a1c55c88f08a886a5f350a759 Author: Richard Biener 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 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(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)) {