https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128452
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to fail|17.0 |
Summary|[14/15/16/17 Regression] |[14/15/16 Regression] wrong
|wrong code with |code with
|-fassociative-math: reassoc |-fassociative-math: reassoc
|decrement_power turns pow |decrement_power turns pow
|(x, -2^63) into pow (x, |(x, -2^63) into pow (x,
|2^63-1) |2^63-1)
Known to work| |17.0
Priority|P3 |P2
--- Comment #1 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Biener <[email protected]>:
https://gcc.gnu.org/g:57a50f4b58af716e325b7e630135a9732cf6b639
commit r17-6312-g57a50f4b58af716e325b7e630135a9732cf6b639
Author: Richard Biener <[email protected]>
Date: Thu Nov 5 11:35:02 2026 +0100
Avoid repeated undistribution with negative pow exponents
For (x * y) * __builtin_powi (x, 8000) + x * z * x * pow (x, -8000.0)
with -Ofast reassoc1 generates thousands of multiplications. When
counting candidate operands undistribute_ops_list linearizes the
multiplication chains, expanding only __builtin_pow* calls accepted
by acceptable_pow_call (positive exponents >= 2) into repeated
operands, so x is counted once per chain. zero_one_operation
however uses stmt_is_power_of_op which accepts any constant integer
exponent, and removes x from the second chain by decrementing
pow (x, -8000.0) to pow (x, -8001.0) instead of removing the explicit
x that was counted. As the explicit factors remain, the rebuilt
addition chain offers the same opportunity again and the process
repeats until the __builtin_powi exponent is exhausted, emitting one
multiplication per iteration.
Fix this by making stmt_is_power_of_op agree with acceptable_pow_call
so that only calls that linearization expands are treated as
containing the operand.
This also fixes wrong-code reported in PR128452.
PR tree-optimization/128452
PR tree-optimization/128454
* tree-ssa-reassoc.cc (acceptable_pow_call): Forward declare.
(stmt_is_power_of_op): Use acceptable_pow_call.
* gcc.dg/tree-ssa/reassoc-56.c: New testcase.
* gcc.dg/torture/pr128452.c: Likewise.