This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]