aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-vect-stmts.c
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2021-08-09 11:42:47 +0200
committerRichard Biener <rguenther@suse.de>2021-08-10 10:12:39 +0200
commit19d1a529fa9f78e7ec7be38d423c90e00cec8f8c (patch)
treec5e6b9af9e2a7ff5e69dc0a769e1d541dca81037 /gcc/tree-vect-stmts.c
parentbb169406cdc9e044eaec500dd742c2fed40f5488 (diff)
downloadgcc-19d1a529fa9f78e7ec7be38d423c90e00cec8f8c.zip
gcc-19d1a529fa9f78e7ec7be38d423c90e00cec8f8c.tar.gz
gcc-19d1a529fa9f78e7ec7be38d423c90e00cec8f8c.tar.bz2
tree-optimization/101801 - rework generic vector vectorization more
This builds ontop of the vect_worthwhile_without_simd_p refactoring done earlier. It was wrong in dropping the appearant double checks for operation support since the optab check can happen with an integer vector emulation mode and thus succeed but vector lowering might not actually support the operation on word_mode. The following patch adds a vect_emulated_vector_p helper and re-instantiates the check where it was previously. It also adds appropriate costing of the scalar stmts emitted by vector lowering to vectorizable_operation which should be the only place such operations are synthesized. I've also cared for the case where the vector mode is supported but the operation is not (though I think this will be unlikely given we're talking about plus, minus and negate). This fixes the observed FAIL of gcc.dg/tree-ssa/gen-vect-11b.c with -m32 where we end up vectorizing a multiplication that ends up being teared down to scalars again by vector lowering. I'm not super happy about all the other places where we're now and previously feeding scalar modes to optab checks where we want to know whether we can vectorize sth but well. 2021-09-08 Richard Biener <rguenther@suse.de> PR tree-optimization/101801 PR tree-optimization/101819 * tree-vectorizer.h (vect_emulated_vector_p): Declare. * tree-vect-loop.c (vect_emulated_vector_p): New function. (vectorizable_reduction): Re-instantiate a check for emulated operations. * tree-vect-stmts.c (vectorizable_shift): Likewise. (vectorizable_operation): Likewise. Cost emulated vector operations according to the scalar sequence synthesized by vector lowering.
Diffstat (limited to 'gcc/tree-vect-stmts.c')
-rw-r--r--gcc/tree-vect-stmts.c45
1 files changed, 37 insertions, 8 deletions
diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c
index 5b94d41..5a5a4da 100644
--- a/gcc/tree-vect-stmts.c
+++ b/gcc/tree-vect-stmts.c
@@ -5682,15 +5682,11 @@ vectorizable_shift (vec_info *vinfo,
if (dump_enabled_p ())
dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
"op not supported by target.\n");
- /* Check only during analysis. */
- if (maybe_ne (GET_MODE_SIZE (vec_mode), UNITS_PER_WORD)
- || (!vec_stmt
- && !vect_can_vectorize_without_simd_p (code)))
- return false;
- if (dump_enabled_p ())
- dump_printf_loc (MSG_NOTE, vect_location,
- "proceeding using word mode.\n");
+ return false;
}
+ /* vector lowering cannot optimize vector shifts using word arithmetic. */
+ if (vect_emulated_vector_p (vectype))
+ return false;
if (!vec_stmt) /* transformation not required. */
{
@@ -6076,6 +6072,7 @@ vectorizable_operation (vec_info *vinfo,
!= CODE_FOR_nothing);
}
+ bool using_emulated_vectors_p = vect_emulated_vector_p (vectype);
if (!target_support_p)
{
if (dump_enabled_p ())
@@ -6088,6 +6085,15 @@ vectorizable_operation (vec_info *vinfo,
if (dump_enabled_p ())
dump_printf_loc (MSG_NOTE, vect_location,
"proceeding using word mode.\n");
+ using_emulated_vectors_p = true;
+ }
+
+ if (using_emulated_vectors_p
+ && !vect_can_vectorize_without_simd_p (code))
+ {
+ if (dump_enabled_p ())
+ dump_printf (MSG_NOTE, "using word mode not possible.\n");
+ return false;
}
int reduc_idx = STMT_VINFO_REDUC_IDX (stmt_info);
@@ -6134,6 +6140,29 @@ vectorizable_operation (vec_info *vinfo,
DUMP_VECT_SCOPE ("vectorizable_operation");
vect_model_simple_cost (vinfo, stmt_info,
ncopies, dt, ndts, slp_node, cost_vec);
+ if (using_emulated_vectors_p)
+ {
+ /* The above vect_model_simple_cost call handles constants
+ in the prologue and (mis-)costs one of the stmts as
+ vector stmt. See tree-vect-generic.c:do_plus_minus/do_negate
+ for the actual lowering that will be applied. */
+ unsigned n
+ = slp_node ? SLP_TREE_NUMBER_OF_VEC_STMTS (slp_node) : ncopies;
+ switch (code)
+ {
+ case PLUS_EXPR:
+ n *= 5;
+ break;
+ case MINUS_EXPR:
+ n *= 6;
+ break;
+ case NEGATE_EXPR:
+ n *= 4;
+ break;
+ default:;
+ }
+ record_stmt_cost (cost_vec, n, scalar_stmt, stmt_info, 0, vect_body);
+ }
return true;
}