Fix the operands of the complex FMS pattern
Corrects an error in the vectorizer's complex fused multiply-subtract pattern, preventing incorrect results for certain complex arithmetic operations.
This commit fixes a bug in GCC’s vectorizer that was causing incorrect calculations for complex fused multiply-subtract (FMS) operations. A recent change in how operands were returned by vect_validate_multiplication led to the complex FMS pattern incorrectly matching them. This resulted in wrong results for code like c[i] -= x[i] * y[i] when using optimizations like -O2 -ffast-math -march=armv8.3-a. The fix aligns the operand indexing within the complex_fms_pattern::matches function with that of the similar PLUS_MINUS pattern, ensuring correct vectorization and accurate results for complex arithmetic.
In Details
The complex_fms_pattern::matches method in tree-vect-slp-patterns.cc incorrectly processed operands returned by vect_validate_multiplication after a refactoring (r16-4663-gc5fa3d4c88fc4f). This refactoring changed vect_validate_multiplication to return operands in RES_OPS = { L0, L1, R0, R1 }. The complex_fms_pattern::matches function was passing operands in the order (RIGHT_OP, LEFT_OP) but subsequently accessed RES_OPS as if the order was (LEFT_OP, RIGHT_OP), leading to a swap of the complex multiplication's real and imaginary parts. This commit corrects the indices used t…
- vectorizer
- A compiler component that transforms loops or sequences of operations to use SIMD (Single Instruction, Multiple Data) instructions, allowing a single operation to be performed on multiple data elements simultaneously.
- SIMD
- Single Instruction, Multiple Data. A class of parallel computers in Flynn's taxonomy that deploy one instruction upon many data elements simultaneously. Modern CPUs achieve this via vector instructions.
- Fused Multiply-Subtract (FMS)
- An arithmetic operation that computes (a * b) - c or a - (b * c) in a single instruction, often providing higher precision and performance than separate multiply and subtract operations.
- complex arithmetic
- Mathematical operations performed on numbers that have both a real and an imaginary part.
- ARMv8.3-A
- A specific architecture version of the ARM 64-bit instruction set, known for features like cryptographic extensions and improved pointer authentication.
- FCMLA
- Fused Multiply Accumulate for Complex numbers. An ARM NEON instruction that performs complex multiplication and addition/subtraction.