https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102202
--- Comment #7 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:a8072f31bc90000b3b8a2c0c7819710cf924727a commit r17-2113-ga8072f31bc90000b3b8a2c0c7819710cf924727a Author: Naveen <[email protected]> Date: Fri Jul 3 05:24:04 2026 -0700 tree-optimization: fold memset with length in [0, 1] to conditional store [PR102202] The patch improves memset optimization when the length is known to be 0 or 1. It uses Ranger information to recognize such cases, shrink-wraps the call on the zero-length case and replaces the one-byte case with a direct byte store. It also extends gimple_fold_builtin_memset to handle Ranger-proven singleton lengths not just integer constants. gcc/ChangeLog: PR tree-optimization/102202 * tree-call-cdce.cc: Include "tree-ssanames.h", "gimple-fold.h". (len_has_boolean_range_p): New function. (can_shrink_wrap_len_p): New function. (gen_zero_len_conditions): New function. (shrink_wrap_len_call): New function. (shrink_wrap_conditional_dead_built_in_calls): Dispatch to shrink_wrap_one_memset_call for memset calls eligible for the [0, 1] length transform, ahead of the generic LHS and range-test paths. (pass_call_cdce::execute): Collect memset calls satisfying can_shrink_wrap_memset_p as shrink-wrap candidates. gcc/testsuite/ChangeLog: PR tree-optimization/102202 * gcc.dg/pr102202-1.c: New test. * gcc.dg/pr102202.c: New test. * gcc.target/aarch64/pr100518.c: Modify to handle the warning. Signed-off-by: Naveen <[email protected]>
