GCC Newspaper
JULY 29, 2026
Date
/
Architectures
Components
Topics
News & Policy
gcc Performance Win

PR tree-optimization/57371: Improved comparison of integers to FP constants.

Enhances optimization for integer-to-floating-point constant comparisons, considering trapping behavior and rounding.

This patch refines the tree-level optimization for comparing integers to floating-point constants, addressing PR57371. It now considers the flag_trapping_math to correctly preserve floating-point exception behavior. The core improvement involves determining if a comparison is unambiguous enough to be converted to a safer integer comparison, carefully handling potential rounding issues inherent in floating-point conversions.

In Details

The match.pd pattern matching component within GCC's tree-SSA optimizer has been updated to improve the optimization of (fptype)ivar != CST expressions, resolving PR tree-optimization/57371. The logic now explicitly checks flag_trapping_math, ensuring that FP_OVERFLOW/FP_INEXACT semantics are preserved when necessary. The primary optimization is to safely transform such comparisons into their integer equivalents by verifying that the target floating-point constant CST can be unambiguously represented by the integer ivar, specifically by checking that (float)(ivar-1) and `(float)(i…

For Context
tree-optimization
An optimization pass in GCC that operates on the compiler's intermediate representation, which is structured as a tree. This forms part of the compiler's optimization pipeline.
PR57371
A Problem Report (PR) identifier in the GCC bug tracking system, indicating a specific issue that has been reported and is being addressed.
trapping math
Floating-point operations that, when encountering exceptional conditions like overflow or inexact results, trigger a CPU trap (an interrupt) to be handled by software. This contrasts with non-trapping math, which typically produces a default result (e.g., infinity, NaN) without interrupting execution.
floating-point constant
A numeric literal that represents a fractional number, stored internally using a format like IEEE 754.
match.pd
A file within GCC that contains pattern definitions used by the tree-based optimizer to recognize and transform specific code structures.
Filed Under: optimizationfloating-pointinteger conversionbugfix