match.pd: Simplify promoted saturating arithmetic operations
Optimizes saturating addition and subtraction operations on promoted types, reducing instruction count.
This change simplifies specific patterns of promoted saturating addition and subtraction operations in the match.pd system. It rewrites operations involving intermediate wide types and clamping into more direct, narrower forms. This reduces the number of instructions generated, especially for vector types, leading to improved performance on targets like AArch64.
In Details
In match.pd, integer promotions and explicit vector conversions could lead to complex sequences for narrow saturating operations, involving wide intermediate types, clamping, and truncation. This patch introduces new simplification rules to directly map patterns like (type) MAX ((wide_type) A - (wide_type) B, 0) to A - MIN (A, B), and (type) MIN ((wide_type) A + (wide_type) B, MAX) to A + MIN (~A, B). This requires defining intermediate types capable of holding the un-overflowed result and ensuring target support for the narrow operations. For vector types, this can significantly redu…
- saturating arithmetic
- Arithmetic operations where the result is clamped to the maximum or minimum value representable by the data type if it exceeds those bounds, rather than overflowing or underflowing.
- promoted types
- In C and C++, when an operation involves operands of different arithmetic types, they may be implicitly converted to a common type, often a wider type, before the operation is performed. This is known as integer promotion or usual arithmetic conversions.
- narrow operation
- An arithmetic operation performed on data types that are smaller than the native word size of the processor, or smaller than the intermediate type used during calculations.
- match.pd
- A system within GCC used for defining instruction matching and generation patterns. It allows the compiler to select specific machine instructions based on the structure of the intermediate representation (RTL).
- AArch64
- The 64-bit ARM architecture, commonly used in mobile devices and increasingly in servers and laptops.
- SIMD
- Single Instruction, Multiple Data. A type of parallel processing where a single instruction operates on multiple data points simultaneously, often used for graphics and multimedia processing. SSE and NEON are examples of SIMD instruction set extensions.