bitintlower: Avoid merging non-mergeable stmts with plus_minus or lshift [PR128699]
Improves bitint lowering by correctly handling mergeable statements involving arithmetic and shifts.
This commit refactors the bitint lowering process to correctly handle statements involving additions/subtractions (plus_minus) and left shifts (lshift). Previously, the code could incorrectly merge statements that were not mergeable, leading to issues. The changes introduce a more robust analysis of statement chains, ensuring that operations requiring specific states (like carry for addition or limb bits for shifts) are not merged with incompatible operations. This prevents potential errors and improves the correctness of bitint lowering.
In Details
The handle_plus_minus and handle_lshift functions in gimple_lower_bitint require specific state (carry, previous limb bits) and work best with operations expanded in m_upwards_2limb mode. The original merging logic did not adequately account for cases where these operations were combined with non-mergeable outermost operations. This patch replaces the loop body with a lambda for better control flow and introduces recursive analysis to identify and prevent premature merging of chains involving plus_minus or lshift with incompatible operations, ensuring such SSA_NAMEs are correctly…
- bitintlower
- The compiler pass responsible for lowering arbitrary-precision integers (
_BitInt) into machine-representable operations. - SSA_NAME
- Static Single Assignment form name. In SSA form, each variable has only one assignment, and each assignment to a variable creates a new version of that variable, distinguished by a version number.
- stmt
- Statement, a basic unit of computation in the compiler's intermediate representation.
- plus_minus
- Likely refers to expressions involving addition and subtraction operations.
- lshift
- Left shift operation.
- limb
- A 'limb' is a machine word (e.g., 32 or 64 bits) used to represent larger arbitrary-precision numbers.
- m_upwards_2limb
- A mode of operation where two limbs (machine words) are processed at a time, typically from least significant to most significant, used for multi-precision arithmetic.