]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Ensure PHI equivalencies do not dominate the argument edge.
authorAndrew MacLeod <amacleod@redhat.com>
Wed, 12 Apr 2023 17:10:55 +0000 (13:10 -0400)
committerAndrew MacLeod <amacleod@redhat.com>
Thu, 13 Apr 2023 18:12:04 +0000 (14:12 -0400)
When we create an equivalency between a PHI definition and an argument,
ensure the definition does not dominate the incoming argument edge.

PR tree-optimization/108139
PR tree-optimization/109462
* gimple-range-cache.cc (ranger_cache::fill_block_cache): Remove
equivalency check for PHI nodes.
* gimple-range-fold.cc (fold_using_range::range_of_phi): Ensure def
does not dominate single-arg equivalency edges.

gcc/gimple-range-cache.cc
gcc/gimple-range-fold.cc

index 3b52f1e734ccb587f96a655f94a354ee384eedd1..2314478d55849d7ae973a4bc65e26edfe565ac28 100644 (file)
@@ -1220,7 +1220,7 @@ ranger_cache::fill_block_cache (tree name, basic_block bb, basic_block def_bb)
       // See if any equivalences can refine it.
       // PR 109462, like 108139 below, a one way equivalence introduced
       // by a PHI node can also be through the definition side.  Disallow it.
-      if (m_oracle && !is_a<gphi *> (SSA_NAME_DEF_STMT (name)))
+      if (m_oracle)
        {
          tree equiv_name;
          relation_kind rel;
@@ -1237,13 +1237,6 @@ ranger_cache::fill_block_cache (tree name, basic_block bb, basic_block def_bb)
              if (!m_gori.has_edge_range_p (equiv_name))
                continue;
 
-             // PR 108139. It is hazardous to assume an equivalence with
-             // a PHI is the same value.  The PHI may be an equivalence
-             // via UNDEFINED arguments which is really a one way equivalence.
-             // PHIDEF == name, but name may not be == PHIDEF.
-             if (is_a<gphi *> (SSA_NAME_DEF_STMT (equiv_name)))
-               continue;
-
              // Check if the equiv definition dominates this block
              if (equiv_bb == bb ||
                  (equiv_bb && !dominated_by_p (CDI_DOMINATORS, bb, equiv_bb)))
index e81f6b3699e85f3185c2f66a435c88f9a9a120b9..429734f954a7588917426120190ca1b5b7009a79 100644 (file)
@@ -795,9 +795,28 @@ fold_using_range::range_of_phi (vrange &r, gphi *phi, fur_source &src)
     // If the PHI boils down to a single effective argument, look at it.
     if (single_arg)
       {
-       // Symbolic arguments are equivalences.
+       // Symbolic arguments can be equivalences.
        if (gimple_range_ssa_p (single_arg))
-         src.register_relation (phi, VREL_EQ, phi_def, single_arg);
+         {
+           // Only allow the equivalence if the PHI definition does not
+           // dominate any incoming edge for SINGLE_ARG.
+           // See PR 108139 and 109462.
+           basic_block bb = gimple_bb (phi);
+           if (!dom_info_available_p (CDI_DOMINATORS))
+             single_arg = NULL;
+           else
+             for (x = 0; x < gimple_phi_num_args (phi); x++)
+               if (gimple_phi_arg_def (phi, x) == single_arg
+                   && dominated_by_p (CDI_DOMINATORS,
+                                       gimple_phi_arg_edge (phi, x)->src,
+                                       bb))
+                 {
+                   single_arg = NULL;
+                   break;
+                 }
+           if (single_arg)
+             src.register_relation (phi, VREL_EQ, phi_def, single_arg);
+         }
        else if (src.get_operand (arg_range, single_arg)
                 && arg_range.singleton_p ())
          {