[gcc r14-9705] Hash operands of PHI in ipa-icf

Jan Hubicka hubicka@gcc.gnu.org
Thu Mar 28 12:25:09 GMT 2024


https://gcc.gnu.org/g:0923fe2d4808c16b72c1d1bfe28220dd326d8b76

commit r14-9705-g0923fe2d4808c16b72c1d1bfe28220dd326d8b76
Author: Jan Hubicka <jh@suse.cz>
Date:   Thu Mar 28 13:24:54 2024 +0100

    Hash operands of PHI in ipa-icf
    
    This patch fixes cache colision on function whose body differs only by constants
    at PHI operands.  As for
    
    if (test)
      a = cst1;
    else
      a = cst2;
    
    gcc/ChangeLog:
    
            PR middle-end/113907
            * ipa-icf.cc (sem_function::init): Hash PHI operands
            (sem_function::compare_phi_node): Add argument about preserving order

Diff:
---
 gcc/ipa-icf.cc | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/gcc/ipa-icf.cc b/gcc/ipa-icf.cc
index 120d8544988..e84922c3ef8 100644
--- a/gcc/ipa-icf.cc
+++ b/gcc/ipa-icf.cc
@@ -1387,6 +1387,23 @@ sem_function::init (ipa_icf_gimple::func_checker *checker)
 	  cfg_checksum = iterative_hash_host_wide_int (e->flags,
 			 cfg_checksum);
 
+	/* TODO: We should be able to match PHIs with different order of
+	   parameters.  This needs to be also updated in
+	   sem_function::compare_phi_node.  */
+	gphi_iterator si;
+	for (si = gsi_start_nonvirtual_phis (bb); !gsi_end_p (si);
+	     gsi_next_nonvirtual_phi (&si))
+	  {
+	    hstate.add_int (GIMPLE_PHI);
+	    gphi *phi = si.phi ();
+	    m_checker->hash_operand (gimple_phi_result (phi), hstate, 0,
+				     func_checker::OP_NORMAL);
+	    hstate.add_int (gimple_phi_num_args (phi));
+	    for (unsigned int i = 0; i < gimple_phi_num_args (phi); i++)
+	      m_checker->hash_operand (gimple_phi_arg_def (phi, i),
+				       hstate, 0, func_checker::OP_NORMAL);
+	  }
+
 	for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);
 	     gsi_next (&gsi))
 	  {
@@ -1579,6 +1596,8 @@ sem_function::compare_phi_node (basic_block bb1, basic_block bb2)
       if (size1 != size2)
 	return return_false ();
 
+      /* TODO: We should be able to match PHIs with different order of
+	 parameters.  This needs to be also updated in sem_function::init.  */
       for (i = 0; i < size1; ++i)
 	{
 	  t1 = gimple_phi_arg (phi1, i)->def;


More information about the Gcc-cvs mailing list