Simplify copysign pattern for constants
GCC match.pd simplifies copysign with constant arguments to use a simplified form.
GCC’s pattern matching (match.pd) is updated to simplify copysign operations where one argument is a constant. The pattern (trunc)copysign ((extend)x, CST) can now be reduced to copysign (x, -1.0/1.0), depending on the sign of the constant. This change is accompanied by a new test case for validation.
In Details
This commit introduces a new pattern in match.pd to optimize calls to copysign where the second argument is a constant. The pattern (trunc)copysign ((extend)x, CST) is recognized, and due to copysign's behavior where only the sign of the second argument matters, it's simplified to copysign (x, -1.0/1.0) or copysign (x, 1.0) based on CST's sign. This likely targets tree-SSA or similar middle-end optimizations and is guarded by PR112472.
- match.pd
- A file containing pattern definitions for GCC's pattern matching system, used for tree transformations and optimizations. It describes how to recognize and rewrite specific code structures.
- copysign
- A function that returns a floating-point value with the magnitude of the first argument and the sign of the second argument.
- trunc
- A cast or operation that truncates a value, typically a floating-point number, to a smaller type or representation.
- extend
- A cast or operation that extends a value, typically an integer or floating-point number, to a larger type or representation.
- CST
- Abbreviation for 'constant' in the context of GCC's internal representation. It refers to a constant value used in patterns.
- tree-ssa
- Static Single Assignment form. An intermediate representation used in optimizing compilers like GCC, where each variable is assigned exactly once. It simplifies many analysis and transformation passes.
- PR112472
- Problem Report number 112472. This indicates a bug or issue that has been reported and is being tracked in the GCC bug tracking system.