https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80576
--- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> --- I've seen code similar to it but I don't remember how close they were. I imagine it comes up quite a bit as GCC itself transforms code in various ways. DSE already eliminates stores with constant sizes but it doesn't handle the non-constant ones: $ cat pr80576.c && gcc -O2 -S -Wall -Wextra -Wpedantic -fdump-tree-optimized=/dev/stdout pr80576.c extern char a[32]; void f (const char *s) { __builtin_memcpy (a, s, 7); // eliminated __builtin_memset (a, 0, sizeof a); } void g (const char *s, unsigned n) { __builtin_memcpy (a, s, n); // not eliminated __builtin_memset (a, 0, sizeof a); } ;; Function f (f, funcdef_no=0, decl_uid=1909, cgraph_uid=1, symbol_order=0) f (const char * s) { <bb 2> [local count: 1073741824]: __builtin_memset (&a, 0, 32); [tail call] return; } ;; Function g (g, funcdef_no=1, decl_uid=1913, cgraph_uid=2, symbol_order=1) g (const char * s, unsigned int n) { long unsigned int _1; <bb 2> [local count: 1073741824]: _1 = (long unsigned int) n_2(D); __builtin_memcpy (&a, s_4(D), _1); __builtin_memset (&a, 0, 32); [tail call] return; }