diff options
author | Aldy Hernandez <aldyh@redhat.com> | 2021-11-13 12:37:25 +0100 |
---|---|---|
committer | Aldy Hernandez <aldyh@redhat.com> | 2021-11-13 14:41:47 +0100 |
commit | b7a23949b0dcc4205fcc2be6b84b91441faa384d (patch) | |
tree | af283f4673b4ba1548de8fad4e79f5875e1743f4 /gcc/gimple-range-path.cc | |
parent | 380fc3b69f6e7006d72ca270f909468426de3ab7 (diff) | |
download | gcc-b7a23949b0dcc4205fcc2be6b84b91441faa384d.zip gcc-b7a23949b0dcc4205fcc2be6b84b91441faa384d.tar.gz gcc-b7a23949b0dcc4205fcc2be6b84b91441faa384d.tar.bz2 |
path solver: Compute all PHI ranges simultaneously.
PHIs must be resolved simulatenously, otherwise we may not pick up the
ranges incoming to the block.
For example. If we put p3_7 in the cache before all PHIs have been
computed, we will pick up the wrong p3_7 value for p2_17:
# p3_7 = PHI <1(2), 0(5)>
# p2_17 = PHI <1(2), p3_7(5)>
This patch delays updating the cache until all PHIs have been
analyzed.
gcc/ChangeLog:
PR tree-optimization/103222
* gimple-range-path.cc (path_range_query::compute_ranges_in_phis):
New.
(path_range_query::compute_ranges_in_block): Call
compute_ranges_in_phis.
* gimple-range-path.h (path_range_query::compute_ranges_in_phis):
New.
gcc/testsuite/ChangeLog:
* gcc.dg/pr103222.c: New test.
Diffstat (limited to 'gcc/gimple-range-path.cc')
-rw-r--r-- | gcc/gimple-range-path.cc | 42 |
1 files changed, 33 insertions, 9 deletions
diff --git a/gcc/gimple-range-path.cc b/gcc/gimple-range-path.cc index 32b2cb5..9957ac9 100644 --- a/gcc/gimple-range-path.cc +++ b/gcc/gimple-range-path.cc @@ -343,6 +343,38 @@ path_range_query::range_defined_in_block (irange &r, tree name, basic_block bb) return true; } +// Compute ranges defined in the PHIs in this block. + +void +path_range_query::compute_ranges_in_phis (basic_block bb) +{ + int_range_max r; + gphi_iterator iter; + + // PHIs must be resolved simultaneously on entry to the block + // because any dependencies must be satistifed with values on entry. + // Thus, we calculate all PHIs first, and then update the cache at + // the end. + + m_tmp_phi_cache.clear (); + for (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)) + m_tmp_phi_cache.set_global_range (name, r); + } + for (iter = gsi_start_phis (bb); !gsi_end_p (iter); gsi_next (&iter)) + { + gphi *phi = iter.phi (); + tree name = gimple_phi_result (phi); + + if (m_tmp_phi_cache.get_global_range (r, name)) + set_cache (r, name); + } +} + // Compute ranges defined in the current block, or exported to the // next block. @@ -369,15 +401,7 @@ path_range_query::compute_ranges_in_block (basic_block bb) } // 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); - } + compute_ranges_in_phis (bb); // ...and then the rest of the imports. EXECUTE_IF_SET_IN_BITMAP (m_imports, 0, i, bi) { |