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

Path solver: Compute ranges only at current path position

Fixes a path solver issue by restricting range computations to the current block in the control flow graph.

This commit corrects the path solver’s range computation logic to only consider the current block’s position in the control flow graph. Previously, range queries could occur with contexts from arbitrary blocks, leading to incorrect results when folding statements. The fix ensures that range calculations are confined to the relevant path position, falling back to global ranges otherwise, and adds an assertion to maintain this invariant.

In Details

The gimple-range-path.cc changes restrict path_range_query::internal_range_of_expr to call range_defined_in_block only at the current path position (m_path[m_pos]). This resolves issues where optimizations like match.pd could query ranges with contexts from unrelated blocks, violating the positional invariant. An assertion is added in range_defined_in_block to enforce this invariant, ensuring positional correctness.

For Context
Path Solver
A component within the compiler's optimization passes that analyzes different execution paths (control flow) through a program to determine properties of variables or expressions along those paths.
Control Flow Graph (CFG)
A representation of all execution paths through a function or program. It consists of basic blocks (sequences of code with one entry and one exit) and edges representing possible transfers of control between blocks.
GIMPLE
GCC's internal representation (IR) used for optimization after the initial parsing and before the final machine code generation. It's a three-address code form.
SSA
Static Single Assignment. An intermediate representation property where every variable is assigned a value exactly once. This simplifies many compiler optimizations.
Filed Under: optimizationpath analysiscompiler