https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127852

--- Comment #5 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Vineet Gupta <[email protected]>:

https://gcc.gnu.org/g:8d1522e29e9c016d738dadafc507ace9bf66a54b

commit r17-5113-g8d1522e29e9c016d738dadafc507ace9bf66a54b
Author: Vineet Gupta <[email protected]>
Date:   Tue Oct 13 18:15:49 2026 +0530

    simplify-rtx: Don't merge equal operands with side effects [PR127852]

    With -ffuse-ops-with-volatile-access combine can hand
    simplify_binary_operation_1 two copies of the same volatile MEM, e.g.
    (minus (ashift (mem/v) 1) (mem/v)) for
    "int a = *p; return 2 * a - *p;".  The MINUS coefficient fold and the
    (X + 1) * Y - Y and (X - 1) * Y + Y folds merge the two copies into one,
    so one of two sequenced volatile reads is lost.  Only the PLUS
    coefficient fold had a guard, and it only looked at a bare volatile MEM.

    Require !side_effects_p for the operand that would be merged, as the
    other folds in this function already do.

    Bootstrapped and regression tested on x86_64-linux-gnu and
aarch64-linux-gnu.

            PR rtl-optimization/127852

    gcc/ChangeLog:

            * simplify-rtx.cc (simplify_context::simplify_binary_operation_1):
            Don't merge two equal operands with side effects in the PLUS and
            MINUS coefficient folds and in the (X - 1) * Y + Y and
            (X + 1) * Y - Y folds.

    gcc/testsuite/ChangeLog:

            * gcc.target/aarch64/volatile-fuse-minus-1.c: New test.
            * gcc.target/aarch64/volatile-fuse-minus-2.c: New test.
            * gcc.target/i386/volatile-fuse-minus-1.c: New test.
            * gcc.target/i386/volatile-fuse-minus-2.c: New test.

    Signed-off-by: Vineet Gupta <[email protected]>

Reply via email to