Fold constant conditional selects for integral types.
Optimize conditional selects of the form (x == CST) ? x : CST to CST.
This change allows the compiler to fold conditional select expressions where the condition compares a variable against a constant. Specifically, it handles cases like (x == CST) ? x : CST and (x != CST) ? CST : x, simplifying them to CST for integral scalar and vector types. This optimization catches patterns previously converted from bitwise masks, including some ARM MVE specific forms, leading to more efficient code.
In Details
This commit enhances the tree-ssa-instr-reduce pass by introducing a new pattern in match.pd to fold conditional selects involving constants. It targets expressions like (x == C) ? x : C and (x != C) ? C : x for integral types. The folding transforms these into a constant C, recognizing that if x equals C, the result is C, and if x does not equal C, the other branch yields C anyway. This addresses specific ARM MVE predicate-to-vector mask conversions.
- conditional select
- An expression that chooses between two values based on a condition. In GCC's Gimple intermediate representation, this is often represented by
GIMPLE_COND_EXPRor similar constructs. - Integral types
- Data types that represent whole numbers, such as integers (
int,long) and their unsigned counterparts. This excludes floating-point types. - ARM MVE
- ARM's Mạnh Vector Extension, a SIMD (Single Instruction, Multiple Data) instruction set extension for Cortex-M processors designed for digital signal processing and general-purpose computing tasks.
- Predicate
- In SIMD/vector processing, a mechanism often used to control which lanes of a vector operation are active. A predicate can be a bitmask or a set of boolean flags.