forwprop: Optimize `match_long_mul_phi` by reordering conditional checks.
forwprop: Reorders checks in `match_long_mul_phi` to prioritize cheaper conditions, improving performance.
In tree-ssa-forwprop.cc, the match_long_mul_phi function has been updated to reorder its conditional checks. The check for the shift amount equality (shift_amt == halfwidth) is now performed before the more computationally expensive gimple_mul_low_sum and gimple_mul_cross_sum calls. This optimization can lead to faster compilation by avoiding unnecessary function calls when the shift amount condition is not met.
In Details
The match_long_mul_phi function in tree-ssa-forwprop.cc attempts to match patterns related to long multiplication within the forward propagation pass. The original code first called gimple_mul_low_sum and then checked if shift_amt == halfwidth. This commit reverses that order, performing the cheaper shift_amt == halfwidth check first. This is a standard optimization technique to short-circuit evaluation and avoid expensive computations when a simpler condition fails.
- forwprop
- Abbreviation for 'forward propagation', an optimization technique in compilers where values or properties are propagated forward through the program's control flow graph.
- tree-ssa-forwprop.cc
- A GCC source file containing the implementation of the forward propagation optimization pass, operating on the SSA (Static Single Assignment) form of the code.
- match_long_mul_phi
- A function likely responsible for identifying and optimizing patterns involving long multiplication and PHI nodes within the forward propagation pass.
- gimple_mul_low_sum
- A GCC internal function that checks if a given GIMPLE statement represents a low-order sum of a multiplication.
- PHI node
- In Static Single Assignment (SSA) form, a PHI node is an operation that merges values from different control flow paths. It effectively says 'if we came from path A, the value is X; if we came from path B, the value is Y'.