https://gcc.gnu.org/g:b1e14fc244c6b4543eb0ec1857afcf125cfbd917

commit r14-11005-gb1e14fc244c6b4543eb0ec1857afcf125cfbd917
Author: Richard Biener <rguent...@suse.de>
Date:   Mon Nov 18 13:46:52 2024 +0100

    tree-optimization/117594 - fix live op vectorization for length masked case
    
    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.
    
            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.
    
    (cherry picked from commit c108785c425b2042f63fa975c58c274d19a8d160)

Diff:
---
 gcc/testsuite/gcc.dg/vect/pr117594.c | 20 ++++++++++++++++++++
 gcc/tree-vect-loop.cc                |  3 ++-
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/vect/pr117594.c 
b/gcc/testsuite/gcc.dg/vect/pr117594.c
new file mode 100644
index 000000000000..ab213908bbc9
--- /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 dfb9d1be6670..2db483c245e8 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -10672,7 +10672,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);

Reply via email to