[Bug tree-optimization/49872] Missed optimization: Could coalesce neighboring memsets

sgunderson at bigfoot dot com gcc-bugzilla@gcc.gnu.org
Thu Jul 28 10:10:00 GMT 2011


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49872

--- Comment #2 from sgunderson at bigfoot dot com 2011-07-28 10:09:51 UTC ---
I'm not sure if I've seen exactly this construction in real-world code, but
I've certainly seen examples of the hybrid I sketched out (looking at one was
what motivated me to file the bug), ie. something like:

struct S {
    int f[1024];
    int g;
};

void func(struct S* s)
{
    memset(s->f, 0, sizeof(s->f));
    s->g = 0;
}

which I would argue should be rewritten to

void func(struct S* s)
{
    memset(s->f, 0, sizeof(s->f) + sizeof(s->g));
}

I'd argue that programmers should not be doing this kind of optimization
themselves, since it's very prone to break when changing the structure,
especially as alignment etc. comes into play.



More information about the Gcc-bugs mailing list