On 11/12/21 14:50, Richard Biener via Gcc-patches wrote:
On November 12, 2021 8:46:25 PM GMT+01:00, Aldy Hernandez via Gcc-patches 
<gcc-patches@gcc.gnu.org> wrote:
PHIs must be resolved first while solving ranges in a block,
regardless of where they appear in the import bitmap.  We went through
a similar exercise for the relational code, but missed these.
Must not all stmts be resolved in program order (for optimality at least)?

Generally,Imports are live on entry values to a block, so their order is not particularly important.. they are all simultaneous. PHIs are also considered imports for data flow purposes, but they happen before the first stmt, all simultaneously... they need to be distinguished because phi arguments can refer to other phi defs which may be in this block live around a back edge, and we need to be sure we get the right version.

we should look closer to be sure this isn't an accidental fix that leaves the root problem .   we need to be sure *all* the PHI arguments are resolved from outside this block. whats the testcase?


Tested on x86-64 & ppc64le Linux.

gcc/ChangeLog:

        PR tree-optimization/103202
        * gimple-range-path.cc
        (path_range_query::compute_ranges_in_block): Solve PHI imports first.
---
gcc/gimple-range-path.cc | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/gcc/gimple-range-path.cc b/gcc/gimple-range-path.cc
index b9aceaf2565..71b290434cb 100644
--- a/gcc/gimple-range-path.cc
+++ b/gcc/gimple-range-path.cc
@@ -365,12 +365,23 @@ path_range_query::compute_ranges_in_block (basic_block bb)
        clear_cache (name);
     }

-  // Solve imports defined in this block.
+  // Solve imports defined in this block, starting with the PHIs...
+  for (gphi_iterator iter = gsi_start_phis (bb); !gsi_end_p (iter);
+       gsi_next (&iter))
+    {
+      gphi *phi = iter.phi ();
+      tree name = gimple_phi_result (phi);
+
+      if (import_p (name) && range_defined_in_block (r, name, bb))
+       set_cache (r, name);
+    }
+  // ...and then the rest of the imports.
   EXECUTE_IF_SET_IN_BITMAP (m_imports, 0, i, bi)
     {
       tree name = ssa_name (i);

-      if (range_defined_in_block (r, name, bb))
+      if (gimple_code (SSA_NAME_DEF_STMT (name)) != GIMPLE_PHI
+         && range_defined_in_block (r, name, bb))
        set_cache (r, name);
     }


Reply via email to