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

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

https://gcc.gnu.org/g:3333fc756fad286f8bee5c626462bf81a90320bf

commit r17-6969-g3333fc756fad286f8bee5c626462bf81a90320bf
Author: Richard Biener <[email protected]>
Date:   Tue Oct 13 12:06:31 2026 +0200

    Do not SRA an aggregate copy with data in registers mangling bits

    When SRA scalarizes an aggregate which is copied from and to other
    aggregates, the copies are performed through the scalar replacements.  If
    the mode of a replacement cannot transfer all bits, such as SFmode and
    DFmode with x87 math, the copy can change the data, for example signaling
    NaNs get quietened:

      struct F { float a, b, c, d; };
      void copy (struct F *dst, const struct F *src)
      {
        struct F s = *src;
        *dst = s;
      }

    with -m32 -mno-sse loads and stores the fields with flds/fstps.  The
    existing types_risk_mangled_binary_repr_p check only catches the case when
    the same data is accessed with different types.

    This patch makes analyze_access_subtree check whether scalar accesses
    have a mode that does not preserve all bits of its precision and whose
    data can both come from an aggregate copy (or from outside of the function)
    and be copied out as part of an aggregate.  For such accesses, the
    replacement is given a bitwise type of the same size.  Direct scalar
    accesses then either view-convert the bitwise replacement or store it to
    or load it from the aggregate, which preserves the semantics of the
    original loads and stores while keeping the bit pattern intact during
    aggregate transfers.  If there is no suitable bitwise type that can
    transfer bits, no replacement is created.

    Additionally, mode_preserves_value_bits_p is introduced so that floating
    point modes with padding bits, such as XFmode (where size > precision), are
    not treated as mangling bits when their value bits are preserved by loads
    and stores.

    Assisted-By: Claude Opus 5.5 <[email protected]>

            PR tree-optimization/127745
            * tree-sra.cc (mode_preserves_value_bits_p): New function.
            (access_bits_copied_through_p): Likewise.
            (analyze_access_subtree): Use a bitwise type for replacements of
            scalar accesses whose data is copied in between aggregates and the
            mode of which cannot transfer bits, or do not create them if no
            suitable bitwise type exists.

            * gcc.target/i386/sra-x87-1.c: New test.
            * gcc.target/i386/sra-x87-2.c: New test.
            * gcc.target/i386/sra-x87-3.c: New test.
            * gcc.target/i386/sra-x87-4.c: New test.
            * gcc.target/i386/sra-x87-5.c: New test.
            * gcc.target/i386/sra-x87-6.c: New test.
            * gcc.target/i386/sra-x87-7.c: New test.
            * gcc.target/i386/sra-x87-8.c: New test.
  • [Bug tree-optimization/127745] ... cvs-commit at gcc dot gnu.org via Gcc-bugs

Reply via email to