This enables use of a predicate mask or length limit for
vectorization of basic blocks in cases where previously only the
equivalent rolled (i.e. loop) form of some source code would have
been vectorized. Predication is used for groups whose size
is not neatly divisible into vectors of lengths that can be
supported directly by the target.
The initial vector mode for an SLP region is "autodetected" by calling
aarch64_preferred_simd_mode, which prefers SVE modes if supported
unless configured otherwise (e.g. VNx4SI for int). If at least one
profitable subgraph can be scheduled then GCC does not try to vectorize
the region using any other modes, even though their estimated costs
might otherwise have been lower.
For example, if analysis of a 24-byte group succeeds with vector mode
V16QI (using types vector(16) and vector(8) char) then the estimated
cost of the vectorized code is 11+11=22. If analysis of the same group
succeeds with vector mode VNx16QI (using type vector([16,16]) char for
both subtrees) then the estimated cost is 15+15=30. In both cases, the
estimated vectorized cost would beat the estimated scalar cost of
96+48=144, but vector([16,16]) is chosen because VNx16QI is tried
first.
This is mitigated by the fact that a sequence of GIMPLE stmts such as:
vectp.14_86 = x_50(D) + 16;
slp_mask_87 = .WHILE_ULT (0, 8, { 0, ... });
.MASK_STORE (vectp.14_86, 8B, slp_mask_87, vect__34.12_85);
are lowered to a fixed-length vector store (e.g., str d30, [x0, 16]) if
possible, instead of a more literal interpretation such as:
add x0, x0, 16
ptrue p7.b, vl8
st1b z30.b, p7, [x0]
The vect_build_slp_tree_2 function used during building of an SLP
tree is updated to prevent it returning failure for BB SLP if the
group size is not an integral multiple of the number of lanes in the
vector type; it now allows such cases if the group size is known to
be less than or equal to the minimum number of lanes in the vector type.
Whether the basic block vectorizer prefers using partial vectors to
splitting groups of isomorphic statements is controlled by a new
parameter, --param=vect-bb-prefer-partial-vectors, which
defaults to 0 (no). AArch64 enables this preference when SVE is
available unless Advanced SIMD has been selected exclusively.
Preferring partial vectors can sometimes cause vectorization to fail
although splitting the group and using narrower vector types would
have succeeded. If vectorization fails after at least one choice of
vector type may have depended on a preference for partial vectors,
GCC will retry analysis with the same vector mode (including VOIDmode
for autodetection) but without the preference for partial vectors,
before trying a different mode (and initially preferring partial
vectors again).
Updated test expectations for gcc.dg/vect/vect-over-widen-*.c,
gcc.target/aarch64/sve/slp_6.c and
gcc.target/aarch64/sve/vec_construct_*.c.
The vec_construct_*.c tests previously expected their output
to use Advanced SIMD instead of SVE despite their use of
vector length agnostic types such as svint16_t and despite
the fact that they are in the aarch64/sve directory. Since
BB SLP can now vectorize these tests using VLA types such
as 'vector([8,8]) char', and because (with one exception) the
resultant code is deemed profitable relative to scalar code,
GCC no longer considers vectorizing using non-VLA types such
as 'vector(8) char' (although the estimated cost with non-VLA
types might have been lower, had it been calculated).
Instruction selection is not the focus of these tests, therefore
I updated them to expect SVE instead (e.g. st1b instead of str)
and added --param=aarch64-autovec-preference=sve-only to reduce
future churn.
Because the cost model takes into account predicate mask
generation for BB SLP with VLA types, the threshold at which
vectorized code wins against scalar code is higher than
before. The number of elements stored by vec_construct_3.c was
increased just enough to allow for that.
Because a V2DI -> V2SI pack becomes a VNx2DI -> VNx4SI -> V2SI
pack when use of predicated tails is enabled, a test that implicitly
requires use of *aarch64_trunc_concat<mode> now fails. This missed
optimization will be restored in a future patch.
gcc/ChangeLog:
* tree-vect-slp.cc (vect_build_slp_tree_1): Remove the early
BB SLP rejection based on vector length.
(vect_build_slp_tree): Relax an assertion to permit BB
vectorization nodes that aren't a multiple of the vector length
if the vector type is long enough.
(force_split_matches): Accept a polynomial vector length and use
its constant lower bound when choosing a splitting point. Handle
SLP group sizes that are exactly divisible by that lower bound
by splitting at the lower bound.
(vect_build_slp_tree_2): For BB SLP, only split an indivisible
group if it could be wider than the chosen vector type. Pass the
polynomial vector length to force_split_matches instead of
assuming a constant number of lanes.
Don't call can_duplicate_and_interleave_p when doing basic block
SLP vectorization.
(vect_analyze_slp_instance): For BB SLP vectorization, use the
constant lower bound of a VLA vector type's number of subparts when
choosing a point at which to split an SLP group, provided that the
matching prefix is divisible by that value.
(vectorizable_slp_permutation_1): Instead of asserting that an
SLP tree node's number of lanes is compatible with the chosen
vector width, return a failure indication if incompatible.
(vectorize_slp_instance_root_stmt): Build a BIT_FIELD_REF instead
of a VIEW_CONVERT_EXPR to extract a fixed-length vector from a
scalable vector result that could have a different number of
subparts, when vectorizing a ctor.
(_bb_vec_info::_bb_vec_info): Add prefer_partial_vectors_p
parameter. Initialize prefer_partial_vectors_p and
maybe_chose_partial_vector_p.
(vect_slp_region): Initialize the preference for partial vectors
from param_vect_bb_prefer_partial_vectors and pass it to
_bb_vec_info. Retry analysis of the same vector mode without
the preference if vectorization fails after a vector type may
have been chosen because of it. Restore the preference when
trying another vector mode.
* tree-vect-stmts.cc (get_vectype_for_scalar_type): Use
bb_vec_info::prefer_partial_vectors_p to choose between
preferring a potentially partial vector type and choosing a
narrower type with which to split the group. Record when a
choice of vector type may have depended on the preference for
partial vectors. When preferring partial vectors, if the
natural vector type is not VLA and has more subparts than the
group size, find the smallest vector type that contains the
group.
(get_mask_type_for_scalar_type): Update the description.
(vect_get_vector_types_for_stmt): As above.
* tree-vectorizer.h (_bb_vec_info::_bb_vec_info): Add
prefer_partial_vectors_p parameter.
(_bb_vec_info::prefer_partial_vectors_p): New member.
(_bb_vec_info::maybe_chose_partial_vector_p): Likewise.
* config/aarch64/aarch64.cc (aarch64_override_options_internal):
Prefer partial vectors to splitting groups for BB vectorization
when SVE is available, unless Advanced SIMD has been selected
exclusively.
* params.opt: Add vect-bb-prefer-partial-vectors parameter.
gcc/testsuite/ChangeLog:
* gcc.dg/vect/vect-over-widen-10.c: Update test expectations to
avoid spurious matching of scan-tree-dump-not pattern.
* gcc.dg/vect/vect-over-widen-13.c: As above.
* gcc.dg/vect/vect-over-widen-14.c: As above.
* gcc.dg/vect/vect-over-widen-17.c: As above.
* gcc.dg/vect/vect-over-widen-18.c: As above.
* gcc.dg/vect/vect-over-widen-5.c: As above.
* gcc.dg/vect/vect-over-widen-6.c: As above.
* gcc.dg/vect/vect-over-widen-7.c: As above.
* gcc.dg/vect/vect-over-widen-8.c: As above.
* gcc.dg/vect/vect-over-widen-9.c: As above.
* gcc.target/aarch64/sve/slp_6.c: Require ld1b, ld1h and ld1w
instructions in the output instead of forbidding them because
discovery of reduction groups now succeeds. Also require
the corresponding st1b, st1h and st1w instructions.
* gcc.target/aarch64/sve/vec_construct_1.c:
Expect SVE instead of ASIMD instructions and add
--param=aarch64-autovec-preference=sve-only to stop
flip-flopping.
* gcc.target/aarch64/sve/vec_construct_2.c: Forbid SVE
instructions as well as ASIMD instructions and add
--param=aarch64-autovec-preference=sve-only to stop
flip-flopping.
* gcc.target/aarch64/sve/vec_construct_3.c: Expect SVE instead
of ASIMD instructions and add
--param=aarch64-autovec-preference=sve-only to avoid
flip-flopping. Increase the number of elements stored to
ensure vectorization using SVE is deemed profitable despite
predicate mask costs.
* gcc.target/aarch64/sve/vec_construct_4.c:
Forbid SVE instructions as well as ASIMD instructions and add
--param=aarch64-autovec-preference=sve-only to stop
flip-flopping. Fix a missing end of comment delimiter.
* gcc.target/aarch64/sve/vec_construct_5.c:
Expect SVE instead of ASIMD instructions and add
--param=aarch64-autovec-preference=sve-only to stop
flip-flopping.
* gcc.target/aarch64/sve/truncated_concatenation_1.c:
Mark one scan-assembler-times check as xfail because code
generation regresses (PR 127271).
---
gcc/config/aarch64/aarch64.cc | 7 +
gcc/params.opt | 4 +
.../gcc.dg/vect/vect-over-widen-10.c | 2 +-
.../gcc.dg/vect/vect-over-widen-13.c | 2 +-
.../gcc.dg/vect/vect-over-widen-14.c | 2 +-
.../gcc.dg/vect/vect-over-widen-17.c | 2 +-
.../gcc.dg/vect/vect-over-widen-18.c | 2 +-
gcc/testsuite/gcc.dg/vect/vect-over-widen-5.c | 2 +-
gcc/testsuite/gcc.dg/vect/vect-over-widen-6.c | 2 +-
gcc/testsuite/gcc.dg/vect/vect-over-widen-7.c | 2 +-
gcc/testsuite/gcc.dg/vect/vect-over-widen-8.c | 2 +-
gcc/testsuite/gcc.dg/vect/vect-over-widen-9.c | 2 +-
gcc/testsuite/gcc.target/aarch64/sve/slp_6.c | 18 +-
.../aarch64/sve/truncated_concatenation_1.c | 5 +-
.../gcc.target/aarch64/sve/vec_construct_1.c | 11 +-
.../gcc.target/aarch64/sve/vec_construct_2.c | 4 +-
.../gcc.target/aarch64/sve/vec_construct_3.c | 25 ++-
.../gcc.target/aarch64/sve/vec_construct_4.c | 5 +-
.../gcc.target/aarch64/sve/vec_construct_5.c | 13 +-
gcc/tree-vect-slp.cc | 154 +++++++++++++-----
gcc/tree-vect-stmts.cc | 75 +++++++--
gcc/tree-vectorizer.h | 5 +-
22 files changed, 245 insertions(+), 101 deletions(-)
diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index 6c1229d0a95..ca6d517a484 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -20450,6 +20450,13 @@ aarch64_override_options_internal (struct gcc_options
*opts,
aarch64_autovec_preference,
opts->x_autovec_preference);
+ /* Try vectorizing basic blocks using partial vectors before falling back
+ to splitting SLP groups, if we have SVE. */
+ if ((isa_flags & AARCH64_FL_SVE)
+ && aarch64_autovec_preference != AARCH64_AUTOVEC_ASIMD_ONLY)
+ SET_OPTION_IF_UNSET (opts, opts_set, param_vect_bb_prefer_partial_vectors,
+ 1);
+
aarch64_override_options_after_change_1 (opts);
}
diff --git a/gcc/params.opt b/gcc/params.opt
index b1be4339bb6..73332cfb051 100644
--- a/gcc/params.opt
+++ b/gcc/params.opt
@@ -1299,6 +1299,10 @@ Bound on number of runtime checks inserted by the
vectorizer's loop versioning f
Common Joined UInteger Var(param_vect_partial_vector_usage) Init(2)
IntegerRange(0, 2) Param Optimization NoOffload
Controls how loop vectorizer uses partial vectors. 0 means never, 1 means
only for loops whose need to iterate can be removed, 2 means for all loops.
The default value is 2.
+-param=vect-bb-prefer-partial-vectors=
+Common Joined UInteger Var(param_vect_bb_prefer_partial_vectors) Init(0)
IntegerRange(0, 1) Param Optimization NoOffload
+Whether the basic block vectorizer prefers using partial vectors to splitting
groups of isomorphic statements. 0 means no, 1 means yes. The default value
is 0.
+
-param=vect-inner-loop-cost-factor=
Common Joined UInteger Var(param_vect_inner_loop_cost_factor) Init(50)
IntegerRange(1, 10000) Param Optimization NoOffload
The maximum factor which the loop vectorizer applies to the cost of statements
in an inner loop relative to the loop being vectorized.
diff --git a/gcc/testsuite/gcc.dg/vect/vect-over-widen-10.c
b/gcc/testsuite/gcc.dg/vect/vect-over-widen-10.c
index f0140e4ef6d..6efcf739db9 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-over-widen-10.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-over-widen-10.c
@@ -16,5 +16,5 @@
/* { dg-final { scan-tree-dump {vect_recog_over_widening_pattern:
detected:[^\n]* >> 1} "vect" } } */
/* { dg-final { scan-tree-dump {vect_recog_over_widening_pattern:
detected:[^\n]* >> 2} "vect" } } */
/* { dg-final { scan-tree-dump {vect_recog_cast_forwprop_pattern:
detected:[^\n]* \(unsigned char\)} "vect" } } */
-/* { dg-final { scan-tree-dump-not {vector[^ ]* int} "vect" } } */
+/* { dg-final { scan-tree-dump-not {vector[^ ]* int vect__} "vect" } } */
/* { dg-final { scan-tree-dump-times "vectorized 1 loop" 1 "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/vect-over-widen-13.c
b/gcc/testsuite/gcc.dg/vect/vect-over-widen-13.c
index 08a65ea5518..720353716cf 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-over-widen-13.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-over-widen-13.c
@@ -48,5 +48,5 @@ main (void)
/* { dg-final { scan-tree-dump {vect_recog_over_widening_pattern:
detected:[^\n]* \+} "vect" } } */
/* { dg-final { scan-tree-dump {vect_recog_over_widening_pattern:
detected:[^\n]* / 2} "vect" } } */
/* { dg-final { scan-tree-dump {vect_recog_cast_forwprop_pattern:
detected:[^\n]* = \(signed char\)} "vect" } } */
-/* { dg-final { scan-tree-dump-not {vector[^ ]* int} "vect" } } */
+/* { dg-final { scan-tree-dump-not {vector[^ ]* int vect__} "vect" } } */
/* { dg-final { scan-tree-dump-times "vectorized 1 loop" 1 "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/vect-over-widen-14.c
b/gcc/testsuite/gcc.dg/vect/vect-over-widen-14.c
index dfa09f5d2ca..f1d5f95c543 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-over-widen-14.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-over-widen-14.c
@@ -15,5 +15,5 @@
/* { dg-final { scan-tree-dump {vect_recog_over_widening_pattern:
detected:[^\n]* \+} "vect" } } */
/* { dg-final { scan-tree-dump {vect_recog_over_widening_pattern:
detected:[^\n]* >> 1} "vect" } } */
/* { dg-final { scan-tree-dump {vect_recog_cast_forwprop_pattern:
detected:[^\n]* = \(unsigned char\)} "vect" } } */
-/* { dg-final { scan-tree-dump-not {vector[^ ]* int} "vect" } } */
+/* { dg-final { scan-tree-dump-not {vector[^ ]* int vect__} "vect" } } */
/* { dg-final { scan-tree-dump-times "vectorized 1 loop" 1 "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/vect-over-widen-17.c
b/gcc/testsuite/gcc.dg/vect/vect-over-widen-17.c
index 53fcfd0c06c..ac1a0f86727 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-over-widen-17.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-over-widen-17.c
@@ -46,5 +46,5 @@ main (void)
adopts realign_load scheme. It requires rs6000_builtin_mask_for_load to
generate mask whose return type is vector char. */
/* { dg-final { scan-tree-dump-not {vector[^\n]*char} "vect" { target
vect_hw_misalign } } } */
-/* { dg-final { scan-tree-dump-not {vector[^ ]* int} "vect" } } */
+/* { dg-final { scan-tree-dump-not {vector[^ ]* int vect__} "vect" } } */
/* { dg-final { scan-tree-dump-times "vectorized 1 loop" 1 "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/vect-over-widen-18.c
b/gcc/testsuite/gcc.dg/vect/vect-over-widen-18.c
index aa58cd1c957..3ebfaa78270 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-over-widen-18.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-over-widen-18.c
@@ -47,5 +47,5 @@ main (void)
/* { dg-final { scan-tree-dump {vect_recog_over_widening_pattern:
detected:[^\n]* |} "vect" } } */
/* { dg-final { scan-tree-dump {vect_recog_over_widening_pattern:
detected:[^\n]* <<} "vect" } } */
/* { dg-final { scan-tree-dump {vector[^\n]*char} "vect" } } */
-/* { dg-final { scan-tree-dump-not {vector[^ ]* int} "vect" } } */
+/* { dg-final { scan-tree-dump-not {vector[^ ]* int vect__} "vect" } } */
/* { dg-final { scan-tree-dump-times "vectorized 1 loop" 1 "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/vect-over-widen-5.c
b/gcc/testsuite/gcc.dg/vect/vect-over-widen-5.c
index c2ab11a9d32..1d89789a86d 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-over-widen-5.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-over-widen-5.c
@@ -49,5 +49,5 @@ main (void)
/* { dg-final { scan-tree-dump {vect_recog_over_widening_pattern:
detected:[^\n]* \+ } "vect" } } */
/* { dg-final { scan-tree-dump {vect_recog_over_widening_pattern:
detected:[^\n]* >> 1} "vect" } } */
/* { dg-final { scan-tree-dump {vect_recog_cast_forwprop_pattern:
detected:[^\n]* \(signed char\)} "vect" } } */
-/* { dg-final { scan-tree-dump-not {vector[^ ]* int} "vect" } } */
+/* { dg-final { scan-tree-dump-not {vector[^ ]* int vect__} "vect" } } */
/* { dg-final { scan-tree-dump-times "vectorized 1 loop" 1 "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/vect-over-widen-6.c
b/gcc/testsuite/gcc.dg/vect/vect-over-widen-6.c
index bda92c965e0..62d5a52587e 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-over-widen-6.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-over-widen-6.c
@@ -13,5 +13,5 @@
/* { dg-final { scan-tree-dump {vect_recog_over_widening_pattern:
detected:[^\n]* \+ } "vect" } } */
/* { dg-final { scan-tree-dump {vect_recog_over_widening_pattern:
detected:[^\n]* >> 1} "vect" } } */
/* { dg-final { scan-tree-dump {vect_recog_cast_forwprop_pattern:
detected:[^\n]* \(unsigned char\)} "vect" } } */
-/* { dg-final { scan-tree-dump-not {vector[^ ]* int} "vect" } } */
+/* { dg-final { scan-tree-dump-not {vector[^ ]* int vect__} "vect" } } */
/* { dg-final { scan-tree-dump-times "vectorized 1 loop" 1 "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/vect-over-widen-7.c
b/gcc/testsuite/gcc.dg/vect/vect-over-widen-7.c
index 1d55e13fb1f..6e09631009a 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-over-widen-7.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-over-widen-7.c
@@ -51,5 +51,5 @@ main (void)
/* { dg-final { scan-tree-dump {vect_recog_over_widening_pattern:
detected:[^\n]* \+ } "vect" } } */
/* { dg-final { scan-tree-dump {vect_recog_over_widening_pattern:
detected:[^\n]* >> 2} "vect" } } */
/* { dg-final { scan-tree-dump {vect_recog_cast_forwprop_pattern:
detected:[^\n]* \(signed char\)} "vect" } } */
-/* { dg-final { scan-tree-dump-not {vector[^ ]* int} "vect" } } */
+/* { dg-final { scan-tree-dump-not {vector[^ ]* int vect__} "vect" } } */
/* { dg-final { scan-tree-dump-times "vectorized 1 loop" 1 "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/vect-over-widen-8.c
b/gcc/testsuite/gcc.dg/vect/vect-over-widen-8.c
index 553c0712a79..b6d650beab4 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-over-widen-8.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-over-widen-8.c
@@ -16,5 +16,5 @@
/* { dg-final { scan-tree-dump {vect_recog_over_widening_pattern:
detected:[^\n]* \+ } "vect" } } */
/* { dg-final { scan-tree-dump {vect_recog_over_widening_pattern:
detected:[^\n]* >> 2} "vect" } } */
/* { dg-final { scan-tree-dump {vect_recog_cast_forwprop_pattern:
detected:[^\n]* \(unsigned char\)} "vect" } } */
-/* { dg-final { scan-tree-dump-not {vector[^ ]* int} "vect" } } */
+/* { dg-final { scan-tree-dump-not {vector[^ ]* int vect__} "vect" } } */
/* { dg-final { scan-tree-dump-times "vectorized 1 loop" 1 "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/vect-over-widen-9.c
b/gcc/testsuite/gcc.dg/vect/vect-over-widen-9.c
index 36bfc68e053..e82f8a571da 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-over-widen-9.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-over-widen-9.c
@@ -56,5 +56,5 @@ main (void)
/* { dg-final { scan-tree-dump {vect_recog_over_widening_pattern:
detected:[^\n]* >> 1} "vect" } } */
/* { dg-final { scan-tree-dump {vect_recog_over_widening_pattern:
detected:[^\n]* >> 2} "vect" } } */
/* { dg-final { scan-tree-dump {vect_recog_cast_forwprop_pattern:
detected:[^\n]* \(signed char\)} "vect" } } */
-/* { dg-final { scan-tree-dump-not {vector[^ ]* int} "vect" } } */
+/* { dg-final { scan-tree-dump-not {vector[^ ]* int vect__} "vect" } } */
/* { dg-final { scan-tree-dump-times "vectorized 1 loop" 1 "vect" } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/slp_6.c
b/gcc/testsuite/gcc.target/aarch64/sve/slp_6.c
index 44d128477d2..0ac3f09cbdb 100644
--- a/gcc/testsuite/gcc.target/aarch64/sve/slp_6.c
+++ b/gcc/testsuite/gcc.target/aarch64/sve/slp_6.c
@@ -36,11 +36,21 @@ vec_slp_##TYPE (TYPE *restrict a, TYPE *restrict b, int n)
\
TEST_ALL (VEC_PERM)
-/* These loops can't use SLP. */
-/* { dg-final { scan-assembler-not {\tld1b\t} } } */
-/* { dg-final { scan-assembler-not {\tld1h\t} } } */
-/* { dg-final { scan-assembler-not {\tld1w\t} } } */
+/* When this test was written, these loops couldn't use SLP. Since changes to
+ enable tail predication, SLP discovery of size 3 reduction groups instead
+ succeeds, producing predicated loads such as ld1b z25.b, p7/z, [x1] for
+ {b[0], b[1], b[2]}. */
+
+/* { dg-final { scan-assembler {\tld1b\t} } } */
+/* { dg-final { scan-assembler {\tld1h\t} } } */
+/* { dg-final { scan-assembler {\tld1w\t} } } */
/* { dg-final { scan-assembler-not {\tld1d\t} } } */
+
+/* { dg-final { scan-assembler {\tst1b\t} } } */
+/* { dg-final { scan-assembler {\tst1h\t} } } */
+/* { dg-final { scan-assembler {\tst1w\t} } } */
+/* { dg-final { scan-assembler-not {\tst1d\t} } } */
+
/* { dg-final { scan-assembler {\tld3b\t} } } */
/* { dg-final { scan-assembler {\tld3h\t} } } */
/* { dg-final { scan-assembler {\tld3w\t} } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/truncated_concatenation_1.c
b/gcc/testsuite/gcc.target/aarch64/sve/truncated_concatenation_1.c
index 95577a1a9ef..4cbad506ece 100644
--- a/gcc/testsuite/gcc.target/aarch64/sve/truncated_concatenation_1.c
+++ b/gcc/testsuite/gcc.target/aarch64/sve/truncated_concatenation_1.c
@@ -29,4 +29,7 @@ int32x2_t f3 (svint64_t a, svint64_t b) {
/* { dg-final { scan-assembler-not {\tfcvtn\t} } }*/
/* { dg-final { scan-assembler-times {\tuzp1\tv[0-9]+\.8b, v[0-9]+\.8b,
v[0-9]+\.8b} 1 } }*/
/* { dg-final { scan-assembler-times {\tuzp1\tv[0-9]+\.4h, v[0-9]+\.4h,
v[0-9]+\.4h} 1 } }*/
-/* { dg-final { scan-assembler-times {\tuzp1\tv[0-9]+\.2s, v[0-9]+\.2s,
v[0-9]+\.2s} 1 } }*/
\ No newline at end of file
+/* PR 127271: xfail because SLP with predicated tails changes a V2DI -> V2SI
+ pack into a VNx2DI -> VNx4SI -> V2SI pack, which prevents use of
+ *aarch64_trunc_concat<mode>. */
+/* { dg-final { scan-assembler-times {\tuzp1\tv[0-9]+\.2s, v[0-9]+\.2s,
v[0-9]+\.2s} 1 { xfail *-*-* } } }*/
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/vec_construct_1.c
b/gcc/testsuite/gcc.target/aarch64/sve/vec_construct_1.c
index 2f8ce6808a9..421a990a739 100644
--- a/gcc/testsuite/gcc.target/aarch64/sve/vec_construct_1.c
+++ b/gcc/testsuite/gcc.target/aarch64/sve/vec_construct_1.c
@@ -1,12 +1,11 @@
/* { dg-do compile } */
-/* { dg-options "-O2 -ftree-slp-vectorize" } */
+/* { dg-options "-O2 -ftree-slp-vectorize
--param=aarch64-autovec-preference=sve-only" } */
/* Test that a group of stores of 8 elements derived from a horizontal
reduction is vectorized by constructing a vector and storing it.
Since there are no GPR-to-SIMD register transfers, there is no
- need to charge additional costs for them. Only one STR (Store
- vector reg, unsigned immed, B/H/S/D-form) instruction is required
- instead of 8.
+ need to charge additional costs for them. Only one vector store
+ instruction is required instead of 8.
*/
#include <arm_sve.h>
@@ -30,8 +29,8 @@ foo (svint8_t src0, svint8_t src1, svint8_t src2, svint8_t
src3, svint8_t src4,
s.h = svaddv_s8 (all, src7);
}
-/* { dg-final { scan-assembler-times {\tins\tv[0-9]+\.b\[[0-9]+\],
v[0-9]+\.b\[[0-9]+\]\n} 7 } } */
-/* { dg-final { scan-assembler-times {\tstr\td[0-9]+, } 1 } } */
+/* { dg-final { scan-assembler-times {\tinsr\tz[0-9]+\.h, h[0-9]+\n} 7 } } */
+/* { dg-final { scan-assembler-times {\tst1b\tz[0-9]+\.h, p[0-9]+,
\[x[0-9]+\]\n} 1 } } */
/* { dg-final { scan-assembler-not {\tstr\tb[0-9]+, } } } */
/* { dg-final { scan-assembler-not {\tstrb\tw[0-9]+, } } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/vec_construct_2.c
b/gcc/testsuite/gcc.target/aarch64/sve/vec_construct_2.c
index 6715118d7b0..2bf537e13e2 100644
--- a/gcc/testsuite/gcc.target/aarch64/sve/vec_construct_2.c
+++ b/gcc/testsuite/gcc.target/aarch64/sve/vec_construct_2.c
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-options "-O2 -ftree-slp-vectorize" } */
+/* { dg-options "-O2 -ftree-slp-vectorize
--param=aarch64-autovec-preference=sve-only" } */
/* Test that a group of stores of 8 elements derived from the results of calls
to a function that has only vector parameters and returns a scalar result is
@@ -40,3 +40,5 @@ foo (svint8_t src0, svint8_t src1, svint8_t src2, svint8_t
src3, svint8_t src4,
/* { dg-final { scan-assembler-not {\tins\tv[0-9]+\.b\[[0-9]+\], w[0-9]+\n} }
} */
/* { dg-final { scan-assembler-not {\tstr\td[0-9]+, } } } */
+/* { dg-final { scan-assembler-not {\tfmov\th[0-9]+, h[0-9]+\n} } } */
+/* { dg-final { scan-assembler-not {\tinsr\tz[0-9]+\.b, w[0-9]+\n} } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/vec_construct_3.c
b/gcc/testsuite/gcc.target/aarch64/sve/vec_construct_3.c
index 8143d0050ad..28346d26a73 100644
--- a/gcc/testsuite/gcc.target/aarch64/sve/vec_construct_3.c
+++ b/gcc/testsuite/gcc.target/aarch64/sve/vec_construct_3.c
@@ -1,24 +1,25 @@
/* { dg-do compile } */
-/* { dg-options "-O2 -ftree-slp-vectorize" } */
+/* { dg-options "-O2 -ftree-slp-vectorize
--param=aarch64-autovec-preference=sve-only" } */
-/* Test that a group of stores of 8 elements derived from a horizontal
+/* Test that a group of stores of 14 elements derived from a horizontal
reduction is vectorized by constructing a vector and storing it
even if the results of the reductions are narrowed.
Since there are no GPR-to-SIMD register transfers, there is no
- need to charge additional costs for them. Only one STR (Store
- vector reg, unsigned immed, B/H/S/D-form) instruction is required
- instead of 8.
+ need to charge additional costs for them. Only one vector store
+ instruction is required instead of 14.
*/
#include <arm_sve.h>
struct S
{
- char a, b, c, d, e, f, g, h;
+ char a, b, c, d, e, f, g, h, i, j, k, l, m, n;
} s;
void
foo (svint16_t src0, svint32_t src1, svint16_t src2, svint32_t src3,
- svint32_t src4, svint16_t src5, svint32_t src6, svint16_t src7)
+ svint32_t src4, svint16_t src5, svint32_t src6, svint16_t src7,
+ svint16_t src8, svint32_t src9, svint16_t src10, svint32_t src11,
+ svint32_t src12, svint16_t src13)
{
svbool_t all16 = svptrue_b16 ();
svbool_t all32 = svptrue_b32 ();
@@ -30,10 +31,16 @@ foo (svint16_t src0, svint32_t src1, svint16_t src2,
svint32_t src3,
s.f = svminv_s16 (all16, src5);
s.g = svlastb_s32 (svptrue_pat_b32 (SV_VL1), src6);
s.h = svaddv_s16 (all16, src7);
+ s.i = svmaxv_s16 (all16, src8);
+ s.j = svminv_s32 (all32, src9);
+ s.k = svlastb_s16 (svptrue_pat_b16 (SV_VL1), src10);
+ s.l = svaddv_s32 (all32, src11);
+ s.m = svmaxv_s32 (all32, src12);
+ s.n = svminv_s16 (all16, src13);
}
-/* { dg-final { scan-assembler-times {\tins\tv[0-9]+\.b\[[0-9]+\],
v[0-9]+\.b\[[0-9]+\]\n} 7 } } */
-/* { dg-final { scan-assembler-times {\tstr\td[0-9]+, } 1 } } */
+/* { dg-final { scan-assembler-times {\tinsr\tz[0-9]+\.b, b[0-9]+\n} 13 } } */
+/* { dg-final { scan-assembler-times {\tst1b\tz[0-9]+\.b, p[0-9]+,
\[x[0-9]\]\n} 1 } } */
/* { dg-final { scan-assembler-not {\tstr\tb[0-9]+, } } } */
/* { dg-final { scan-assembler-not {\tstrb\tw[0-9]+, } } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/vec_construct_4.c
b/gcc/testsuite/gcc.target/aarch64/sve/vec_construct_4.c
index 49f8114b64c..3d41af684a3 100644
--- a/gcc/testsuite/gcc.target/aarch64/sve/vec_construct_4.c
+++ b/gcc/testsuite/gcc.target/aarch64/sve/vec_construct_4.c
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-options "-O2 -ftree-slp-vectorize" } */
+/* { dg-options "-O2 -ftree-slp-vectorize
--param=aarch64-autovec-preference=sve-only" } */
/* Test that a group of stores of 8 elements derived from a horizontal
reduction is not vectorized by constructing a vector and storing it
@@ -33,5 +33,6 @@ foo (svint16_t src0, svint8_t src1, svint16_t src2, svint8_t
src3,
/* { dg-final { scan-assembler-times {\tstp\tw[0-9]+, w[0-9]+,} 4 } } */
/* { dg-final { scan-assembler-not {\tins\tv[0-9]+\.s\[[0-9]+\], w[0-9]+\n} }
} */
-/* { dg-final { scan-assembler-not {\tfmov\ts[0-9]+, w[0-9]+\n} } }
+/* { dg-final { scan-assembler-not {\tfmov\ts[0-9]+, w[0-9]+\n} } } */
/* { dg-final { scan-assembler-not {\tstp\tq[0-9]+, q[0-9]+,} } } */
+/* { dg-final { scan-assembler-not {\tinsr\tz[0-9]+.s, w[0-9]+\n} } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/vec_construct_5.c
b/gcc/testsuite/gcc.target/aarch64/sve/vec_construct_5.c
index 983d6c69ebc..28c7e68f303 100644
--- a/gcc/testsuite/gcc.target/aarch64/sve/vec_construct_5.c
+++ b/gcc/testsuite/gcc.target/aarch64/sve/vec_construct_5.c
@@ -1,13 +1,12 @@
/* { dg-do compile } */
-/* { dg-options "-O2 -ftree-slp-vectorize" } */
+/* { dg-options "-O2 -ftree-slp-vectorize
--param=aarch64-autovec-preference=sve-only" } */
/* Test that a group of stores of 8 elements derived from lane extractions is
vectorized by constructing a vector and storing it. Since there are no
GPR-to-SIMD register transfers, there is no need to charge additional costs
- for them. Only one STR (Store vector reg, unsigned immed, B/H/S/D-form)
- instruction is required instead of 8. This is a test for over-restriction
- of an exemption from usual GPR-to-SIMD costs to reductions (in case lane
- extraction is not treated as a reduction).
+ for them. Only one vector store instruction is required instead of 8. This
+ is a test for over-restriction of an exemption from usual GPR-to-SIMD costs
+ to reductions (in case lane extraction is not treated as a reduction).
*/
#include <arm_sve.h>
@@ -30,8 +29,8 @@ foo (svint8_t src0, svint8_t src1, svint8_t src2, svint8_t
src3, svint8_t src4,
s.h = svlastb_s8 (p, src7);
}
-/* { dg-final { scan-assembler-times {\tins\tv[0-9]+\.b\[[0-9]+\],
v[0-9]+\.b\[[0-9]+\]\n} 7 } } */
-/* { dg-final { scan-assembler-times {\tstr\td[0-9]+, } 1 } } */
+/* { dg-final { scan-assembler-times {\tinsr\tz[0-9]+\.h, h[0-9]+\n} 7 } } */
+/* { dg-final { scan-assembler-times {\tst1b\tz[0-9]+\.h, p[0-9]+,
\[x[0-9]+\]\n} 1 } } */
/* { dg-final { scan-assembler-not {\tstr\tb[0-9]+, } } } */
/* { dg-final { scan-assembler-not {\tstrb\tw[0-9]+, } } } */
diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc
index 095ab0ce210..db497d492c8 100644
--- a/gcc/tree-vect-slp.cc
+++ b/gcc/tree-vect-slp.cc
@@ -1752,26 +1752,6 @@ vect_build_slp_tree_1 (vec_info *vinfo, unsigned char
*swap,
matches[0] = -1;
return false;
}
- /* Check nunits required but continue analysis, producing matches[]
- as if nunits was not an issue. This allows splitting of groups
- to happen. */
- unsigned HOST_WIDE_INT const_nunits = 0;
- if (vectype
- && is_a <bb_vec_info> (vinfo)
- && !multiple_p (group_size, TYPE_VECTOR_SUBPARTS (vectype)))
- {
- if (!TYPE_VECTOR_SUBPARTS (vectype).is_constant (&const_nunits)
- || const_nunits > group_size)
- {
- if (dump_enabled_p ())
- dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
- "Build SLP failed: unrolling required "
- "in basic block SLP\n");
- /* Fatal mismatch. */
- matches[0] = -1;
- return false;
- }
- }
gcc_assert (vectype || !gimple_get_lhs (first_stmt_info->stmt));
*node_vectype = vectype;
@@ -2055,6 +2035,8 @@ vect_build_slp_tree (vec_info *vinfo,
SLP_TREE_REF_COUNT (res)++;
/* For BB vectorization nodes that need splitting should be failed. */
gcc_assert (!is_a <bb_vec_info> (vinfo)
+ || known_le (group_size,
+ TYPE_VECTOR_SUBPARTS (res->vectype))
|| multiple_p (group_size,
TYPE_VECTOR_SUBPARTS (res->vectype)));
}
@@ -2101,21 +2083,35 @@ vect_slp_build_two_operator_nodes (slp_tree perm, tree
vectype,
SLP_TREE_CHILDREN (perm).quick_push (child2);
}
-/* For isomorphic matches[], indicate a splitting point according to
- CONST_NUNITS. */
+/* For isomorphic matches[], indicate a splitting point within an SLP group of
+ GROUP_SIZE stmts according to the NUNITS of its vector type. */
static void
force_split_matches (match_elt_t *matches, unsigned group_size,
- unsigned const_nunits)
+ poly_uint64 nunits)
{
if (dump_enabled_p ())
dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
"Build SLP failed: unrolling required "
"in basic block SLP\n");
- /* With constant vector elements simulate a mismatch at the
+ /* With constant or minimum vector length, simulate a mismatch at the
point we need to split. But indicate the tail is isomorphic. */
+ unsigned const_nunits = constant_lower_bound (nunits);
+ gcc_assert ((const_nunits & (const_nunits - 1)) == 0);
unsigned tail = group_size & (const_nunits - 1);
+
+ /* An SLP group size can be exactly divisible by the minimum number of lanes
+ provided by its variable-length vector type, despite the required number
of
+ vectors of that type being unknown. In such cases, split off one group
+ of minimum vector length. */
+ if (tail == 0)
+ {
+ gcc_assert (!nunits.is_constant ());
+ tail = const_nunits;
+ }
+
+ gcc_assert (group_size >= tail);
for (unsigned i = group_size - tail; i < group_size; ++i)
matches[i] = (int)(group_size - tail);
}
@@ -2221,8 +2217,13 @@ vect_build_slp_tree_2 (vec_info *vinfo, slp_tree node,
&vectype))
return NULL;
+ /* Split an SLP group if its elements cannot be represented by an integral
+ number of vectors of the chosen type. For variable-length types, assume
+ that a single vector can represent any number of elements not greater
+ than its minimum number of lanes. */
bool soft_fail
= (is_a <bb_vec_info> (vinfo)
+ && maybe_gt (group_size, TYPE_VECTOR_SUBPARTS (vectype))
&& !multiple_p (group_size, TYPE_VECTOR_SUBPARTS (vectype)));
/* If the SLP node is a load, terminate the recursion unless masked. */
@@ -2232,7 +2233,7 @@ vect_build_slp_tree_2 (vec_info *vinfo, slp_tree node,
if (soft_fail)
{
force_split_matches (matches, group_size,
- TYPE_VECTOR_SUBPARTS (vectype).to_constant ());
+ TYPE_VECTOR_SUBPARTS (vectype));
return NULL;
}
if (STMT_VINFO_GATHER_SCATTER_P (stmt_info))
@@ -2368,7 +2369,7 @@ vect_build_slp_tree_2 (vec_info *vinfo, slp_tree node,
if (soft_fail)
{
force_split_matches (matches, group_size,
- TYPE_VECTOR_SUBPARTS (vectype).to_constant ());
+ TYPE_VECTOR_SUBPARTS (vectype));
return NULL;
}
/* vect_build_slp_tree_2 determined all BIT_FIELD_REFs reference
@@ -2574,13 +2575,20 @@ vect_build_slp_tree_2 (vec_info *vinfo, slp_tree node,
/* Check whether we can build the invariant. If we can't
we never will be able to. */
tree type = TREE_TYPE (chains[0][n].op);
- if (!GET_MODE_SIZE (vinfo->vector_mode).is_constant ()
- && (TREE_CODE (type) == BOOLEAN_TYPE
- || !can_duplicate_and_interleave_p (vinfo, group_size,
- type)))
+ if (!GET_MODE_SIZE (vinfo->vector_mode).is_constant ())
{
- matches[0] = -1;
- goto out;
+ if (TREE_CODE (type) == BOOLEAN_TYPE)
+ {
+ matches[0] = -1;
+ goto out;
+ }
+ if (!is_a <bb_vec_info> (vinfo)
+ && !can_duplicate_and_interleave_p (vinfo, group_size,
+ type))
+ {
+ matches[0] = -1;
+ goto out;
+ }
}
}
else if (dt != vect_internal_def)
@@ -2839,7 +2847,8 @@ out:
if (soft_fail)
{
force_split_matches (matches, group_size,
- TYPE_VECTOR_SUBPARTS (vectype).to_constant ());
+ TYPE_VECTOR_SUBPARTS (vectype));
+ vect_free_oprnd_info (oprnds_info);
return NULL;
}
@@ -3023,7 +3032,7 @@ out:
uniform_val = NULL_TREE;
break;
}
- if (!uniform_val
+ if (!uniform_val && !is_a <bb_vec_info> (vinfo)
&& !can_duplicate_and_interleave_p (vinfo,
oprnd_info->ops.length (),
TREE_TYPE (op0)))
@@ -5290,8 +5299,17 @@ vect_analyze_slp_instance (vec_info *vinfo,
tree vectype = get_vectype_for_scalar_type (vinfo, scalar_type,
1 << floor_log2 (i));
unsigned HOST_WIDE_INT const_nunits;
- if (vectype
- && TYPE_VECTOR_SUBPARTS (vectype).is_constant (&const_nunits))
+ bool split_p = false;
+ if (vectype)
+ {
+ poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype);
+ if (nunits.is_constant (&const_nunits))
+ split_p = (i >= const_nunits);
+ else if ((const_nunits = constant_lower_bound (nunits)) > 1
+ && (i % const_nunits) == 0)
+ split_p = true;
+ }
+ if (split_p)
{
/* Split into two groups at the first vector boundary. */
gcc_assert ((const_nunits & (const_nunits - 1)) == 0);
@@ -8828,9 +8846,11 @@ vect_make_slp_decision (loop_vec_info loop_vinfo)
/* Initialize a bb_vec_info struct for the statements in BBS basic blocks. */
-_bb_vec_info::_bb_vec_info (vec<basic_block> _bbs, vec_info_shared *shared)
- : vec_info (vec_info::bb, shared),
- roots (vNULL)
+_bb_vec_info::_bb_vec_info (vec<basic_block> _bbs, vec_info_shared *shared,
+ bool prefer_partial_vectors_p)
+ : vec_info (vec_info::bb, shared), roots (vNULL),
+ prefer_partial_vectors_p (prefer_partial_vectors_p),
+ maybe_chose_partial_vector_p (false)
{
/* The region we are operating on. bbs[0] is the entry, excluding
its PHI nodes. In the future we might want to track an explicit
@@ -8861,7 +8881,6 @@ _bb_vec_info::_bb_vec_info (vec<basic_block> _bbs,
vec_info_shared *shared)
}
}
-
/* Free BB_VINFO struct, as well as all the stmt_vec_info structs of all the
stmts in the basic block. */
@@ -10780,6 +10799,7 @@ vect_slp_region (vec<basic_block> bbs,
vec<data_reference_p> datarefs,
machine_mode next_vector_mode = VOIDmode;
targetm.vectorize.autovectorize_vector_modes (&vector_modes, false);
unsigned int mode_i = 0;
+ bool prefer_partial_vectors_p = param_vect_bb_prefer_partial_vectors;
vec_info_shared shared;
@@ -10788,7 +10808,7 @@ vect_slp_region (vec<basic_block> bbs,
vec<data_reference_p> datarefs,
{
bool vectorized = false;
bool fatal = false;
- bb_vinfo = new _bb_vec_info (bbs, &shared);
+ bb_vinfo = new _bb_vec_info (bbs, &shared, prefer_partial_vectors_p);
bool first_time_p = shared.datarefs.is_empty ();
BB_VINFO_DATAREFS (bb_vinfo) = datarefs;
@@ -10937,6 +10957,24 @@ vect_slp_region (vec<basic_block> bbs,
vec<data_reference_p> datarefs,
GET_MODE_NAME (bb_vinfo->vector_mode));
}
+ /* If we previously preferred using partial vectors to splitting a group,
+ and at least one choice of vector type may have depended on that
+ preference, then retry without it.
+ ??? We could make this fallback depend on the cause of failure, but
+ choosing different vector types can change the shape of an SLP graph
+ such that vectorization succeeds for apparently unrelated reasons. */
+ if (!vectorized && !fatal && prefer_partial_vectors_p
+ && bb_vinfo->maybe_chose_partial_vector_p)
+ {
+ if (dump_enabled_p ())
+ dump_printf_loc (MSG_NOTE, vect_location,
+ "***** Re-trying analysis without preference for "
+ "partial vectors\n");
+ prefer_partial_vectors_p = false;
+ delete bb_vinfo;
+ continue;
+ }
+
if (mode_i == 0)
autodetected_vector_mode = bb_vinfo->vector_mode;
@@ -10982,6 +11020,7 @@ vect_slp_region (vec<basic_block> bbs,
vec<data_reference_p> datarefs,
/* Try the next biggest vector size. */
next_vector_mode = vector_modes[mode_i++];
+ prefer_partial_vectors_p = param_vect_bb_prefer_partial_vectors;
if (dump_enabled_p ())
dump_printf_loc (MSG_NOTE, vect_location,
"***** Re-trying analysis with vector mode %s\n",
@@ -12203,7 +12242,21 @@ vectorizable_slp_permutation_1 (vec_info *vinfo,
gimple_stmt_iterator *gsi,
unpack_factor = 1;
}
unsigned olanes = unpack_factor * ncopies * SLP_TREE_LANES (node);
- gcc_assert (repeating_p || multiple_p (olanes, nunits));
+
+ /* With fully-predicated BB-SLP, an external node's number of lanes can be
+ incompatible with the chosen vector width (e.g., lane packs of 3 with a
+ natural 2-lane vector type). */
+ if (!repeating_p && !multiple_p (olanes, nunits))
+ {
+ if (dump_p)
+ dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
+ "unsupported permutation %p: vector type %T,"
+ " nunits=" HOST_WIDE_INT_PRINT_UNSIGNED
+ " ncopies=%" PRIu64 ", lanes=%u and unpack=%u\n",
+ (void *) node, vectype, estimated_poly_value (nunits),
+ ncopies, SLP_TREE_LANES (node), unpack_factor);
+ return -1;
+ }
/* Compute the { { SLP operand, vector index}, lane } permutation sequence
from the { SLP operand, scalar lane } permutation as recorded in the
@@ -12880,8 +12933,21 @@ vectorize_slp_instance_root_stmt (vec_info *vinfo,
slp_tree node, slp_instance i
tree root_lhs = gimple_get_lhs (instance->root_stmts[0]->stmt);
if (!useless_type_conversion_p (TREE_TYPE (root_lhs),
TREE_TYPE (new_def)))
- new_def = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (root_lhs),
- new_def);
+ {
+ tree vectype = TREE_TYPE (root_lhs);
+ poly_uint64 new_def_nunits
+ = TYPE_VECTOR_SUBPARTS (TREE_TYPE (new_def));
+ if (known_eq (TYPE_VECTOR_SUBPARTS (vectype), new_def_nunits))
+ {
+ new_def
+ = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (root_lhs), new_def);
+ }
+ else
+ {
+ new_def = build3 (BIT_FIELD_REF, vectype, new_def,
+ TYPE_SIZE (vectype), bitsize_zero_node);
+ }
+ }
}
else
{
diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index 88e3d7e4ae8..b3aa81eb426 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -13731,9 +13731,11 @@ get_related_vectype_for_scalar_type (machine_mode
prevailing_mode,
/* Function get_vectype_for_scalar_type.
Returns the vector type corresponding to SCALAR_TYPE as supported
- by the target. If GROUP_SIZE is nonzero and we're performing BB
- vectorization, make sure that the number of elements in the vector
- is no bigger than GROUP_SIZE. */
+ by the target, or NULL_TREE if none. If GROUP_SIZE is nonzero and we're
+ performing BB vectorization, ensure that the number of subparts in the
+ returned type is no bigger than GROUP_SIZE, or no smaller than GROUP_SIZE if
+ a vector mask or length can be used to limit the number of lanes loaded and
+ stored. */
tree
get_vectype_for_scalar_type (vec_info *vinfo, tree scalar_type,
@@ -13743,7 +13745,8 @@ get_vectype_for_scalar_type (vec_info *vinfo, tree
scalar_type,
constructed the SLP tree; the only valid uses of zero GROUP_SIZEs
are tentative requests during things like early data reference
analysis and pattern recognition. */
- if (is_a <bb_vec_info> (vinfo))
+ bb_vec_info bb_vinfo = dyn_cast<bb_vec_info> (vinfo);
+ if (bb_vinfo)
gcc_assert (vinfo->slp_instances.is_empty () || group_size != 0);
else
group_size = 0;
@@ -13758,11 +13761,19 @@ get_vectype_for_scalar_type (vec_info *vinfo, tree
scalar_type,
if (vectype)
vinfo->used_vector_modes.add (TYPE_MODE (vectype));
- /* If the natural choice of vector type doesn't satisfy GROUP_SIZE,
- try again with an explicit number of elements. */
- if (vectype
- && group_size
- && maybe_ge (TYPE_VECTOR_SUBPARTS (vectype), group_size))
+ if (!vectype || !group_size)
+ return vectype;
+
+ /* The natural choice of vector type satisfies GROUP_SIZE if it can be used
to
+ store the whole group without a mask or length limit (known_eq) or if it
+ can be used to carve the group into pieces (known_lt). */
+ const poly_uint64 natural_nelts = TYPE_VECTOR_SUBPARTS (vectype);
+ if (known_le (natural_nelts, group_size))
+ return vectype;
+
+ /* We might be able to use a partial vector to handle a GROUP_SIZE that is
not
+ satisfied by the natural choice of vector type. */
+ if (!bb_vinfo->prefer_partial_vectors_p)
{
/* Start with the biggest number of units that fits within
GROUP_SIZE and halve it until we find a valid vector type.
@@ -13784,8 +13795,39 @@ get_vectype_for_scalar_type (vec_info *vinfo, tree
scalar_type,
nunits /= 2;
}
while (nunits > 1 && !vectype);
+
+ return vectype;
+ }
+
+ /* Interoperability between modes requires one to be a constant multiple of
+ the other, so do not try to substitute a narrower fixed-length vector type
+ for a variable-length vector type. Do not try to minimize the number of
+ elements in a variable-length type either because it can increase the size
+ of vector constants (e.g., if QImode values are stored in HImode). */
+ if (!natural_nelts.is_constant ())
+ {
+ bb_vinfo->maybe_chose_partial_vector_p = true;
+ return vectype;
}
+ /* Try to minimize the number of subparts in the partial vector type. Start
+ with the smallest number of units that contains GROUP_SIZE and double it
+ until we find a valid vector type. */
+ unsigned int nunits = 1 << ceil_log2 (group_size);
+ do
+ {
+ vectype = get_related_vectype_for_scalar_type (vinfo->vector_mode,
+ scalar_type, nunits);
+ nunits *= 2;
+ }
+ while (known_le (nunits, natural_nelts) && !vectype);
+
+ /* We should have rediscovered the natural vector type if nothing else. */
+ gcc_assert (vectype != NULL);
+
+ if (maybe_gt (TYPE_VECTOR_SUBPARTS (vectype), group_size))
+ bb_vinfo->maybe_chose_partial_vector_p = true;
+
return vectype;
}
@@ -13805,10 +13847,10 @@ get_vectype_for_scalar_type (vec_info *vinfo, tree
scalar_type, slp_tree node)
/* Function get_mask_type_for_scalar_type.
Returns the mask type corresponding to a result of comparison
- of vectors of specified SCALAR_TYPE as supported by target.
- If GROUP_SIZE is nonzero and we're performing BB vectorization,
- make sure that the number of elements in the vector is no bigger
- than GROUP_SIZE. */
+ of vectors of specified SCALAR_TYPE as supported by target or NULL_TREE if
+ none. If GROUP_SIZE is nonzero and we're performing BB vectorization,
ensure
+ that the returned mask type is suitable for use with the vector type that
+ would be chosen by get_vectype_for_scalar_type. */
tree
get_mask_type_for_scalar_type (vec_info *vinfo, tree scalar_type,
@@ -14784,9 +14826,10 @@ vect_gen_while_not (gimple_seq *seq, tree mask_type,
tree start_index,
/* Try to compute the vector types required to vectorize STMT_INFO,
returning true on success and false if vectorization isn't possible.
- If GROUP_SIZE is nonzero and we're performing BB vectorization,
- take sure that the number of elements in the vectors is no bigger
- than GROUP_SIZE.
+ If GROUP_SIZE is nonzero and we're performing BB vectorization, ensure that
+ the number of subparts in *STMT_VECTYPE_OUT is no bigger than GROUP_SIZE, or
+ no smaller than GROUP_SIZE if a vector mask or length can be used to limit
+ the number of lanes loaded and stored.
On success:
diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h
index f585305249e..610d2373044 100644
--- a/gcc/tree-vectorizer.h
+++ b/gcc/tree-vectorizer.h
@@ -1471,10 +1471,13 @@ struct slp_root
typedef class _bb_vec_info : public vec_info
{
public:
- _bb_vec_info (vec<basic_block> bbs, vec_info_shared *);
+ _bb_vec_info (vec<basic_block> bbs, vec_info_shared *,
+ bool prefer_partial_vectors_p);
~_bb_vec_info ();
vec<slp_root> roots;
+ const bool prefer_partial_vectors_p;
+ bool maybe_chose_partial_vector_p;
} *bb_vec_info;
#define BB_VINFO_BBS(B) (B)->bbs
--
2.43.0