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

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

https://gcc.gnu.org/g:bb273fcdc0945f3f07a03ba90a39443494563f06

commit r17-6340-gbb273fcdc0945f3f07a03ba90a39443494563f06
Author: Kyrylo Tkachov <[email protected]>
Date:   Wed Nov 11 05:12:38 2026 -0800

    aarch64: Add memory clobber to GCS stack switch patterns [PR128284]

    The GCSSS1 and GCSSS2 instructions validate and consume the cap token
    at the new GCS address and write a return token to the old GCS.  The
    aarch64_gcsss1 and aarch64_gcsss2 patterns are plain unspec_volatile
    with no memory effects, so RTL optimisers treat memory as unchanged
    across them.  For:

      uint64_t f (uint64_t *p)
      {
        uint64_t a = *p;
        __gcsss (p);
        return a ^ *p;
      }

    cse1 reuses the load before the switch for the load after it and the
    function folds to returning 0.

    Add (clobber (mem:BLK (scratch))) to both patterns, as done for other
    instructions with arbitrary memory side effects.  GCSPOPM only reads
    memory and changes no memory, so it is left unchanged.

    Before:
            sys     #3, c7, c7, #2, x0 // gcsss1
            mov     w0, 0
            sysl    x0, #3, c7, c7, #3 // gcsss2
            mov     w0, 0
            ret
    After:
            ldr     x2, [x0]
            sys     #3, c7, c7, #2, x0 // gcsss1
            mov     w1, 0
            sysl    x1, #3, c7, c7, #3 // gcsss2
            ldr     x0, [x0]
            eor     x0, x2, x0
            ret

    Bootstrapped and tested on aarch64-none-linux-gnu.

    gcc/ChangeLog:

            PR target/128284
            * config/aarch64/aarch64.md (aarch64_gcsss1): Add a memory clobber.
            (aarch64_gcsss2): Likewise.

    gcc/testsuite/ChangeLog:

            PR target/128284
            * gcc.target/aarch64/pr128284.c: New test.

    Signed-off-by: Kyrylo Tkachov <[email protected]>

Reply via email to