public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "ubizjak at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/34723] New: Summing ariable should be initialized to the first member before the loop Date: Wed, 09 Jan 2008 09:39:00 -0000 [thread overview] Message-ID: <bug-34723-1649@http.gcc.gnu.org/bugzilla/> (raw) This testcase: --cut here-- char table[256]; int test(void) { char val = 0; int i; for (i = 0; i < 10; i++) val += table[i]; return val; } --cut here-- compiles using gcc-4.2 -O2 to: test: movzbl table, %eax movl $1, %edx .p2align 4,,7 .L2: addb table(%edx), %al addl $1, %edx cmpl $10, %edx jne .L2 movsbl %al,%eax ret but using gcc-4.3 -O2 to: test: xorl %edx, %edx xorl %eax, %eax .p2align 4,,7 .p2align 3 .L2: addb table(%edx), %al addl $1, %edx cmpl $10, %edx jne .L2 movsbl %al,%eax ret Note that gcc-4.3 initializes summation variable to zero, where gcc-4.2 initializes summation variable to first array member, saving one loop iteration. The difference is already present on tree level, where: gcc-4.2: test () { int i; char val; <bb 2>: val = (char) (unsigned char) MEM[symbol: table]; i = 1; <L0>:; val = (char) ((unsigned char) val + (unsigned char) MEM[symbol: table, index: (unsigned int) i]); i = i + 1; if (i != 10) goto <L0>; else goto <L2>; <L2>:; return (int) val; } gcc-4.3: test () { int i; char val; unsigned char D.1186; <bb 2>: i = 0; val = 0; <bb 3>: D.1186 = (unsigned char) val + (unsigned char) MEM[symbol: table, index: (unsigned int) i]; val = (char) D.1186; i = i + 1; if (i != 10) goto <bb 3>; else goto <bb 4>; <bb 4>: return (int) val; } -- Summary: Summing ariable should be initialized to the first member before the loop Product: gcc Version: 4.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: ubizjak at gmail dot com GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34723
next reply other threads:[~2008-01-09 8:32 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2008-01-09 9:39 ubizjak at gmail dot com [this message] 2008-01-09 9:56 ` [Bug tree-optimization/34723] Summing variable " pinskia at gcc dot gnu dot 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-34723-1649@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).