The code was passing factor == 0 to vect_get_loop_len which always
returns an unmodified length, even if the number of scalar elements
doesn't agree.  It also failed to insert the eventually generated
code.

Testing in the CI.

Richard.

        PR tree-optimization/117594
        * tree-vect-loop.cc (vectorizable_live_operation_1): Pass
        factor == 1 to vect_get_loop_len, insert generated stmts.

        * gcc.dg/vect/pr117594.c: New testcase.
---
 gcc/testsuite/gcc.dg/vect/pr117594.c | 20 ++++++++++++++++++++
 gcc/tree-vect-loop.cc                |  3 ++-
 2 files changed, 22 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/vect/pr117594.c

diff --git a/gcc/testsuite/gcc.dg/vect/pr117594.c 
b/gcc/testsuite/gcc.dg/vect/pr117594.c
new file mode 100644
index 00000000000..ab213908bbc
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr117594.c
@@ -0,0 +1,20 @@
+/* { dg-require-effective-target int32plus } */
+
+#include "tree-vect.h"
+
+unsigned a;
+short b, d, e;
+int main()
+{
+  check_vect ();
+  short h = d;
+  short *z = &h;
+  for (_Bool i = 0; i < 1; i = 1)
+    for (unsigned j = 0; j < (z[i] ?: 10); j += 3)
+      {
+       a -= 9;
+       b -= ~e;
+      }
+  if (a != 4294967260)
+    __builtin_abort ();
+}
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index 18c4fa1d000..ce728143469 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -11221,7 +11221,8 @@ vectorizable_live_operation_1 (loop_vec_info loop_vinfo,
       gimple_stmt_iterator gsi = gsi_last (tem);
       tree len = vect_get_loop_len (loop_vinfo, &gsi,
                                    &LOOP_VINFO_LENS (loop_vinfo),
-                                   1, vectype, 0, 0);
+                                   1, vectype, 0, 1);
+      gimple_seq_add_seq (&stmts, tem);
 
       /* BIAS - 1.  */
       signed char biasval = LOOP_VINFO_PARTIAL_LOAD_STORE_BIAS (loop_vinfo);
-- 
2.43.0

Reply via email to