public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 0/4] rtl-ssa: Some small, obvious fixes
@ 2023-10-24 10:29 Richard Sandiford
  2023-10-24 10:29 ` [PATCH 1/4] rtl-ssa: Fix null deref in first_any_insn_use Richard Sandiford
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Richard Sandiford @ 2023-10-24 10:29 UTC (permalink / raw)
  To: gcc-patches; +Cc: Richard Sandiford

This series contains some small fixes to RTL-SSA.  Tested on
aarch64-linux-gnu & x86_64-linux-gnu, pushed as obvious.

Richard Sandiford (4):
  rtl-ssa: Fix null deref in first_any_insn_use
  rtl-ssa: Fix handling of deleted insns
  rtl-ssa: Don't insert after insns that can throw
  rtl-ssa: Avoid creating duplicated phis

 gcc/rtl-ssa.h              | 1 +
 gcc/rtl-ssa/blocks.cc      | 5 +++++
 gcc/rtl-ssa/changes.cc     | 5 ++++-
 gcc/rtl-ssa/member-fns.inl | 2 +-
 gcc/rtl-ssa/movement.h     | 3 ++-
 5 files changed, 13 insertions(+), 3 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/4] rtl-ssa: Fix null deref in first_any_insn_use
  2023-10-24 10:29 [PATCH 0/4] rtl-ssa: Some small, obvious fixes Richard Sandiford
@ 2023-10-24 10:29 ` Richard Sandiford
  2023-10-24 10:29 ` [PATCH 2/4] rtl-ssa: Fix handling of deleted insns Richard Sandiford
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Richard Sandiford @ 2023-10-24 10:29 UTC (permalink / raw)
  To: gcc-patches; +Cc: Richard Sandiford

first_any_insn_use implicitly (but contrary to its documentation)
assumed that there was at least one use.

gcc/
	* rtl-ssa/member-fns.inl (first_any_insn_use): Handle null
	m_first_use.
---
 gcc/rtl-ssa/member-fns.inl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/rtl-ssa/member-fns.inl b/gcc/rtl-ssa/member-fns.inl
index c127fab8b98..3fdca14e0ef 100644
--- a/gcc/rtl-ssa/member-fns.inl
+++ b/gcc/rtl-ssa/member-fns.inl
@@ -215,7 +215,7 @@ set_info::last_nondebug_insn_use () const
 inline use_info *
 set_info::first_any_insn_use () const
 {
-  if (m_first_use->is_in_any_insn ())
+  if (m_first_use && m_first_use->is_in_any_insn ())
     return m_first_use;
   return nullptr;
 }
-- 
2.25.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/4] rtl-ssa: Fix handling of deleted insns
  2023-10-24 10:29 [PATCH 0/4] rtl-ssa: Some small, obvious fixes Richard Sandiford
  2023-10-24 10:29 ` [PATCH 1/4] rtl-ssa: Fix null deref in first_any_insn_use Richard Sandiford
