GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
reassoc Performance Win

Reassociation uses target policy for conditional compare ordering

Reassociation pass now uses target-specific policies to order conditional compares, improving code generation for architectures like AArch64.

The reassociation pass in GCC has been updated to use a target-specific policy hook for ordering conditional comparisons. This addresses issues where generic reassociation might not respect target constraints, leading to suboptimal code. The new hook allows targets like AArch64 to specify preferences, such as preferring constants or floating-point zeros in comparisons, resulting in more efficient instruction selection. The generic pass also ensures that trapping comparisons are handled correctly.

In Details

The reassoc pass now uses a ccmp_first_preference target hook to order conditional comparisons, addressing limitations in generic operand rank-based ordering. This hook classifies comparisons into unsupported, neutral, preferred, and required head categories. AArch64 implements this to prioritize comparisons involving constants or floating-point zeros, and to handle forwarded trapping comparisons correctly, improving the generated instruction sequence over standard reassociation.

For Context
Reassociation
A compiler optimization pass that restructures arithmetic expressions to improve performance or enable other optimizations. It rearranges the order of operations, such as changing (a + b) + c to a + (b + c).
Conditional Compare (CCMP)
An instruction found on architectures like AArch64 that performs a comparison and conditionally sets a result register based on the comparison outcome. It's often used in sequences to implement complex conditional logic efficiently.
Target Policy Hook
A mechanism in GCC that allows target-specific code to influence the behavior of generic compiler passes. This enables the compiler to generate optimized code tailored to the features and constraints of a particular processor architecture.
Filed Under: optimizationreassociationaarch64instruction selection