Decide vectorization factor (VF) independently of externals/constants.
Improves vectorization by basing the vectorization factor on assigned types, not external/constant node properties.
This commit refactors the SLP vectorizer to determine the vectorization factor (VF) based on the assigned SLP_TREE_VECTYPE rather than relying on max_nunits in the SLP graph, which previously included external and constant nodes. These external/constant nodes could artificially inflate the VF, leading to missed optimizations. By decoupling VF calculation from these nodes, the vectorizer can now select a more appropriate VF, resolving issues like ICEs in vect_get_num_copies and improving vectorization efficiency, particularly for code involving invariant data.
In Details
This commit modifies the SLP vectorizer's logic for choosing the vectorization factor (VF). Previously, vect_update_slp_vf_for_node used max_nunits which considered external and constant nodes, potentially leading to a suboptimal VF. The change makes the VF decision solely based on SLP_TREE_VECTYPE. This requires adjustments to functions like vect_get_num_copies to handle invariant vectors correctly, introducing vect_get_num_copies_for_invariant which uses ceil_div. The fundamental issue addressed is that vectorizable_* routines might receive invariant vectors with excess lanes,…
- VF
- Vectorization Factor, indicating how many data elements are processed in parallel by a single SIMD instruction.
- SLP_TREE_VECTYPE
- A field within the SLP tree structure that stores the determined vector type for a given operation.
- invariant nodes
- In the context of vectorization, nodes representing values that do not change within the loop or vectorized region.
- ICE
- Internal Compiler Error, a crash within the compiler itself, often due to unexpected program states or logic bugs.
- ceil_div
- Ceiling division, which rounds the result of a division up to the nearest whole number.