@ 2023-10-24 10:29 ` Richard Sandiford
  2023-10-24 10:29 ` [PATCH 3/4] rtl-ssa: Don't insert after insns that can throw Richard Sandiford
  2023-10-24 10:30 ` [PATCH 4/4] rtl-ssa: Avoid creating duplicated phis Richard Sandiford
  3 siblings, 0 replies; 5+ messages in thread
From: Richard Sandiford @ 2023-10-24 10:29 UTC (permalink / raw)
  To: gcc-patches; +Cc: Richard Sandiford

RTL-SSA queues up some invasive changes for later.  But sometimes
the insns involved in those changes can be deleted by later
optimisations, making the queued change unnecessary.  This patch
checks for that case.

gcc/
	* rtl-ssa/changes.cc (function_info::perform_pending_updates): Check
	whether an insn has been replaced by a note.
---
 gcc/rtl-ssa/changes.cc | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gcc/rtl-ssa/changes.cc b/gcc/rtl-ssa/changes.cc
index 73ab3ccfd24..de6222ae736 100644
--- a/gcc/rtl-ssa/changes.cc
+++ b/gcc/rtl-ssa/changes.cc
@@ -983,7 +983,10 @@ function_info::perform_pending_updates ()
   for (insn_info *insn : m_queued_insn_updates)
     {
       rtx_insn *rtl = insn->rtl ();
-      if (JUMP_P (rtl))
+      if (NOTE_P (rtl))
+	// The insn was later optimized away, typically to a NOTE_INSN_DELETED.
+	;
+      else if (JUMP_P (rtl))
 	{
 	  if (INSN_CODE (rtl) == NOOP_MOVE_INSN_CODE)
 	    {
-- 
2.25.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 3/4] rtl-ssa: Don't insert after insns that can throw
  2023-10-24 10:29 [PATCH 0/4] rtl-ssa: Some small, obvious fixes Richard Sandiford
  2023-10-24 10:29 ` [PATCH 1/4] rtl-ssa: Fix null deref in first_any_insn_use Richard Sandiford
  2023-10-24 10:29 ` [PATCH 2/4] rtl-ssa: Fix handling of deleted insns Richard Sandiford
@ 2023-10-24 10:29 ` Richard Sandiford
  2023-10-24 10:30 ` [PATCH 4/4] rtl-ssa: Avoid creating duplicated phis Richard Sandiford
  3 siblings, 0 replies; 5+ messages in thread
From: Richard Sandiford @ 2023-10-24 10:29 UTC (permalink / raw)
  To: gcc-patches; +Cc: Richard Sandiford

rtl_ssa::can_insert_after didn't handle insns that can throw.
Fixing that avoids a regression with a later patch.

gcc/
	* rtl-ssa.h: Include cfgbuild.h.
	* rtl-ssa/movement.h (can_insert_after): Replace is_jump with the
	more comprehensive control_flow_insn_p.
---
 gcc/rtl-ssa.h          | 1 +
 gcc/rtl-ssa/movement.h | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/gcc/rtl-ssa.h b/gcc/rtl-ssa.h
index 7355c6c4463..3a3c8b50ee2 100644
--- a/gcc/rtl-ssa.h
+++ b/gcc/rtl-ssa.h
@@ -49,6 +49,7 @@
 #include "obstack-utils.h"
 #include "mux-utils.h"
 #include "rtlanal.h"
+#include "cfgbuild.h"
 
 // Provides the global crtl->ssa.
 #include "memmodel.h"
diff --git a/gcc/rtl-ssa/movement.h b/gcc/rtl-ssa/movement.h
index d9945f49172..67370947dbd 100644
--- a/gcc/rtl-ssa/movement.h
+++ b/gcc/rtl-ssa/movement.h
@@ -61,7 +61,8 @@ move_earlier_than (insn_range_info range, insn_info *insn)
 inline bool
 can_insert_after (insn_info *insn)
 {
-  return insn->is_bb_head () || (insn->is_real () && !insn->is_jump ());
+  return (insn->is_bb_head ()
+	  || (insn->is_real () && !control_flow_insn_p (insn->rtl ())));
 }
 
 // Try to restrict move range MOVE_RANGE so that it is possible to
-- 
2.25.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 4/4] rtl-ssa: Avoid creating duplicated phis
  2023-10-24 10:29 [PATCH 0/4] rtl-ssa: Some small, obvious fixes Richard Sandiford
                   ` (2 preceding siblings ...)
  2023-10-24 10:29 ` [PATCH 3/4] rtl-ssa: Don't insert after insns that can throw Richard Sandiford
@ 2023-10-24 10:30 ` Richard Sandiford
  3 siblings, 0 replies; 5+ messages in thread
From: Richard Sandiford @ 2023-10-24 10:30 UTC (permalink / raw)
  To: gcc-patches; +Cc: Richard Sandiford

If make_uses_available was called twice for the same use,
we could end up trying to create duplicate definitions for
the same extended live range.

gcc/
	* rtl-ssa/blocks.cc (function_info::create_degenerate_phi): Check
	whether the requested phi already exists.
---
 gcc/rtl-ssa/blocks.cc | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/gcc/rtl-ssa/blocks.cc b/gcc/rtl-ssa/blocks.cc
index d46cbf1e388..ecce7a68c59 100644
--- a/gcc/rtl-ssa/blocks.cc
+++ b/gcc/rtl-ssa/blocks.cc
@@ -525,6 +525,11 @@ function_info::create_phi (ebb_info *ebb, resource_info resource,
 phi_info *
 function_info::create_degenerate_phi (ebb_info *ebb, set_info *def)
 {
+  // Allow the function to be called twice in succession for the same def.
+  def_lookup dl = find_def (def->resource (), ebb->phi_insn ());
+  if (set_info *set = dl.matching_set ())
+    return as_a<phi_info *> (set);
+
   access_info *input = def;
   phi_info *phi = create_phi (ebb, def->resource (), &input, 1);
   if (def->is_reg ())
-- 
2.25.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-10-24 10:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-24 10:29 [PATCH 0/4] rtl-ssa: Some small, obvious fixes Richard Sandiford
2023-10-24 10:29 ` [PATCH 1/4] rtl-ssa: Fix null deref in first_any_insn_use Richard Sandiford
2023-10-24 10:29 ` [PATCH 2/4] rtl-ssa: Fix handling of deleted insns Richard Sandiford
2023-10-24 10:29 ` [PATCH 3/4] rtl-ssa: Don't insert after insns that can throw Richard Sandiford
2023-10-24 10:30 ` [PATCH 4/4] rtl-ssa: Avoid creating duplicated phis Richard Sandiford

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).