[Bug fortran/125914] -1.0**integer should be real(-1**integer)
cvs-commit at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Jun 22 05:30:06 GMT 2026
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125914
--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Thomas Koenig <tkoenig@gcc.gnu.org>:
https://gcc.gnu.org/g:5b0da09f0ed5da80734c143d3ce2bacd78dc0c28
commit r17-1734-g5b0da09f0ed5da80734c143d3ce2bacd78dc0c28
Author: Thomas Koenig <tkoenig@gcc.gnu.org>
Date: Mon Jun 22 07:26:25 2026 +0200
Optimize (-1.0)**n to (real) (1 - ((n & 1) << 1)).
The problem was that the optimization done for PR 57073 uses powi and
friends, so it only applied to default integer exponent. The test
case has an integer(kind=8) exponent, which is is calculated by
calling a gfortran library function.
There are two possible approaches: One would be to convert all
integer types to default integer (because only the lowest-value
bit matters to the result) and call the right __builtin_powi function.
However, the generated code is suboptimal, see PR 125919. I therefore
chose the variant which currently generates the best code.
This requires the change to the power_6.f90 test case.
gcc/fortran/ChangeLog:
PR fortran/125914
* trans-expr.cc (gfc_conv_power_op): Rewrite (-1.0)**n into
(real) (1 - ((n & 1) << 1)).
gcc/testsuite/ChangeLog:
PR fortran/125914
* gfortran.dg/power_6.f90: Remove scans for powi.
* gfortran.dg/power_10.f90: New test.
More information about the Gcc-bugs
mailing list