This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug optimization/11832] New: Optimization of common code in switch statements
- From: "alga at rgai dot hu" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 6 Aug 2003 09:45:10 -0000
- Subject: [Bug optimization/11832] New: Optimization of common code in switch statements
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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