aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-vect-loop-manip.cc
diff options
context:
space:
mode:
authorLewis Hyatt <lhyatt@gmail.com>2024-12-06 19:01:27 -0500
committerLewis Hyatt <lhyatt@gcc.gnu.org>2024-12-06 19:01:28 -0500
commit568b3b30218715ff0b2b8f6404fc8bce819d6153 (patch)
tree49f5c2f0c5c33286c18a5c694f996c70185aea12 /gcc/tree-vect-loop-manip.cc
parentc7fd6c4369ef1a009b40c1787ea9d2dad2cf449f (diff)
downloadgcc-568b3b30218715ff0b2b8f6404fc8bce819d6153.zip
gcc-568b3b30218715ff0b2b8f6404fc8bce819d6153.tar.gz
gcc-568b3b30218715ff0b2b8f6404fc8bce819d6153.tar.bz2
middle-end: Handle resized PHI nodes in loop_version()
While testing upcoming support for 64-bit location_t, I came across some test failures on sparc (32-bit) that trigger when location_t is changed to be 64-bit. The reason is that several call sites that make use of loop_version() for performing loop optimizations assume that a gphi* obtained prior to calling loop_version() will remain valid afterwards, but this is not the case for a PHI that needs to be resized. It doesn't happen usually, because PHI nodes usually have room for at least 4 arguments and this is usually more than are needed, but this is not guaranteed. Fix the affected callers by avoiding the assumption that a PHI node pointer remains valid. For most cases, this is done by remembering instead the gphi->result pointer, which contains a pointer back to the PHI node that is kept up to date when the PHI is moved to a new address. gcc/ChangeLog: * tree-parloops.cc (struct reduction_info): Store the result of the reduction PHI rather than the PHI itself. (reduction_info::reduc_phi): New member function. (reduction_hasher::equal): Adapt to the change in struct reduction_info. (reduction_phi): Likewise. (initialize_reductions): Likewise. (create_call_for_reduction_1): Likewise. (transform_to_exit_first_loop_alt): Likewise. (transform_to_exit_first_loop): Likewise. (build_new_reduction): Likewise. (set_reduc_phi_uids): Likewise. (try_create_reduction_list): Likewise. * tree-ssa-loop-split.cc (split_loop): Remember the PHI result variable so that the PHI can be found in case it is resized and move to a new address. * tree-vect-loop-manip.cc (vect_loop_versioning): After calling loop_version(), fix up stored PHI pointers in case they have changed. * tree-vectorizer.cc (vec_info::resync_stmt_addr): New function. * tree-vectorizer.h (vec_info::resync_stmt_addr): Declare.
Diffstat (limited to 'gcc/tree-vect-loop-manip.cc')
-rw-r--r--gcc/tree-vect-loop-manip.cc8
1 files changed, 8 insertions, 0 deletions
diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc
index 54b2954..4f3abb9 100644
--- a/gcc/tree-vect-loop-manip.cc
+++ b/gcc/tree-vect-loop-manip.cc
@@ -4190,6 +4190,14 @@ vect_loop_versioning (loop_vec_info loop_vinfo,
prob * prob2, (prob * prob2).invert (),
prob * prob2, (prob * prob2).invert (),
true);
+
+ /* If the PHI nodes in the loop header were reallocated, we need to fix up
+ our internally stashed copies of those. */
+ if (loop_to_version == loop)
+ for (auto gsi = gsi_start_phis (loop->header);
+ !gsi_end_p (gsi); gsi_next (&gsi))
+ loop_vinfo->resync_stmt_addr (gsi.phi ());
+
/* We will later insert second conditional so overall outcome of
both is prob * prob2. */
edge true_e, false_e;