https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93262
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Untested trunk fix on top of the PR93249 fix, so won't apply cleanly to older stuff, will need reindentation: --- tree-ssa-dse.c.jj2 2020-01-14 12:13:39.900589819 +0100 +++ tree-ssa-dse.c 2020-01-14 13:47:50.085009665 +0100 @@ -508,6 +508,22 @@ maybe_trim_memstar_call (ao_ref *ref, sb /* Head trimming requires adjusting all the arguments. */ if (head_trim) { + /* For __*_chk need to adjust also the last argument. */ + if (gimple_call_num_args (stmt) == 4) + { + tree size = gimple_call_arg (stmt, 3); + if (!tree_fits_uhwi_p (size)) + break; + if (!integer_all_onesp (size)) + { + unsigned HOST_WIDE_INT sz = tree_to_uhwi (size); + if (sz < (unsigned) head_trim) + break; + tree arg = wide_int_to_tree (TREE_TYPE (size), + sz - head_trim); + gimple_call_set_arg (stmt, 3, arg); + } + } tree *dst = gimple_call_arg_ptr (stmt, 0); increment_start_addr (stmt, dst, head_trim); tree *src = gimple_call_arg_ptr (stmt, 1); @@ -527,6 +543,22 @@ maybe_trim_memstar_call (ao_ref *ref, sb /* Head trimming requires adjusting all the arguments. */ if (head_trim) { + /* For __*_chk need to adjust also the last argument. */ + if (gimple_call_num_args (stmt) == 4) + { + tree size = gimple_call_arg (stmt, 3); + if (!tree_fits_uhwi_p (size)) + break; + if (!integer_all_onesp (size)) + { + unsigned HOST_WIDE_INT sz = tree_to_uhwi (size); + if (sz < (unsigned) head_trim) + break; + tree arg = wide_int_to_tree (TREE_TYPE (size), + sz - head_trim); + gimple_call_set_arg (stmt, 3, arg); + } + } tree *dst = gimple_call_arg_ptr (stmt, 0); increment_start_addr (stmt, dst, head_trim); decrement_count (stmt, head_trim); Now to figure out if we want a runtime testcase in gcc.c-torture/execute/builtins/ or not...