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

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

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

commit r17-5198-gfcca05f5c87cc80d82122724d042dca39356969a
Author: From: Jonas Hansen <[email protected]>
Date:   Wed Oct 14 07:27:14 2026 -0600

    [PATCH v2 1/2] middle-end: Account for implicit zero padding in string
initializers

    PR127416 exposes folded character-array initializers as STRING_CSTs. When
    one initializes only a short prefix of an aggregate member, counting the
    string length as both the total and nonzero element counts hides the
    implicit trailing zeros from the constructor density heuristic. This can
    replace clearing and stores with a copy of a large read-only constant.

    Include the known array size in the total element count while retaining
    the existing nonzero estimates and completeness handling. This lets the
    existing density heuristic choose between clearing and copying without
    penalizing aggregates that are mostly nonzero.

    For the original ssa-dse-1.C on Cortex-M0 at -O1, .text plus .rodata falls
    from 276 to 124 bytes, compared with 164 before PR127416. Use byte-sized
    enum elements in the DSE test to preserve its original optimization check,
    and add a regression covering sparse and dense aggregates and their
    runtime contents.

    Regtested with the complete configured native C/C++ and runtime-library
    testsuites on x86_64-pc-linux-gnu before rebasing onto current trunk,
    including all supported C++ compiler standard modes. No new failures:
    the remaining failures reproduce before the follow-up, and sandbox-related
    sanitizer failures pass outside the sandbox.

    After updating to trunk 4d22d3ead95, rebuilt the compiler and reran the
    related C++ tests and the new upstream C aggregate-range tests: 92 expected
    passes, 3 unsupported, no unexpected results. The full testsuite was not
    repeated on the updated base. Before rebasing, also tested with 20
    arm-none-eabi Cortex-M0 compile checks and native and Arm compiler
    self-tests.

    gcc/ChangeLog:

            PR tree-optimization/127416
            * expr.cc (categorize_ctor_elements_1): Include implicit trailing
            zeros in the total element count for string initializers.

    gcc/testsuite/ChangeLog:

            PR tree-optimization/127416
            * g++.dg/tree-ssa/constexpr-array-padding.C: New test.
            * g++.dg/tree-ssa/ssa-dse-1.C (byte): New enum.
            (fixbuf): Use byte as the buffer element type.

    Signed-off-by: Jonas Hansen <[email protected]>

Reply via email to