Fix latch PHI arg lookup in vectorizable_reduction for double-reduction
authorRichard Biener <rguenther@suse.de>
Tue, 20 Oct 2020 11:15:45 +0000 (13:15 +0200)
committerRichard Biener <rguenther@suse.de>
Tue, 20 Oct 2020 12:21:01 +0000 (14:21 +0200)
We were using the wrong loop to figure the latch arg of a
double-reduction PHI.  Which isn't a problem in case ->dest_idx
match up with the outer loop edges - but that's of course not guaranteed.

2020-10-20  Richard Biener  <rguenther@suse.de>

* tree-vect-loop.c (vectorizable_reduction): Use the correct
loops latch edge for the PHI arg lookup.

gcc/tree-vect-loop.c

index 991fd45..6c29e00 100644 (file)
@@ -6359,8 +6359,10 @@ vectorizable_reduction (loop_vec_info loop_vinfo,
   /* Verify following REDUC_IDX from the latch def leads us back to the PHI
      and compute the reduction chain length.  Discover the real
      reduction operation stmt on the way (stmt_info and slp_for_stmt_info).  */
-  tree reduc_def = PHI_ARG_DEF_FROM_EDGE (reduc_def_phi,
-                                         loop_latch_edge (loop));
+  tree reduc_def
+    = PHI_ARG_DEF_FROM_EDGE (reduc_def_phi,
+                            loop_latch_edge
+                              (gimple_bb (reduc_def_phi)->loop_father));
   unsigned reduc_chain_length = 0;
   bool only_slp_reduc_chain = true;
   stmt_info = NULL;