]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/114485 - neg induction with partial vectors
authorRichard Biener <rguenther@suse.de>
Thu, 4 Apr 2024 08:00:51 +0000 (10:00 +0200)
committerRichard Biener <rguenther@suse.de>
Fri, 3 May 2024 12:46:14 +0000 (14:46 +0200)
We can't use vect_update_ivs_after_vectorizer for partial vectors,
the following fixes vect_can_peel_nonlinear_iv_p accordingly.

PR tree-optimization/114485
* tree-vect-loop-manip.cc (vect_can_peel_nonlinear_iv_p):
vect_step_op_neg isn't OK for partial vectors but only
for unknown niter.

* gcc.dg/vect/pr114485.c: New testcase.

(cherry picked from commit 85621f98d245004a6c9787dde21e0acc17ab2c50)

gcc/testsuite/gcc.dg/vect/pr114485.c [new file with mode: 0644]
gcc/tree-vect-loop-manip.cc

diff --git a/gcc/testsuite/gcc.dg/vect/pr114485.c b/gcc/testsuite/gcc.dg/vect/pr114485.c
new file mode 100644 (file)
index 0000000..6536806
--- /dev/null
@@ -0,0 +1,18 @@
+#include "tree-vect.h"
+
+int b, c = 8, d;
+int e[23];
+int main()
+{
+  check_vect ();
+
+  int *h = e;
+  for (int i = 1; i < b + 21; i += 2)
+    {
+      c *= -1;
+      d = h[i] ? i : 0;
+    }
+  if (c != 8)
+    abort ();
+  return 0;
+}
index 767b19b15a1d3e8bd0c7d0084f20704829849361..9049a4b01e47aa8136d39dc5060f1ddafbca2250 100644 (file)
@@ -1401,17 +1401,20 @@ vect_can_peel_nonlinear_iv_p (loop_vec_info loop_vinfo,
      For shift, when shift mount >= precision, there would be UD.
      For mult, don't known how to generate
      init_expr * pow (step, niters) for variable niters.
-     For neg, it should be ok, since niters of vectorized main loop
-     will always be multiple of 2.  */
-  if ((!LOOP_VINFO_NITERS_KNOWN_P (loop_vinfo)
-       || !LOOP_VINFO_VECT_FACTOR (loop_vinfo).is_constant ())
-      && induction_type != vect_step_op_neg)
+     For neg unknown niters are ok, since niters of vectorized main loop
+     will always be multiple of 2.
+     See also PR113163,  PR114196 and PR114485.  */
+  if (!LOOP_VINFO_VECT_FACTOR (loop_vinfo).is_constant ()
+      || LOOP_VINFO_USING_PARTIAL_VECTORS_P (loop_vinfo)
+      || (!LOOP_VINFO_NITERS_KNOWN_P (loop_vinfo)
+         && induction_type != vect_step_op_neg))
     {
       if (dump_enabled_p ())
        dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
                         "Peeling for epilogue is not supported"
-                        " for nonlinear induction except neg"
-                        " when iteration count is unknown.\n");
+                        " for this nonlinear induction"
+                        " when iteration count is unknown or"
+                        " when using partial vectorization.\n");
       return false;
     }