https://gcc.gnu.org/g:5846fcf649c0df58099b5825d3c1ca6f29ece6c3

commit 5846fcf649c0df58099b5825d3c1ca6f29ece6c3
Author: Ondřej Machota <ondrejmach...@gmail.com>
Date:   Mon Jul 7 18:04:25 2025 +0200

    rtl-ssa-dce: remove uses of dead notes

Diff:
---
 gcc/dce.cc             | 26 ++++++++++++--------------
 gcc/rtl-ssa/changes.cc | 12 +++++++++++-
 2 files changed, 23 insertions(+), 15 deletions(-)

diff --git a/gcc/dce.cc b/gcc/dce.cc
index 3654a5101106..d564935a82f3 100644
--- a/gcc/dce.cc
+++ b/gcc/dce.cc
@@ -1402,14 +1402,22 @@ rtl_ssa_dce::is_rtx_pattern_prelive (const_rtx insn)
     }
 }
 
+// Return true if an call INSN can be deleted
 bool
 rtl_ssa_dce::can_delete_call (const_rtx insn)
 {
   gcc_checking_assert (CALL_P (insn));
 
-  if (cfun->can_delete_dead_exceptions)
-    return true;
-  return insn_nothrow_p (insn);
+  // We cannot delete pure or const sibling calls because it is
+  // hard to see the result.
+  return !SIBLING_CALL_P (insn)
+    // We can delete dead const or pure calls as long as they do not
+    // infinite loop.
+    && (RTL_CONST_OR_PURE_CALL_P (insn)
+      && !RTL_LOOPING_CONST_OR_PURE_CALL_P (insn))
+    // Don't delete calls that may throw if we cannot do so.
+    && cfun->can_delete_dead_exceptions 
+    && insn_nothrow_p (insn);
 }
 
 bool
@@ -1417,16 +1425,7 @@ rtl_ssa_dce::is_rtx_prelive (const_rtx insn)
 {
   gcc_checking_assert (insn != nullptr);
 
-  if (CALL_P (insn)
-      // We cannot delete pure or const sibling calls because it is
-      // hard to see the result.
-      && (!SIBLING_CALL_P (insn))
-      // We can delete dead const or pure calls as long as they do not
-      // infinite loop.
-      && (RTL_CONST_OR_PURE_CALL_P (insn)
-         && !RTL_LOOPING_CONST_OR_PURE_CALL_P (insn))
-      // Don't delete calls that may throw if we cannot do so.
-      && can_delete_call (insn))
+  if (CALL_P (insn) && can_delete_call (insn))
     return false;
 
   if (!NONJUMP_INSN_P (insn))
@@ -1690,7 +1689,6 @@ rtl_ssa_dce::sweep ()
 
   auto_vec<insn_change> to_delete;
 
-  // Previously created debug instructions won't be visited here
   for (insn_info *insn : crtl->ssa->nondebug_insns ())
     {
       // Artificial (bb_head, bb_end, phi), marked or debug instructions
diff --git a/gcc/rtl-ssa/changes.cc b/gcc/rtl-ssa/changes.cc
index 6598ebc1df13..a9b1a00475dd 100644
--- a/gcc/rtl-ssa/changes.cc
+++ b/gcc/rtl-ssa/changes.cc
@@ -287,7 +287,17 @@ function_info::process_uses_of_deleted_def (set_info *set)
        {
          // following assert causes crash when running rtl_ssa_dce with
          // deleting eq_notes on testsuite
-         // gcc_assert (use->is_live_out_use ());
+         if (use->only_occurs_in_notes ())
+         {
+               insn_info *insn =  use->insn ();
+               rtx_insn *rtl = insn->rtl ();
+               // TODO: remove note from rtl
+         }
+         else
+         {
+               gcc_assert (use->is_live_out_use ());
+         }
+
          remove_use (use);
        }
       // The phi handling above might have removed multiple uses of this_set.

Reply via email to