]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fixup store bool pattern
authorRichard Biener <rguenther@suse.de>
Tue, 7 Oct 2025 13:32:45 +0000 (15:32 +0200)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 8 Oct 2025 07:03:05 +0000 (09:03 +0200)
I think the bool pattern recognition for a store from a bool we
decided to represent with a mask type is a bit confused.  The
following streamlines it by using the mask to create a data 0/1
and first possibly converting the mask according to the vector
data type we produce (that was missing and is noticable in PR110223).

This alone doesn't fix the 2nd testcase from the PR, but is required.

PR tree-optimization/110223
* tree-vect-patterns.cc (vect_recog_bool_pattern): Fix
mistakes in the store-from-mask bool pattern.  Add
required mask conversions.

gcc/tree-vect-patterns.cc

index dccd3c9806e6b9d2f765ddde1411aa4b5bede83e..55c50420e32af772fe61b8615582fed2a80330cd 100644 (file)
@@ -5763,30 +5763,18 @@ vect_recog_bool_pattern (vec_info *vinfo,
        return NULL;
 
       tree type = integer_type_for_mask (var, vinfo);
-      tree cst0, cst1, new_vectype;
-
       if (!type)
        return NULL;
 
-      if (TYPE_MODE (type) == TYPE_MODE (TREE_TYPE (vectype)))
-       type = TREE_TYPE (vectype);
-
-      cst0 = build_int_cst (type, 0);
-      cst1 = build_int_cst (type, 1);
-      new_vectype = get_vectype_for_scalar_type (vinfo, type);
+      var = vect_convert_mask_for_vectype (var, vectype, stmt_vinfo, vinfo);
 
-      rhs = vect_recog_temp_ssa_var (type, NULL);
+      tree cst0 = build_int_cst (TREE_TYPE (vectype), 0);
+      tree cst1 = build_int_cst (TREE_TYPE (vectype), 1);
+      rhs = vect_recog_temp_ssa_var (TREE_TYPE (vectype), NULL);
       pattern_stmt = gimple_build_assign (rhs, COND_EXPR, var, cst1, cst0);
-      append_pattern_def_seq (vinfo, stmt_vinfo, pattern_stmt, new_vectype);
+      append_pattern_def_seq (vinfo, stmt_vinfo, pattern_stmt, vectype);
 
       lhs = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (vectype), lhs);
-      if (!useless_type_conversion_p (TREE_TYPE (lhs), TREE_TYPE (rhs)))
-       {
-         tree rhs2 = vect_recog_temp_ssa_var (TREE_TYPE (lhs), NULL);
-         gimple *cast_stmt = gimple_build_assign (rhs2, NOP_EXPR, rhs);
-         append_pattern_def_seq (vinfo, stmt_vinfo, cast_stmt);
-         rhs = rhs2;
-       }
       pattern_stmt = gimple_build_assign (lhs, SSA_NAME, rhs);
       pattern_stmt_info = vinfo->add_stmt (pattern_stmt);
       vinfo->move_dr (pattern_stmt_info, stmt_vinfo);