]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/119757 - reject mixed mask/non-mask ldst SLP
authorRichard Biener <rguenther@suse.de>
Mon, 14 Apr 2025 10:44:02 +0000 (12:44 +0200)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 14 Apr 2025 11:53:17 +0000 (13:53 +0200)
The following makes sure to not mix masked/non-masked stmts when
forming a SLP node.

PR tree-optimization/119757
* tree-vect-slp.cc (vect_build_slp_tree_1): Record and compare
whether a stmt uses a maks.

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

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

diff --git a/gcc/testsuite/gcc.dg/vect/pr119757.c b/gcc/testsuite/gcc.dg/vect/pr119757.c
new file mode 100644 (file)
index 0000000..8644299
--- /dev/null
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+
+void base64_encode(const char *table64,
+                   const char *inputbuff, int insize,
+                   char * __restrict output)
+{
+  const unsigned char *in = (const unsigned char *)inputbuff;
+
+  while(insize >= 3) {
+    *output++ = table64[ in[0] >> 2 ];
+    *output++ = table64[ ((in[0] & 0x03) << 4) | (in[1] >> 4) ];
+    *output++ = table64[ ((in[1] & 0x0F) << 2) | ((in[2] & 0xC0) >> 6) ];
+    *output++ = table64[ in[2] & 0x3F ];
+    insize -= 3;
+    in += 3;
+  }
+}
index ecb4a6521dec6742896f8b94a2d5760f0d727567..19beeed8a3a980e226a115afdd61b755dc6b4015 100644 (file)
@@ -1099,7 +1099,7 @@ vect_build_slp_tree_1 (vec_info *vinfo, unsigned char *swap,
   tree first_lhs = NULL_TREE;
   tree first_op1 = NULL_TREE;
   stmt_vec_info first_load = NULL, prev_first_load = NULL;
-  bool first_stmt_ldst_p = false;
+  bool first_stmt_ldst_p = false, first_stmt_ldst_masklen_p = false;
   bool first_stmt_phi_p = false;
   int first_reduc_idx = -1;
   bool maybe_soft_fail = false;
@@ -1133,6 +1133,7 @@ vect_build_slp_tree_1 (vec_info *vinfo, unsigned char *swap,
   FOR_EACH_VEC_ELT (stmts, i, stmt_info)
     {
       bool ldst_p = false;
+      bool ldst_masklen_p = false;
       bool phi_p = false;
       code_helper rhs_code = ERROR_MARK;
 
@@ -1195,17 +1196,22 @@ vect_build_slp_tree_1 (vec_info *vinfo, unsigned char *swap,
          else
            rhs_code = CALL_EXPR;
 
-         if (cfn == CFN_MASK_LOAD
-             || cfn == CFN_GATHER_LOAD
-             || cfn == CFN_MASK_GATHER_LOAD
-             || cfn == CFN_MASK_LEN_GATHER_LOAD
-             || cfn == CFN_SCATTER_STORE
-             || cfn == CFN_MASK_SCATTER_STORE
-             || cfn == CFN_MASK_LEN_SCATTER_STORE)
+         if (cfn == CFN_GATHER_LOAD
+             || cfn == CFN_SCATTER_STORE)
            ldst_p = true;
+         else if (cfn == CFN_MASK_LOAD
+                  || cfn == CFN_MASK_GATHER_LOAD
+                  || cfn == CFN_MASK_LEN_GATHER_LOAD
+                  || cfn == CFN_MASK_SCATTER_STORE
+                  || cfn == CFN_MASK_LEN_SCATTER_STORE)
+           {
+             ldst_p = true;
+             ldst_masklen_p = true;
+           }
          else if (cfn == CFN_MASK_STORE)
            {
              ldst_p = true;
+             ldst_masklen_p = true;
              rhs_code = CFN_MASK_STORE;
            }
          else if (cfn == CFN_GOMP_SIMD_LANE)
@@ -1246,6 +1252,7 @@ vect_build_slp_tree_1 (vec_info *vinfo, unsigned char *swap,
          first_lhs = lhs;
          first_stmt_code = rhs_code;
          first_stmt_ldst_p = ldst_p;
+         first_stmt_ldst_masklen_p = ldst_masklen_p;
          first_stmt_phi_p = phi_p;
          first_reduc_idx = STMT_VINFO_REDUC_IDX (stmt_info);
 
@@ -1364,6 +1371,7 @@ vect_build_slp_tree_1 (vec_info *vinfo, unsigned char *swap,
                  && (STMT_VINFO_GATHER_SCATTER_P (stmt_info)
                      != STMT_VINFO_GATHER_SCATTER_P (first_stmt_info)))
              || first_stmt_ldst_p != ldst_p
+             || (ldst_p && first_stmt_ldst_masklen_p != ldst_masklen_p)
              || first_stmt_phi_p != phi_p)
            {
              if (dump_enabled_p ())