GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
gcc

Add contains_zero_p predicate to value range hierarchy.

Introduces `contains_zero_p` to value range types for clearer zero checks.

This commit introduces a new pure virtual function, contains_zero_p(), to the GCC compiler’s value range analysis hierarchy. This predicate clearly indicates whether a given range includes the value zero. It serves as a more explicit replacement for the previously used nonzero_p() function, which had ambiguous behavior. The new function is implemented for various range types, improving the clarity and precision of range analysis.

In Details

A new pure virtual function, contains_zero_p(), has been added to the vrange hierarchy, including unsupported_range, irange, prange, frange, and Value_Range. This predicate returns true if the range encompasses zero. It's designed to replace the ambiguous nonzero_p() function, providing a clearer and more direct check for the presence of zero within a range, particularly useful for optimizations that depend on whether a value can be zero.

For Context
vrange
A base class or concept in GCC's value-range analysis representing a range of possible values for a variable or expression. Specific derived classes handle different types of ranges (e.g., integer, floating-point).
contains_zero_p
A predicate function that checks if a given range of values includes zero. This provides a clearer and more direct check for the presence of zero within a range compared to the removed nonzero_p function.
nonzero_p
A predicate function that previously indicated whether a given range of values excluded zero. Its behavior was sometimes ambiguous and has been superseded by more precise checks.
pure virtual function
In object-oriented programming, a virtual function that is declared but not implemented in the base class. Derived classes must provide an implementation for pure virtual functions.
Filed Under: optimizationrefactor