Match folded signed SAT_ADD immediates [PR128948]
Pattern matching for signed saturating add with immediate operands now handles folded overflow checks, improving optimization.
This commit enhances pattern matching in match-sat-alu.pd to correctly recognize folded signed saturating-add operations involving immediate values. A previous change (commit 610ffda1010f) inadvertently caused the signed saturating-add matcher to miss expressions where the XOR sign test for a nonnegative immediate was folded away. New predicates and alternatives have been added to accommodate these folded checks, ensuring that such operations can be optimized effectively.
In Details
In match-sat-alu.pd, new predicates signed_integer_add_nonnegative_imm and signed_integer_sat_add_nonnegative_imm_overflow are introduced. Additionally, signed_integer_sat_add is augmented with new alternatives to handle the folded overflow checks resulting from the removal of the XOR sign test for nonnegative immediates, as caused by commit 610ffda1010f (PR115392). This fix ensures that patterns for signed saturating addition with immediate operands are correctly matched even after such folding optimizations.
- match-sat-alu.pd
- A file containing pattern matching definitions for saturating arithmetic logic unit (ALU) operations, used by the GCC compiler for optimization.
- saturating arithmetic
- Arithmetic operations that clamp the result to a maximum or minimum value if it exceeds the representable range, instead of overflowing or underflowing.
- immediate operand
- A constant value directly embedded within an instruction, rather than being fetched from memory or a register.
- pattern matching
- A compiler technique used to identify specific code structures or sequences that can be replaced by more efficient code or intrinsics.
- folding
- An optimization technique where constant expressions or function calls with constant arguments are evaluated at compile time.