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

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

https://gcc.gnu.org/g:1efd3c41bf05d5580229a7a9cf7a36035342ded3

commit r17-6811-g1efd3c41bf05d5580229a7a9cf7a36035342ded3
Author: Dominic P <[email protected]>
Date:   Sat Nov 28 11:03:42 2026 +0000

    simplify-rtx: Keep volatile reads in smax (-A, A) -> abs (A) [PR126726]

    The smax (-A, A) -> abs (A) fold added for PR126726 drops the A inside
    the NEG without checking it for side effects.  For

      int f (volatile int *p, volatile long *q)
      {
        long t = *q;
        int a = *(int *) p;
        int b = -*p;
        return (a > b ? a : b) + (int) t;
      }

    combine folds (smax (neg (mem/v)) (mem)) to (abs (mem)), so the volatile
    read is lost and *p is read before *q.  With
    -ffuse-ops-with-volatile-access two volatile reads, as in
    "int a = -*p; int b = *p;", are likewise merged into one.  Require
    !side_effects_p on the NEG operand.

    Assisted-by: Claude Opus 5.5 (Anthropic)
    Signed-off-by: Dominic P <[email protected]>

    gcc/ChangeLog:

            PR rtl-optimization/126726
            * simplify-rtx.cc (simplify_context::simplify_binary_operation_1)
            <case SMAX>: Don't fold smax (-A, A) to abs (A) when the negated
            operand has side effects.

    gcc/testsuite/ChangeLog:

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

Reply via email to