LTO: Fix cache partitioning to handle zero min partition size
Prevents division-by-zero errors in LTO cache partitioning when minimum partition size is zero.
The Link-Time Optimization (LTO) cache partitioning feature in GCC previously asserted that both minimum and maximum partition sizes must be non-zero. This commit relaxes that restriction by handling a min_partition_size of 0. Instead of asserting, it clamps the value to 1, preventing potential division-by-zero errors and allowing for reasonable default behavior in such cases. A new test case is added to verify this fix.
In Details
The lto-partition.cc code asserts min_partition_size and max_partition_size are non-zero to avoid division by zero later. This commit modifies the logic to handle min_partition_size = 0 by clamping it to 1, resolving an issue where this assertion was overly strict. This prevents potential crashes and ensures the partitioning logic proceeds correctly.
- LTO
- Link-Time Optimization is a compiler optimization technique that allows the compiler to optimize code across different translation units during the linking stage, rather than just within individual object files.
- cache partitioning
- A technique used in LTO to divide the intermediate representation of the program into smaller chunks or partitions for more efficient processing and memory management.
- PR lto/125257
- A Public Relations (bug report) identifier for an issue filed in the GCC bug tracking system related to LTO.