ranger: walk a constant array's initializer by index
VRP pass now walks array initializers by index for constant loads, improving analysis accuracy for missing elements.
The GCC ranger (Value Range Propagation) pass now walks constant array initializers by index when processing loads from arrays with unknown indices. Previously, it would union all initializer elements regardless of their position, potentially leading to inaccuracies if elements were missing. This change improves the analysis by correctly identifying missing elements and adds new tests for this behavior.
In Details
In gimple-range-fold.cc, the vrp-cstload-limit parameter caps the size of initializers processed for constant loads. This commit refactors ctor_ref_range::accumulate_range_from_array_ref to iterate through the initializer by index instead of merely unioning elements. This allows for more precise range analysis, especially when the accessed index implies missing elements in the initializer, which will be leveraged by subsequent patches.
- ranger
- A GCC pass that performs Value Range Propagation (VRP). It analyzes the possible range of values for variables and expressions to enable optimizations.
- initializer
- The set of values provided when an array or other variable is declared. For example,
int arr[3] = {1, 2, 3};. - constant load
- An operation that reads data from memory where the memory address is known at compile time.
- GIMPLE
- GCC's internal representation of code after initial parsing and before optimization. It's a three-address-like intermediate representation.
- vrp-cstload-limit
- A GCC compiler parameter that limits the number of elements processed from an initializer during constant load analysis in the VRP pass.