GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
ccmp

ccmp: Reject chains of pure booleans without explicit comparison

Prevents incorrect code generation for all-boolean logical operations on AArch64.

This commit improves the ccmp (conditional compare) expander by rejecting chains composed entirely of boolean values when no explicit comparison is present. Previously, the expander could misinterpret such chains, leading to incorrect instruction generation, as seen with return x || y; on AArch64. The change ensures that candidate recognition reports whether an explicit comparison was found, and rejects candidates without one, thus preventing faulty code emission and improving the robustness of logical operation expansion.

In Details

The ccmp expansion logic in GCC's middle-end, specifically within ccmp.cc and tree-outof-ssa.cc, incorrectly handled logical operations composed solely of boolean variables without an explicit comparison. It treated plain booleans as comparisons against zero, leading to unnecessary ccmp instructions and suboptimal code. This patch enhances ccmp_candidate_p to track whether an explicit comparison is part of the candidate expression. If a candidate consists only of boolean variables and lacks an explicit comparison, it's now rejected, forcing fallback to simpler operations like orr.…

For Context
ccmp
Conditional compare instruction, primarily used on architectures like AArch64 to perform comparisons and set flags based on conditions.
boolean
A data type that can hold one of two values, typically true or false, often represented as 0 or 1.
TER fallback
A fallback mechanism in GCC's expression expansion that handles cases not directly supported by specialized instruction patterns.
SSA
Static Single Assignment form, an intermediate representation used by GCC that simplifies many optimization passes.
AArch64
The 64-bit ARM architecture instruction set.
Filed Under: AArch64gccbugfixlogical operations