public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-4850] tree-optimization/103029 - ensure vect loop versioning constraint on PHIs
@ 2021-11-02 17:49 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2021-11-02 17:49 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:164bbf701ff10ff44e272525e8f462ed3ff1cf43

commit r12-4850-g164bbf701ff10ff44e272525e8f462ed3ff1cf43
Author: Richard Biener <rguenther@suse.de>
Date:   Tue Nov 2 18:47:14 2021 +0100

    tree-optimization/103029 - ensure vect loop versioning constraint on PHIs
    
    PHI nodes in vectorizer loop versioning need to maintain the same
    order of PHI arguments to not disturb SLP discovery.  The following
    adds an assertion and mitigation in case loop versioning breaks this
    which happens more often after the recent reorg.
    
    2021-11-02  Richard Biener  <rguenther@suse.de>
    
            PR tree-optimization/103029
            * tree-vect-loop-manip.c (vect_loop_versioning): Ensure
            the PHI nodes in the loop maintain their original operand
            order.

Diff:
---
 gcc/tree-vect-loop-manip.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/gcc/tree-vect-loop-manip.c b/gcc/tree-vect-loop-manip.c
index 72d583189c4..f788deb3d72 100644
--- a/gcc/tree-vect-loop-manip.c
+++ b/gcc/tree-vect-loop-manip.c
@@ -3562,12 +3562,29 @@ vect_loop_versioning (loop_vec_info loop_vinfo,
 			 "applying loop versioning to outer loop %d\n",
 			 loop_to_version->num);
 
+      unsigned orig_pe_idx = loop_preheader_edge (loop)->dest_idx;
+
       initialize_original_copy_tables ();
       nloop = loop_version (loop_to_version, cond_expr, &condition_bb,
 			    prob, prob.invert (), prob, prob.invert (), true);
       gcc_assert (nloop);
       nloop = get_loop_copy (loop);
 
+      /* For cycle vectorization with SLP we rely on the PHI arguments
+	 appearing in the same order as the SLP node operands which for the
+	 loop PHI nodes means the preheader edge dest index needs to remain
+	 the same for the analyzed loop which also becomes the vectorized one.
+	 Make it so in case the state after versioning differs by redirecting
+	 the first edge into the header to the same destination which moves
+	 it last.  */
+      if (loop_preheader_edge (loop)->dest_idx != orig_pe_idx)
+	{
+	  edge e = EDGE_PRED (loop->header, 0);
+	  ssa_redirect_edge (e, e->dest);
+	  flush_pending_stmts (e);
+	}
+      gcc_assert (loop_preheader_edge (loop)->dest_idx == orig_pe_idx);
+
       /* Kill off IFN_LOOP_VECTORIZED_CALL in the copy, nobody will
          reap those otherwise;  they also refer to the original
 	 loops.  */


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-11-02 17:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-02 17:49 [gcc r12-4850] tree-optimization/103029 - ensure vect loop versioning constraint on PHIs Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).