Fix bad linearization in reassoc pass for RDIV_EXPR.
Reassoc optimization pass now correctly handles non-associative RDIV_EXPR, preventing incorrect linearization.
This commit fixes a bug in the reassoc optimization pass where the linearize_expr function incorrectly assumed RDIV_EXPR was associative. When undistribute_ops_list encountered an outer RDIV_EXPR, it would proceed to linearize the right-hand side, leading to incorrect code. The fix ensures that linearize_expr_tree only sets binrhsisreassoc to true if the expression is actually associative, thus preventing erroneous linearization of non-associative division expressions.
In Details
The linearize_expr_tree function in gcc/tree-ssa-reassoc.cc is modified to correctly handle RDIV_EXPR. Previously, undistribute_ops_list would call linearize_expr with binrhsisreassoc set to true even for RDIV_EXPR, which is not associative. The fix adds a check is_associative before setting binrhsisreassoc to true, ensuring that the linearization logic is only applied to truly associative operations. This resolves PR tree-optimization/128089.
- tree-optimization
- A phase in the GCC compilation pipeline where optimizations are performed on an intermediate representation called GENERIC or GIMPLE (tree-based representations).
- reassoc pass
- A GCC optimization pass that attempts to reassociate arithmetic operations to enable further optimizations or improve instruction scheduling.
- RDIV_EXPR
- A GCC internal tree node representing a reverse division operation.
- linearize_expr
- A GCC internal function that transforms expressions into a linear sequence of operations, typically for SSA (Static Single Assignment) form or other optimization passes.
- associative operation
- An operation where the grouping of operands does not affect the result, e.g., (a + b) + c = a + (b + c).