[gcc r15-1187] vect: Merge loop mask and cond_op mask in fold-left reduction [PR115382].
Robin Dapp
rdapp@gcc.gnu.org
Tue Jun 11 18:09:58 GMT 2024
https://gcc.gnu.org/g:2b438a0d2aa80f051a09b245a58f643540d4004b
commit r15-1187-g2b438a0d2aa80f051a09b245a58f643540d4004b
Author: Robin Dapp <rdapp@ventanamicro.com>
Date: Fri Jun 7 14:36:41 2024 +0200
vect: Merge loop mask and cond_op mask in fold-left reduction [PR115382].
Currently we discard the cond-op mask when the loop is fully masked
which causes wrong code in
gcc.dg/vect/vect-cond-reduc-in-order-2-signed-zero.c
when compiled with
-O3 -march=cascadelake --param vect-partial-vector-usage=2.
This patch ANDs both masks.
gcc/ChangeLog:
PR tree-optimization/115382
* tree-vect-loop.cc (vectorize_fold_left_reduction): Use
prepare_vec_mask.
* tree-vect-stmts.cc (check_load_store_for_partial_vectors):
Remove static of prepare_vec_mask.
* tree-vectorizer.h (prepare_vec_mask): Export.
Diff:
---
gcc/tree-vect-loop.cc | 10 +++++++++-
gcc/tree-vect-stmts.cc | 2 +-
gcc/tree-vectorizer.h | 3 +++
3 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index c471f1564a72..5b1ad06eca66 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -7204,7 +7204,15 @@ vectorize_fold_left_reduction (loop_vec_info loop_vinfo,
tree len = NULL_TREE;
tree bias = NULL_TREE;
if (LOOP_VINFO_FULLY_MASKED_P (loop_vinfo))
- mask = vect_get_loop_mask (loop_vinfo, gsi, masks, vec_num, vectype_in, i);
+ {
+ tree loop_mask = vect_get_loop_mask (loop_vinfo, gsi, masks,
+ vec_num, vectype_in, i);
+ if (is_cond_op)
+ mask = prepare_vec_mask (loop_vinfo, TREE_TYPE (loop_mask),
+ loop_mask, vec_opmask[i], gsi);
+ else
+ mask = loop_mask;
+ }
else if (is_cond_op)
mask = vec_opmask[i];
if (LOOP_VINFO_FULLY_WITH_LENGTH_P (loop_vinfo))
diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index 05a169ecb2dd..831f18253765 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -1643,7 +1643,7 @@ check_load_store_for_partial_vectors (loop_vec_info loop_vinfo, tree vectype,
MASK_TYPE is the type of both masks. If new statements are needed,
insert them before GSI. */
-static tree
+tree
prepare_vec_mask (loop_vec_info loop_vinfo, tree mask_type, tree loop_mask,
tree vec_mask, gimple_stmt_iterator *gsi)
{
diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h
index 97ec9c341e7d..6bb0f5c3a56f 100644
--- a/gcc/tree-vectorizer.h
+++ b/gcc/tree-vectorizer.h
@@ -2508,6 +2508,9 @@ extern void vect_free_slp_tree (slp_tree);
extern bool compatible_calls_p (gcall *, gcall *);
extern int vect_slp_child_index_for_operand (const gimple *, int op, bool);
+extern tree prepare_vec_mask (loop_vec_info, tree, tree, tree,
+ gimple_stmt_iterator *);
+
/* In tree-vect-patterns.cc. */
extern void
vect_mark_pattern_stmts (vec_info *, stmt_vec_info, gimple *, tree);
More information about the Gcc-cvs
mailing list