GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
gimple-fold

gimple-fold: Let callers say whether comparisons short-circuit

Improves comparison folding by allowing callers to specify short-circuiting behavior, ensuring correct trapping semantics.

This commit enhances the gimple-fold pass by allowing callers to explicitly indicate whether comparisons should short-circuit. This is crucial for maintaining correct trapping semantics, especially with floating-point NaNs. The change modifies combine_comparisons to accept a comparison code argument, enabling accurate behavior for different contexts like reassoc, if-conversion, and predicate analysis, preventing incorrect loss or addition of exceptions.

In Details

The gimple-fold component, specifically combine_comparisons, now accepts a CODE argument to distinguish between different evaluation semantics of logical AND/OR expressions. Callers must now specify whether they are using TRUTH_ANDIF_EXPR (short-circuiting, e.g., in ifcombine or predicate analysis) or TRUTH_AND_EXPR (both operands evaluated, e.g., in reassoc or if-conversion). This ensures that trapping semantics, particularly for NaNs in floating-point comparisons, are preserved correctly by accurately reflecting whether the second operand is actually evaluated.

For Context
GIMPLE
GCC's Internal Modeled Expression Representation, a three-address intermediate representation used for optimizations.
gimple-fold
A GCC optimization pass that simplifies GIMPLE expressions.
short-circuiting
A behavior in logical operations where the second operand is not evaluated if the result can be determined from the first operand alone (e.g., false && ... is always false).
TRUTH_ANDIF_EXPR
A GIMPLE expression representing a logical AND where the second operand is conditionally evaluated.
TRUTH_AND_EXPR
A GIMPLE expression representing a logical AND where both operands are always evaluated.
trapping
In floating-point arithmetic, a mechanism to signal exceptional conditions like division by zero or invalid operations (e.g., involving NaN).
NaN
Not a Number, a special floating-point value indicating an undefined or unrepresentable result.
reassoc
The 'reassociate' optimization pass in GCC, which rearranges associative operations to improve performance or enable other optimizations.
Filed Under: optimizationgimplefloating-point