This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 1/3] Make gsi_next_nonvirtual_phi do what one expects


This refactoring makes gsi_next_nonvirtual_phi() always advance the
gimple phi iterator (regardless of whether the current phi is virtual or
not).  It matches the behavior of other gsi_next functions.

It can be applied independently of the other patches (but patch 3
depends on this one).

I regstrapped this patch separately on x86_64-pc-linux-gnu.  Ok?

>From cbf3fa8408f54baffbec79d304d930e17aa7231c Mon Sep 17 00:00:00 2001
From: Vladislav Ivanishin <vlad@ispras.ru>
Date: Thu, 29 Aug 2019 14:41:06 +0300
Subject: [PATCH 1/3] Make gsi_next_nonvirtual_phi do what one expects

gcc/:

        * gimple-iterator.h (gsi_next_nonvirtual_phi): Change the semantics to
        match that of other gsi_next_* functions.  Adjust the comment.
        (gsi_start_nonvirtual_phis): New function.
        * ipa-icf.c (sem_function::compare_phi_node): Update uses of
        gsi_next_nonvirtual_phi accordingly.  (No functional change.)
---
 gcc/gimple-iterator.h | 33 ++++++++++++++++++---------------
 gcc/ipa-icf.c         | 11 ++++-------
 2 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/gcc/gimple-iterator.h b/gcc/gimple-iterator.h
index ee6f5b1f54d..ccd93d936be 100644
--- a/gcc/gimple-iterator.h
+++ b/gcc/gimple-iterator.h
@@ -325,28 +325,31 @@ gsi_one_nondebug_before_end_p (gimple_stmt_iterator i)
   return gsi_end_p (i);
 }
 
-/* Iterates I statement iterator to the next non-virtual statement.  */
+/* Advance I statement iterator to the next non-virtual GIMPLE_PHI
+   statement.  */
 
 static inline void
 gsi_next_nonvirtual_phi (gphi_iterator *i)
 {
-  gphi *phi;
-
-  if (gsi_end_p (*i))
-    return;
-
-  phi = i->phi ();
-  gcc_assert (phi != NULL);
-
-  while (virtual_operand_p (gimple_phi_result (phi)))
+  do
     {
       gsi_next (i);
-
-      if (gsi_end_p (*i))
-	return;
-
-      phi = i->phi ();
     }
+  while (!gsi_end_p (*i) && virtual_operand_p (gimple_phi_result (i->phi ())));
+}
+
+/* Return a new iterator pointing to the first non-virtual phi statement in
+   basic block BB.  */
+
+static inline gphi_iterator
+gsi_start_nonvirtual_phis (basic_block bb)
+{
+  gphi_iterator i = gsi_start_phis (bb);
+
+  if (!gsi_end_p (i) && virtual_operand_p (gimple_phi_result (i.phi ())))
+    gsi_next_nonvirtual_phi (&i);
+
+  return i;
 }
 
 /* Return the basic block associated with this iterator.  */
diff --git a/gcc/ipa-icf.c b/gcc/ipa-icf.c
index 2174fb7494c..24d5b0e6e6c 100644
--- a/gcc/ipa-icf.c
+++ b/gcc/ipa-icf.c
@@ -1678,13 +1678,10 @@ sem_function::compare_phi_node (basic_block bb1, basic_block bb2)
   gcc_assert (bb1 != NULL);
   gcc_assert (bb2 != NULL);
 
-  si2 = gsi_start_phis (bb2);
-  for (si1 = gsi_start_phis (bb1); !gsi_end_p (si1);
-       gsi_next (&si1))
+  si2 = gsi_start_nonvirtual_phis (bb2);
+  for (si1 = gsi_start_nonvirtual_phis (bb1); !gsi_end_p (si1);
+       gsi_next_nonvirtual_phi (&si1))
     {
-      gsi_next_nonvirtual_phi (&si1);
-      gsi_next_nonvirtual_phi (&si2);
-
       if (gsi_end_p (si1) && gsi_end_p (si2))
 	break;
 
@@ -1721,7 +1718,7 @@ sem_function::compare_phi_node (basic_block bb1, basic_block bb2)
 	    return return_false ();
 	}
 
-      gsi_next (&si2);
+      gsi_next_nonvirtual_phi (&si2);
     }
 
   return true;
-- 
2.22.0

Thanks,
Vlad

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]