]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/121592 - failed reduction SLP discovery
authorRichard Biener <rguenther@suse.de>
Tue, 19 Aug 2025 10:31:53 +0000 (12:31 +0200)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 19 Aug 2025 11:45:58 +0000 (13:45 +0200)
The testcase in the PR shows that when we have a reduction chain
with a wrapped conversion we fail to properly fall back to a
regular reduction, resulting in wrong-code.  The following fixes
this by failing discovery.  The testcase has other issues, so
I'm not including it here.

PR tree-optimization/121592
* tree-vect-slp.cc (vect_analyze_slp): When SLP reduction chain
discovery fails, fail overall when the tail of the chain
isn't also the entry for the non-SLP reduction.

gcc/tree-vect-slp.cc

index 05363f89cf46ac9a4175ae492ed455e3a52632c0..d5adb8baf8766c4df42731de00a545ae204a5068 100644 (file)
@@ -5005,6 +5005,11 @@ vect_analyze_slp (vec_info *vinfo, unsigned max_tree_size,
                vinfo = next;
              }
            STMT_VINFO_DEF_TYPE (first_element) = vect_internal_def;
+           /* ???  When there's a conversion around the reduction
+              chain 'last' isn't the entry of the reduction.  */
+           if (STMT_VINFO_DEF_TYPE (last) != vect_reduction_def)
+             return opt_result::failure_at (vect_location,
+                                            "SLP build failed.\n");
            /* It can be still vectorized as part of an SLP reduction.  */
            loop_vinfo->reductions.safe_push (last);
          }