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  <rguent...@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.  */

Reply via email to