[Bug middle-end/116454] [13 Regression] `*++ptr * 1j` is handled incorrectly with -ffast-math, increments ptr twice since r0-77972-g9f5396713d9e18
cvs-commit at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Mar 20 09:59:38 GMT 2026
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116454
--- Comment #14 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Richard Biener
<rguenth@gcc.gnu.org>:
https://gcc.gnu.org/g:a5859de5504b8574de329a53d5ca04613ae4cf08
commit r13-10147-ga5859de5504b8574de329a53d5ca04613ae4cf08
Author: Andrew Pinski <quic_apinski@quicinc.com>
Date: Wed Aug 21 17:41:38 2024 -0700
fold: Fix `a * 1j` if a has side effects [PR116454]
The problem here was a missing save_expr around arg0 since
it is used twice, once in REALPART_EXPR and once in IMAGPART_EXPR.
Thia adds the save_expr and reformats the code slightly so it is a
little easier to understand. It excludes the case when arg0 is
a COMPLEX_EXPR since in that case we'll end up with the distinct
real and imaginary parts. This is important to retain early
optimization in some testcases.
Bootstapped and tested on x86_64-linux-gnu with no regressions.
PR middle-end/116454
gcc/ChangeLog:
* fold-const.cc (fold_binary_loc): Fix `a * +-1i`
by wrapping arg0 with save_expr when it is not COMPLEX_EXPR.
gcc/testsuite/ChangeLog:
* gcc.dg/torture/pr116454-1.c: New test.
* gcc.dg/torture/pr116454-2.c: New test.
Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
Co-Authored-By: Richard Biener <rguenther@suse.de>
(cherry picked from commit b07f8a301158e53717b8688cc8ea430b6f02574c)
More information about the Gcc-bugs
mailing list