Allow signed types in average vectorization fallback
GCC's vectorization now supports signed types for average calculations, expanding optimization possibilities.
The vectorizer’s fallback mechanism for average calculations previously only supported unsigned types. This change removes that restriction, allowing signed integer types to be vectorized. The core logic remains the same, as arithmetic right shifts and subsequent adjustments work identically for both signed and unsigned types. The implementation now uses target_supports_op_p for better portability in checking operation support.
In Details
The vect_recog_average_pattern in GCC's tree-vectorizer, when a direct SIMD instruction for average is not available, falls back to a sequence of arithmetic operations. This fallback previously enforced an unsigned type constraint. This patch removes that constraint, enabling the vectorized average pattern to recognize and optimize code using signed integer types. It also switches the check for operation support from optab_for_tree_code to target_supports_op_p for improved target-specific checks.
- vectorization
- A compiler optimization that transforms code to operate on multiple data elements simultaneously using wide processor registers (SIMD instructions).
- SIMD
- Single Instruction, Multiple Data. A class of parallel computer architectures that perform the same operation on multiple data points concurrently.
- fallback mechanism
- A secondary implementation or strategy used when the primary or preferred method is not available or applicable.
- tree-vectorizer
- The component within GCC responsible for identifying and applying vectorization optimizations at the GCC Intermediate Representation (tree) level.
- target_supports_op_p
- A GCC function used to query whether a specific arithmetic or logical operation is supported by the target architecture.