public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "sgunderson at bigfoot dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/49872] New: Missed optimization: Could coalesce neighboring memsets Date: Wed, 27 Jul 2011 16:51:00 -0000 [thread overview] Message-ID: <bug-49872-4@http.gcc.gnu.org/bugzilla/> (raw) http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49872 Summary: Missed optimization: Could coalesce neighboring memsets Product: gcc Version: 4.7.0 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: tree-optimization AssignedTo: unassigned@gcc.gnu.org ReportedBy: sgunderson@bigfoot.com Given the following code: #include <string.h> struct S { int f[1024]; int g[1024]; }; void func(struct S* s) { memset(s->f, 0, sizeof(s->f)); memset(s->g, 0, sizeof(s->g)); } GCC currently generates two memsets. The code with -O2 is a bit hard to read, so I'm just pasting the -Os assembly for clarity: 00000000 <func>: 0: 55 push %ebp 1: 31 c0 xor %eax,%eax 3: 89 e5 mov %esp,%ebp 5: b9 00 04 00 00 mov $0x400,%ecx a: 57 push %edi b: 8b 7d 08 mov 0x8(%ebp),%edi e: f3 ab rep stos %eax,%es:(%edi) 10: 8b 55 08 mov 0x8(%ebp),%edx 13: 66 b9 00 04 mov $0x400,%cx 17: 81 c2 00 10 00 00 add $0x1000,%edx 1d: 89 d7 mov %edx,%edi 1f: f3 ab rep stos %eax,%es:(%edi) 21: 5f pop %edi 22: 5d pop %ebp 23: c3 ret Ideally GCC should also be able to coalesce this together with memsets not written as memset, e.g. s->g[0] = 0;.
next reply other threads:[~2011-07-27 16:51 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2011-07-27 16:51 sgunderson at bigfoot dot com [this message] 2011-07-28 10:01 ` [Bug tree-optimization/49872] " rguenth at gcc dot gnu.org 2011-07-28 10:10 ` sgunderson at bigfoot dot com 2021-08-21 23:57 ` pinskia at gcc dot gnu.org 2024-04-21 19:26 ` pinskia at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-49872-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).