Optimize product of quotients to a single division.
Replaces two divisions with a multiply and one division, improving performance on targets where division is expensive.
This commit introduces an optimization rule to match.pd that transforms the product of two quotients, (A / B) * (C / D), into a single division: (A * C) / (B * D). This is beneficial on architectures where division is significantly slower than multiplication. The new rule excludes infinities and NaNs and requires non-trapping math to ensure correctness. New test cases are added to gcc.dg/tree-ssa/ to verify this transformation.
In Details
A new simplification rule is added to match.pd for the pattern (A / B) * (C / D), transforming it into (A * C) / (B * D). This replaces two divisions with a multiply and one division. The rule is guarded by checks for infinities, NaNs, and requires non-trapping math. It also ensures quotients are singly used to avoid conflicts with other optimizations like shared reciprocals. Tests are added for aarch64-none-linux-gnu.
- match.pd
- Likely a pattern-matching database or file within GCC's middle-end that defines algebraic simplifications and optimizations for tree structures.
- quotient
- The result of a division operation.
- non-trapping math
- Floating-point operations that do not raise exceptions for conditions like division by zero or overflow. This allows for more aggressive optimizations where certain exceptional cases can be safely ignored or handled differently.
- NaN
- Not a Number. A special floating-point value used to represent undefined or unrepresentable results, such as the result of 0/0.