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

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

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

commit r17-2389-geae644638908427b11f8d791f718851e25bece01
Author: Naveen <[email protected]>
Date:   Tue Jul 14 01:42:06 2026 -0700

    tree-optimization: Fold length-one memset through arbitrary pointers
[PR102202]

    gimple_fold_builtin_memset currently folds constant-length memset calls
    into scalar stores only when the destination is an ADDR_EXPR. Calls
    through an arbitrary pointer, such as a function parameter are left as
    library calls and non-constant fill values are rejected even for the
    length-one case where byte replication is unnecessary.

    Add a dedicated folding path for length-one memset calls through
    arbitrary pointer destinations. Since the access is exactly one byte,
    use unsigned_char_type_node for the store. This supports both constant
    and non-constant fill values: constant fills are converted with
    fold_convert while non-constant fills use gimple_convert. Volatile
    qualification is preserved from the pointed-to type and the store is
    emitted as a MEM_REF at offset zero using the usual ref-all character
    pointer type.

    Defer this new arbitrary-pointer fold until after object-size analysis
    has run so that the original memset remains available to object-size
    based diagnostics. The existing ADDR_EXPR-based folding path for other
    constant lengths is unchanged.

    gcc/ChangeLog:
            PR tree-optimization/102202
            * gimple-fold.cc (gimple_fold_builtin_memset): Hoist
            tree_to_uhwi (len) before the INTEGER_CST guard.  Fold
            length-one memset calls through arbitrary pointer destinations.
            Build a ref-all MEM_REF at offset zero and preserve the call
            result when it is used.

    gcc/testsuite/ChangeLog:
            PR tree-optimization/102202
            * gcc.dg/pr102202-fold.c: New test.

    Signed-off-by: Naveen <[email protected]>

Reply via email to