]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/121059 - fixup loop mask query
authorRichard Biener <rguenther@suse.de>
Mon, 14 Jul 2025 12:09:28 +0000 (14:09 +0200)
committerRichard Biener <rguenther@suse.de>
Fri, 31 Oct 2025 13:56:31 +0000 (14:56 +0100)
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.sandiford@arm.com>
(cherry picked from commit 234f122a9be5cc2a30d2a9e94c2fc9cde1d5a64d)

gcc/testsuite/gcc.dg/vect/pr121059.c [new file with mode: 0644]
gcc/tree-vect-stmts.cc

diff --git a/gcc/testsuite/gcc.dg/vect/pr121059.c b/gcc/testsuite/gcc.dg/vect/pr121059.c
new file mode 100644 (file)
index 0000000..2bbfcea
--- /dev/null
@@ -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;
+}
index 52face23c10c0ba1713371cb6cc8206d2f38177b..16fb8faf1d1b55c33d4cdbaa82669f6ac602e57e 100644 (file)
@@ -6170,7 +6170,8 @@ vectorizable_operation (vec_info *vinfo,
   poly_uint64 nunits_in;
   poly_uint64 nunits_out;
   tree vectype_out;
-  int ncopies, vec_num;
+  unsigned int ncopies;
+  unsigned vec_num;
   int i;
   vec<tree> vec_oprnds0 = vNULL;
   vec<tree> vec_oprnds1 = vNULL;
@@ -6626,8 +6627,8 @@ vectorizable_operation (vec_info *vinfo,
              && code == BIT_AND_EXPR
              && VECTOR_BOOLEAN_TYPE_P (vectype))
            {
-             if (loop_vinfo->scalar_cond_masked_set.contains ({ op0,
-                                                                ncopies}))
+             if (loop_vinfo->scalar_cond_masked_set.contains
+                                                  ({ op0, vec_num * ncopies}))
                {
                  mask = vect_get_loop_mask (gsi, masks, vec_num * ncopies,
                                             vectype, i);
@@ -6636,8 +6637,8 @@ vectorizable_operation (vec_info *vinfo,
                                           vop0, gsi);
                }
 
-             if (loop_vinfo->scalar_cond_masked_set.contains ({ op1,
-                                                                ncopies }))
+             if (loop_vinfo->scalar_cond_masked_set.contains
+                                                 ({ op1, vec_num * ncopies }))
                {
                  mask = vect_get_loop_mask (gsi, masks, vec_num * ncopies,
                                             vectype, i);