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

Compare elimination pass no longer limits flag uses

The compare-elim pass in GCC now tracks all flag uses, improving code generation for conditional operations on ARM.

The compare-elim pass in GCC has been enhanced to remove the artificial limit on tracking flag uses. Previously, after three uses, the pass would incorrectly assume uses were unknown, leading to suboptimal code generation for conditional moves and select instructions on architectures like ARM and AArch64. By tracking all uses, this change enables better elimination of compares, resulting in smaller code size.

In Details

The compare-elim pass in GCC optimizes conditional code by eliminating redundant comparisons. It tracks the uses of flags set by comparison instructions to decide if a comparison can be removed. The MAX_CMP_USE limit was an arbitrary cutoff that caused incorrect handling of common instruction sequences, such as an and; cmp #0 followed by multiple conditional selects. This commit removes the limit and uses auto_vec to efficiently store uses, improving code generation for patterns previously mishandled.

For Context
compare-elim
A GCC compiler optimization pass that removes redundant conditional comparison instructions by analyzing how comparison flags are used.
flag uses
In compiler optimization, refers to how the status flags (like zero, carry, overflow) set by an instruction (e.g., a comparison) are subsequently used by other instructions (e.g., conditional branches or moves).
conditional select
An instruction that chooses between two source operands based on the state of condition flags, effectively performing a conditional assignment without a branch.
auto_vec
A GCC internal data structure that provides a dynamically sized vector, similar to C++'s std::vector, used here to store instruction uses without requiring heap allocation for common cases.
Filed Under: optimizationarm