GCC middle-end recognizes floating-point dot product
GCC's middle-end now recognizes and can vectorize floating-point dot product operations, leveraging target-specific instructions.
This patch extends GCC’s middle-end to recognize floating-point dot product expressions, similar to how it handles integer dot products. It allows the vectorizer to utilize target-specific instructions for widening dot products where inputs are converted to a wider type before multiplication and accumulation. This is crucial for performance in numerical computations, provided the target architecture supports such operations and the calculation allows reassociation.
In Details
This commit enables recognition of widening floating-point dot products by extending the DOT_PROD_EXPR pattern in GCC's middle-end. It reuses the sdot_prod optab but removes its integer-only mode restriction. The key differentiator from integer dot products is that floating-point conversions must happen *before* multiplication to be recognized. Specifically, it looks for patterns where two narrower floating-point inputs are converted to a wider type, then multiplied, and the results accumulated in the wider type. This contrasts with patterns where the product is rounded to the narrower ty…
- middle-end
- The part of a compiler that sits between the front-end (which parses source code) and the back-end (which generates machine code). It performs optimizations and transformations on an intermediate representation of the code.
- vectorizer
- A compiler optimization component that transforms loops to execute operations in parallel on multiple data elements simultaneously, using SIMD (Single Instruction, Multiple Data) instructions.
- DOT_PROD_EXPR
- An internal representation or pattern within GCC's intermediate language (Tree) that signifies a dot product operation, typically a sum of element-wise products.
- widening dot product
- A dot product operation where the input elements are first converted to a wider data type before multiplication and accumulation. This helps maintain precision in numerical computations.
- optab
- Short for 'operation table'. A table within GCC's backend that maps generic operations (like multiplication, addition) to specific machine instructions for a given target architecture.
- reassociation
- The property of an operation that allows its operands to be grouped differently without changing the result. For example, (a + b) + c is mathematically equivalent to a + (b + c). Floating-point arithmetic is not always strictly associative due to rounding errors.
- _Float16
- A half-precision floating-point type, typically 16 bits. It offers less precision and range than standard single-precision (float) or double-precision (double) types.