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] Fix latent PHI-opt bug


This fixes a miscompile that can happen when PHI-opt is entered
with a not cleaned up CFG and we have a always true/false condition
like

 if (a_1 != a_1)

or

 if (0 != 0)

in this case the check guarding

      /* If the middle basic block was empty or is defining the
         PHI arguments and this is a single phi where the args are 
different
         for the edges e0 and e1 then we can remove the middle basic 
block. */
      if (emtpy_or_with_defined_p
          && single_non_singleton_phi_for_edges (phi_nodes (gimple_bb 
(phi)),
                                                            e0, e1))
        {
          replace_phi_edge_with_variable (cond_bb, e1, phi, arg);
          /* Note that we optimized this PHI.  */
          return 2;

can run into PHI being _not_ the single non-singleton PHI as
both values in the conditional are equal.

I've remembered running into this issue before so this time I'll
fix it properly instead of just making sure to cleanup the CFG
properly ...

Bootstrap and regtest running on x86_64-unknown-linux-gnu.

Richard.

2014-10-21  Richard Biener  <rguenther@suse.de>

	* tree-ssa-phiopt.c (value_replacement): Properly verify we
	are the non-singleton PHI.

Index: gcc/tree-ssa-phiopt.c
===================================================================
--- gcc/tree-ssa-phiopt.c	(revision 216396)
+++ gcc/tree-ssa-phiopt.c	(working copy)
@@ -814,7 +814,7 @@ value_replacement (basic_block cond_bb,
 	 for the edges e0 and e1 then we can remove the middle basic block. */
       if (emtpy_or_with_defined_p
 	  && single_non_singleton_phi_for_edges (phi_nodes (gimple_bb (phi)),
-							    e0, e1))
+						 e0, e1) == phi)
 	{
           replace_phi_edge_with_variable (cond_bb, e1, phi, arg);
 	  /* Note that we optimized this PHI.  */


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