public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug optimization/11832] New: Optimization of common code in switch statements
@ 2003-08-06 9:45 alga at rgai dot hu
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
0 siblings, 2 replies; 3+ messages in thread
From: alga at rgai dot hu @ 2003-08-06 9:45 UTC (permalink / raw)
To: gcc-bugs
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2003-08-23 1:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-08-06 9:45 [Bug optimization/11832] New: Optimization of common code in switch statements alga at rgai dot hu
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
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).