GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
cselib Performance Win

cselib: Optimize Value Invalidation by Avoiding Repeated discard_useless_locs

This commit optimizes value invalidation in `cselib` by avoiding the repeated discarding of useless locations, improving compile time, especially with RTL chec…

The code was spending significant time repeatedly calling discard_useless_locs in cselib, especially when RTL checking was enabled. To address this, the commit adds a flag to cselib_val to indicate whether every location only references preserved values. It then maintains a list of entries that might have useless locations, allowing remove_useless_values to iterate over this list instead of the entire hash table. This optimization reduces compile time in scenarios with many blocks and entries in cselib_preserved_hash_table.

In Details

In cselib, var-tracking retains invariant values for the whole function by moving them to cselib_preserved_hash_table. The issue was that discard_useless_locs was repeatedly called, examining every location of every entry after each basic block. This commit introduces a bit in cselib_val to track if every location only references preserved values. A list of entries that might have useless locations is maintained, which improves the performance of remove_useless_values by iterating over this list instead of the whole hash table.

For Context

cselib helps the compiler optimize code by tracking relationships between values. After processing each block of code, the compiler invalidates registers and memory locations that are no longer valid. The compiler was spending a lot of time iterating over all tracked values to remove these invalid locations. This commit optimizes this process by only checking values that might contain invalid locations, significantly reducing the amount of work the compiler has to do and improving compilation speed.

Filed Under: cseliboptimizationcompile-timertl