public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "alga at rgai dot hu" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug optimization/11832] New: Optimization of common code in switch statements Date: Wed, 06 Aug 2003 09:45:00 -0000 [thread overview] Message-ID: <20030806094508.11832.alga@rgai.hu> (raw) PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11832 Summary: Optimization of common code in switch statements Product: gcc Version: 3.4 Status: UNCONFIRMED Severity: normal Priority: P3 Component: optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: alga at rgai dot hu CC: gcc-bugs at gcc dot gnu dot org GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: arm-unknown-elf If a C switch statement contains common code among certain case branches, GCC isn't able to combine the common code. Reorganization of the switch may solve this problem. --- c example --- int a, b, e; unsigned char *c; void foo() { int d = 13; b = -1; switch (e) { case 1: b++; c[b] = (unsigned char)d; break; case 2: b++; c[b] = (unsigned char)d; b++; c[b] = (unsigned char)d; break; case 3: b++; c[b] = (unsigned char)d; b++; c[b] = (unsigned char)d; b++; c[b] = (unsigned char)d; break; default: a = 1; b++; c[b] = (unsigned char)d; b++; c[b] = (unsigned char)d; b++; c[b] = (unsigned char)d; b++; c[b] = (unsigned char)d; } } --- arm code --- foo: stmfd sp!, {r4, lr} ldr r3, .L10 ldr r2, [r3, #0] ldr lr, .L10+4 mvn r3, #0 cmp r2, #2 str r3, [lr, #0] mov r4, #13 beq .L4 bgt .L7 cmp r2, #1 beq .L3 b .L6 .L7: cmp r2, #3 beq .L5 b .L6 .L3: ldr r3, .L10+8 ldr r2, [r3, #0] mov r3, #0 str r3, [lr, #0] strb r4, [r2, #0] ldmfd sp!, {r4, pc} .L4: ldr r1, .L10+8 ldr r2, [r1, #0] mov r3, #0 str r3, [lr, #0] strb r4, [r2, #0] ldr r3, [lr, #0] ldr r2, [r1, #0] b .L8 .L5: ldr r2, .L10+8 ldr r1, [r2, #0] mov r3, #0 str r3, [lr, #0] strb r4, [r1, #0] ldr r3, [lr, #0] ldr r1, [r2, #0] add r3, r3, #1 str r3, [lr, #0] strb r4, [r1, r3] ldr r3, [lr, #0] ldr r2, [r2, #0] .L8: add r3, r3, #1 .L9: str r3, [lr, #0] strb r4, [r2, r3] ldmfd sp!, {r4, pc} .L6: ldr r0, .L10+8 ldr r2, [lr, #0] ldr ip, [r0, #0] ldr r3, .L10+12 mov r1, #1 add r2, r2, #1 str r2, [lr, #0] str r1, [r3, #0] strb r4, [ip, r2] ldr r3, [lr, #0] ldr r2, [r0, #0] add r3, r3, r1 str r3, [lr, #0] strb r4, [r2, r3] ldr r3, [lr, #0] ldr r2, [r0, #0] add r3, r3, r1 str r3, [lr, #0] strb r4, [r2, r3] ldr r3, [lr, #0] ldr r2, [r0, #0] add r3, r3, r1 b .L9
next reply other threads:[~2003-08-06 9:45 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2003-08-06 9:45 alga at rgai dot hu [this message] 2003-08-06 12:50 ` [Bug optimization/11832] " pinskia at physics dot uc dot edu 2003-08-23 1:57 ` dhazeghi at yahoo dot com
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=20030806094508.11832.alga@rgai.hu \ --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).