Fold vector unpack operations over polynomial constants.
Compiler optimizes vector unpack operations on variable-length constants for better constant folding.
The GCC middle-end now folds VEC_UNPACK_LO_EXPR and VEC_UNPACK_HI_EXPR when operating on suitable variable-length vector constants. This enhancement extends existing folding capabilities for fixed-length vectors to variable-length ones, allowing more constants to be resolved before RTL expansion and potentially eliminating unnecessary instructions.
In Details
This patch extends fold-const.cc's const_unop to handle VEC_UNPACK_LO_EXPR and VEC_UNPACK_HI_EXPR on VECTOR_CSTs with variable vector lengths (VLA). The folding occurs when the input VLA has twice the elements of the output and the selected half forms a valid VECTOR_CST. This is particularly useful for known iteration loops where folding can eliminate unrolled masks, unifying VLA and VLS paths.
- VEC_UNPACK_LO_EXPR
- An expression in GCC's intermediate representation (RTL or GIMPLE) that extracts the lower half of a vector.
- VEC_UNPACK_HI_EXPR
- An expression in GCC's intermediate representation that extracts the upper half of a vector.
- VECTOR_CST
- A constant value represented as a vector within the compiler's intermediate representation.
- VLA
- Variable Vector Length. Refers to vector types whose size is determined at runtime or is otherwise not fixed at compile time.
- RTL expansion
- The process in GCC where higher-level intermediate representations (like GIMPLE) are translated into Register Transfer Language (RTL), which is closer to machine code.