public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-7613] tree-optimization/104880 - update-address-taken and cmpxchg
@ 2022-03-11 14:03 Richard Biener
0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2022-03-11 14:03 UTC (permalink / raw)
To: gcc-cvs
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))
{
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-03-11 14:03 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-11 14:03 [gcc r12-7613] tree-optimization/104880 - update-address-taken and cmpxchg Richard Biener
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).