Constant divisions not converted to multiplications
Project / Subsystem
gcc / gcc
Date
2026-05-21
Proposer
Undisclosed <1007140@aruba.it>
Source type
public_inbox
Consensus
Proposed
Sentiment
—/10
Technical tradeoffs
- • Performance gain from using multiplication instead of division.
- • Potential loss of precision in floating-point calculations when using reciprocal math.
- • Default behavior prioritizes precision over performance.
All attributes
- project
- gcc
- subsystem
- gcc
- patch_id
- —
- discussion_id
- 1BDAC475-C1FD-457D-8EB3-C65F7B40ED88@aruba.it
- source_type
- public_inbox
- title
- Constant divisions not converted to multiplications
- headline
- Constant divisions are not converted to multiplications with -O3
- tldr
- GCC with -O3 doesn't always turn divisions by constants into multiplications; -freciprocal-math enables this optimization at the cost of precision.
- proposer
- Undisclosed <1007140@aruba.it>
- consensus
- Proposed
- outcome
- proposed
- sentiment_score
- —
- technical_tradeoffs
-
- • Performance gain from using multiplication instead of division.
- • Potential loss of precision in floating-point calculations when using reciprocal math.
- • Default behavior prioritizes precision over performance.
- series_id
- —
- series_role
- standalone
- series_parts
- []
- tags
-
- • gcc
- • optimization
- • floating-point
- • performance
- • precision
- bugzilla_url
- —
- date
- 2026-05-21T00:00:00.000Z
Constant divisions not converted to multiplications
A user found that GCC 14.2 with optimization level -O3 doesn’t convert divisions by constants into multiplications, leading to slower code. This behavior was confirmed on GCC 16.1.1. The -freciprocal-math option enables this optimization, though it’s off by default due to potential precision loss. Enabling unsafe math optimizations also turns on this optimization.