GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
tree-optimization

Restrict power exponent checks to constant integers

Fixes `__builtin_pow` handling by ensuring exponent checks only apply to constant integer exponents.

This commit corrects a miscompilation issue involving __builtin_pow and the undistribution of factors from multiplication chains. Previously, the stmt_is_power_of_op function incorrectly processed non-constant or non-integer exponents in pow calls, leading to truncation and incorrect results. The fix modifies stmt_is_power_of_op to strictly require a constant integer exponent, ensuring that factors are removed from elsewhere in the chain and preventing misinterpretation of mathematical expressions.

In Details

This commit revises stmt_is_power_of_op within tree-ssa-reassoc.cc to enforce that it only identifies power operations with constant integer exponents when undistributing factors. Previously, it would incorrectly process non-constant or floating-point exponents, leading to truncation (e.g., 2.5 to 2) and subsequent incorrect decrements by decrement_power. This caused miscompilations in expressions involving __builtin_pow and multiplication chains. The change ensures that only valid, constant integer exponents are considered for factor removal, preventing these errors and potential…

For Context
undistribute
An optimization step that breaks down a combined operation (like a power) into its constituent parts, often to enable other optimizations like reassociation.
reassociation
An optimization that rearranges the order of operations (e.g., changing (a + b) + c to a + (b + c)) without changing the result, typically to improve performance or enable further optimizations.
SSA
Static Single Assignment. An intermediate representation where every variable is assigned exactly once, simplifying many dataflow analyses and optimizations.
ICE
Internal Compiler Error. An error that occurs within the compiler itself, often due to unexpected conditions or bugs in the compiler's logic.
Filed Under: optimizationtree-ssa-reassoc__builtin_powfloating-point