Saturate reuse-volume multiplications
Prevents wrap-around in reuse-volume calculations for more accurate prefetching.
This commit introduces saturating multiplication to the reuse-volume calculations within the loop-prefetch optimization pass. This prevents the multiplication results from wrapping around to zero when they exceed the maximum value of unsigned integers. By capping these estimates at UINT_MAX, the accuracy of prefetch and non-temporal store decisions is improved, leading to more effective memory access optimization.
In Details
This change in tree-ssa-loop-prefetch.cc introduces a saturating_mul function and uses it within volume_of_dist_vector and determine_loop_nest_reuse. This addresses PR tree-optimization/128232 by preventing the reuse-volume estimates from wrapping to zero when their values exceed UINT_MAX. This ensures that the prefetching heuristics do not make incorrect decisions based on artificially low or zero reuse volumes, particularly for large loops or memory access patterns.
- loop-prefetch
- An optimization pass that inserts prefetch instructions into loops to load data into caches before it is actually needed, reducing memory latency.
- reuse-volume
- A metric used in loop optimization to estimate how many times data within a loop's working set is likely to be reused.
- saturating multiplication
- A multiplication operation that, instead of wrapping around on overflow, clamps the result to the maximum representable value for the given integer type.
- UINT_MAX
- The maximum value representable by an unsigned integer type.
- non-temporal store
- A memory store operation that hints to the hardware not to cache the written data, useful for streaming data that won't be read again soon.