https://gcc.gnu.org/g:71be87055548cf942c7bc56d10ffd479db8569e4

commit r16-2259-g71be87055548cf942c7bc56d10ffd479db8569e4
Author: Richard Biener <rguent...@suse.de>
Date:   Mon Jul 14 14:09:28 2025 +0200

    tree-optimization/121059 - fixup loop mask query
    
    When we opportunistically mask an operand of a AND with an already
    available loop mask we need to query that set with the correct number
    of masks we expect.
    
            PR tree-optimization/121059
            * tree-vect-stmts.cc (vectorizable_operation): Query
            scalar_cond_masked_set with the correct number of masks.
    
            * gcc.dg/vect/pr121059.c: New testcase.
    
    Co-Authored-By: Richard Sandiford  <richard.sandif...@arm.com>

Diff:
---
 gcc/testsuite/gcc.dg/vect/pr121059.c | 24 ++++++++++++++++++++++++
 gcc/tree-vect-stmts.cc               |  7 +++----
 2 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/vect/pr121059.c 
b/gcc/testsuite/gcc.dg/vect/pr121059.c
new file mode 100644
index 000000000000..2bbfcead86da
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr121059.c
@@ -0,0 +1,24 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-O3 --param vect-partial-vector-usage=1" } */
+/* { dg-additional-options "-march=x86-64-v4" { target avx512f } } */
+
+typedef struct {
+  long left, right, top, bottom;
+} MngBox;
+typedef struct {
+  MngBox object_clip[6];
+  char exists[256], frozen[];
+} MngReadInfo;
+MngReadInfo mng_info;
+
+long ReadMNGImage_i;
+
+void ReadMNGImage(int ReadMNGImage_i)
+{
+  for (; ReadMNGImage_i < 256; ReadMNGImage_i++)
+    if (mng_info.exists[ReadMNGImage_i] && mng_info.frozen[ReadMNGImage_i])
+      mng_info.object_clip[ReadMNGImage_i].left =
+          mng_info.object_clip[ReadMNGImage_i].right =
+              mng_info.object_clip[ReadMNGImage_i].top =
+                  mng_info.object_clip[ReadMNGImage_i].bottom = 0;
+}
diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index 4aa69da2218b..e2dcfaa7a1fc 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -6705,7 +6705,6 @@ vectorizable_operation (vec_info *vinfo,
   poly_uint64 nunits_in;
   poly_uint64 nunits_out;
   tree vectype_out;
-  int vec_num;
   int i;
   vec<tree> vec_oprnds0 = vNULL;
   vec<tree> vec_oprnds1 = vNULL;
@@ -6877,7 +6876,7 @@ vectorizable_operation (vec_info *vinfo,
 
   /* Multiple types in SLP are handled by creating the appropriate number of
      vectorized stmts for each SLP node.  */
-  vec_num = SLP_TREE_NUMBER_OF_VEC_STMTS (slp_node);
+  auto vec_num = SLP_TREE_NUMBER_OF_VEC_STMTS (slp_node);
 
   /* Reject attempts to combine mask types with nonmask types, e.g. if
      we have an AND between a (nonmask) boolean loaded from memory and
@@ -7229,7 +7228,7 @@ vectorizable_operation (vec_info *vinfo,
              && code == BIT_AND_EXPR
              && VECTOR_BOOLEAN_TYPE_P (vectype))
            {
-             if (loop_vinfo->scalar_cond_masked_set.contains ({ op0, 1 }))
+             if (loop_vinfo->scalar_cond_masked_set.contains ({ op0, vec_num 
}))
                {
                  mask = vect_get_loop_mask (loop_vinfo, gsi, masks,
                                             vec_num, vectype, i);
@@ -7238,7 +7237,7 @@ vectorizable_operation (vec_info *vinfo,
                                           vop0, gsi);
                }
 
-             if (loop_vinfo->scalar_cond_masked_set.contains ({ op1, 1 }))
+             if (loop_vinfo->scalar_cond_masked_set.contains ({ op1, vec_num 
}))
                {
                  mask = vect_get_loop_mask (loop_vinfo, gsi, masks,
                                             vec_num, vectype, i);

Reply via email to