https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126242
--- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Roger Sayle <[email protected]>: https://gcc.gnu.org/g:d6073a20f86a9012ce1284a752e32ac5ec9e2132 commit r17-2960-gd6073a20f86a9012ce1284a752e32ac5ec9e2132 Author: Roger Sayle <[email protected]> Date: Tue Aug 4 21:03:20 2026 +0100 PR tree-optimization/126242: Check range is defined to avoid ICE. Here's the latest revision of my patch to resolve PR 126242 (and 126325), incorporating Richard Biener's feedback to simplify the logic, eliminating itype_ok and always using calling gimple_match_range_of_expr. This version also resolves PR tree-optimization/126325 introduced/exposed by the same change, checking that when transforming (float)x < C into x < (int)C that (int)C is exactly representable, i.e. that (float)(int)C == C. This patch resolves PR tree-opt/126242, an unanticipated interaction between the two recent (float)i == 1.0 patches to match.pd. The issue is that value range information is getting queried in circumstances (on paths) where we've failed to initialize the range and/or ranger has failed to bound the value. The correction below fixes this in two ways: initialize the range information in more cases, and check that the range has been successfully initialized before using it. The motivation/benefit for the first approach is seen in the example: unsigned char t = x & 63; return (float)t > 100.0; Previously, because unsigned char can be safely represented in a float we'd use the bounds [0,255], and transform this to t > 100. Obviously, there's benefit in using ranger to reduce the range to [0,63], even when the integer type fits the floating point type, allowing the above expression to be simplified even further to false. 2026-08-04 Roger Sayle <[email protected]> Richard Biener <[email protected]> gcc/ChangeLog PR tree-optimization/126242 PR tree-optimization/126325 * match.pd ((FTYPE) N CMP CST): Always attempt to initialize value range information. Check undefined_p before using range bounds. Check that icst_val hasn't overflowed, i.e. that (FTYPE)ICST == CST, before transforming to integer comparison. gcc/testsuite/ChangeLog PR tree-optimization/126242 PR tree-optimization/126325 * gcc.dg/pr126325.c: New test case. * gfortran.dg/pr126242.f90: New reduced test case. * gfortran.dg/pr41928-2.f90: Also compile pr41928.f90 with -Ofast.
