* [PATCH] tree-optimization/111123 - indirect clobbers thrown away too early
@ 2023-08-24 9:02 Richard Biener
0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2023-08-24 9:02 UTC (permalink / raw)
To: gcc-patches
The testcase in the PR shows that late uninit diagnostic relies
on indirect clobbers in CTORs but we throw those away in the fab
pass which is too early. The reasoning was they were supposed
to keep SSA names live but that's no longer the case since DCE
doesn't treat them as keeping SSA uses live.
The following instead removes them before out-of-SSA coalescing
which is the thing that's still affected by them.
Bootstrapped and tested on x86_64-unknown-linux-gnu, I'll push
this later if there are no quick comments.
Richard.
PR tree-optimization/111123
* tree-ssa-ccp.cc (pass_fold_builtins::execute): Do not
remove indirect clobbers here ...
* tree-outof-ssa.cc (rewrite_out_of_ssa): ... but here.
(remove_indirect_clobbers): New function.
* g++.dg/warn/Wuninitialized-pr111123-1.C: New testcase.
---
.../g++.dg/warn/Wuninitialized-pr111123-1.C | 20 ++++++++++++
gcc/tree-outof-ssa.cc | 32 ++++++++++++++++++-
gcc/tree-ssa-ccp.cc | 17 +---------
3 files changed, 52 insertions(+), 17 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/warn/Wuninitialized-pr111123-1.C
diff --git a/gcc/testsuite/g++.dg/warn/Wuninitialized-pr111123-1.C b/gcc/testsuite/g++.dg/warn/Wuninitialized-pr111123-1.C
new file mode 100644
index 00000000000..17a6f2b28d8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wuninitialized-pr111123-1.C
@@ -0,0 +1,20 @@
+// { dg-do compile }
+// { dg-require-effective-target c++11 }
+// { dg-options "-O -Wuninitialized" }
+
+#include <vector>
+
+struct Camera {
+ struct P2d {
+ float x, y;
+ };
+ std::vector<P2d> clip_area;
+ float border = 10.f;
+ [[gnu::noinline]] Camera() : clip_area({{border,border}}) { } // { dg-warning "uninitialized" }
+};
+
+Camera foo()
+{
+ Camera c;
+ return c;
+}
diff --git a/gcc/tree-outof-ssa.cc b/gcc/tree-outof-ssa.cc
index 0bf57a4bbc5..767623ab8ea 100644
--- a/gcc/tree-outof-ssa.cc
+++ b/gcc/tree-outof-ssa.cc
@@ -1283,6 +1283,33 @@ insert_backedge_copies (void)
}
}
+/* Remove indirect clobbers. */
+
+static void
+remove_indirect_clobbers (void)
+{
+ basic_block bb;
+
+ FOR_EACH_BB_FN (bb, cfun)
+ for (auto gsi = gsi_start_bb (bb); !gsi_end_p (gsi);)
+ {
+ gimple *stmt = gsi_stmt (gsi);
+ if (gimple_clobber_p (stmt))
+ {
+ tree lhs = gimple_assign_lhs (stmt);
+ if (TREE_CODE (lhs) == MEM_REF
+ && TREE_CODE (TREE_OPERAND (lhs, 0)) == SSA_NAME)
+ {
+ unlink_stmt_vdef (stmt);
+ gsi_remove (&gsi, true);
+ release_defs (stmt);
+ continue;
+ }
+ }
+ gsi_next (&gsi);
+ }
+}
+
/* Free all memory associated with going out of SSA form. SA is
the outof-SSA info object. */
@@ -1305,6 +1332,10 @@ finish_out_of_ssa (struct ssaexpand *sa)
unsigned int
rewrite_out_of_ssa (struct ssaexpand *sa)
{
+ /* Remove remaining indirect clobbers as we do not need those anymore.
+ Those might extend SSA lifetime and restrict coalescing. */
+ remove_indirect_clobbers ();
+
/* If elimination of a PHI requires inserting a copy on a backedge,
then we will have to split the backedge which has numerous
undesirable performance effects.
@@ -1313,7 +1344,6 @@ rewrite_out_of_ssa (struct ssaexpand *sa)
copies into the loop itself. */
insert_backedge_copies ();
-
/* Eliminate PHIs which are of no use, such as virtual or dead phis. */
eliminate_useless_phis ();
diff --git a/gcc/tree-ssa-ccp.cc b/gcc/tree-ssa-ccp.cc
index 15e65f16008..e048675577f 100644
--- a/gcc/tree-ssa-ccp.cc
+++ b/gcc/tree-ssa-ccp.cc
@@ -4302,22 +4302,7 @@ pass_fold_builtins::execute (function *fun)
if (gimple_code (stmt) != GIMPLE_CALL)
{
- /* Remove all *ssaname_N ={v} {CLOBBER}; stmts,
- after the last GIMPLE DSE they aren't needed and might
- unnecessarily keep the SSA_NAMEs live. */
- if (gimple_clobber_p (stmt))
- {
- tree lhs = gimple_assign_lhs (stmt);
- if (TREE_CODE (lhs) == MEM_REF
- && TREE_CODE (TREE_OPERAND (lhs, 0)) == SSA_NAME)
- {
- unlink_stmt_vdef (stmt);
- gsi_remove (&i, true);
- release_defs (stmt);
- continue;
- }
- }
- else if (gimple_assign_load_p (stmt) && gimple_store_p (stmt))
+ if (gimple_assign_load_p (stmt) && gimple_store_p (stmt))
optimize_memcpy (&i, gimple_assign_lhs (stmt),
gimple_assign_rhs1 (stmt), NULL_TREE);
gsi_next (&i);
--
2.35.3
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-08-24 9:02 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-24 9:02 [PATCH] tree-optimization/111123 - indirect clobbers thrown away too early 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).