Landing: 435528a4133b
Project / Subsystem
gcc / expmed
Date
2026-08-23
Author
Dominic P
Commit
435528a4133bf61c4c25af0dca0ba2cd94facf79
Source
github
Perf win
Yes
Breaking
No
All attributes
- project
- gcc
- subsystem
- expmed
- patch_id
- —
- commit_hash
- 435528a4133bf61c4c25af0dca0ba2cd94facf79
- source_type
- github
- headline
- Reset division constant cache between functions
- tldr
- Fixes a bug where division/modulo optimization state incorrectly carried over between functions.
- author
- Dominic P
- outcome
- committed
- performance_win
- true
- breaking_change
- false
- series_id
- gcc:expmed: do not carry last_div_const between functions
- series_parts
- []
- tags
-
- • optimization
- • compiler internals
- • code generation
- discussion_id_link
- —
- bugzilla_pr
- —
- date
- 2026-08-23T00:00:00.000Z
The expand_divmod function maintained a cache of the constant divisor from the last division it processed, intending to optimize subsequent modulo operations with the same constant. However, this cache was a function-scope static variable that was never reset, causing its state to persist across function boundaries. This commit resets the cache at the start of each function expansion, ensuring that a function’s optimization is determined solely by its own code and not influenced by previously compiled functions in the same translation unit. This change makes the heuristic deterministic and can lead to code size improvements.