From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4898 invoked by alias); 6 Aug 2003 08:19:51 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 4889 invoked by uid 48); 6 Aug 2003 08:19:51 -0000 Date: Wed, 06 Aug 2003 08:19:00 -0000 From: "alga at rgai dot hu" To: gcc-bugs@gcc.gnu.org Message-ID: <20030806081946.11822.alga@rgai.hu> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug optimization/11822] New: Formulated jumps for switch X-Bugzilla-Reason: CC X-SW-Source: 2003-08/txt/msg00856.txt.bz2 List-Id: PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11822 Summary: Formulated jumps for switch Product: gcc Version: 3.4 Status: UNCONFIRMED Severity: minor 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 In some cases the jump table used for implementing a C switch statement could be replaced with a jump to a calculated address. This can be done if the jump table contains an appropriate pattern which can be formulated into a function/calculation. A simple example is the case when the code sizes of case blocks are equal and each case label is addressable with one data processing instruction. In this case GCC could compute the size of case blocks and multiply them by the switch condition value and modify pc with this value. It could also be possible to rearrange the jump table into regions with this "formulated jumps" mechanism. GCC should use this mechanism when optimizing for size. --- example --- // arm-elf-gcc -S -g0 -Os -o form-jump.s form-jump.c void func (int); void foo (int a) { switch(a) { case 15: func(5); case 16: func(59); case 17: func(515); case 18: func(65); case 19: func(8); case 20: func(15); } } --- arm code --- foo: mov ip, sp sub r0, r0, #15 stmfd sp!, {fp, ip, lr, pc} sub fp, ip, #4 cmp r0, #5 ldrls pc, [pc, r0, asl #2] b .L1 .p2align 2 .L9: .word .L3 .word .L4 .word .L5 .word .L6 .word .L7 .word .L8 .L3: mov r0, #5 bl func .L4: mov r0, #59 bl func .L5: ldr r0, .L10 bl func .L6: mov r0, #65 bl func .L7: mov r0, #8 bl func .L8: mov r0, #15 ldmea fp, {fp, sp, lr} b func .L1: ldmea fp, {fp, sp, pc} --- possible solution --- foo: mov ip, sp sub r0, r0, #15 stmfd sp!, {fp, ip, lr, pc} sub fp, ip, #4 cmp r0, #5 addls pc, pc, r0, asl #3 b .L1 .L3: mov r0, #5 bl func .L4: mov r0, #59 bl func .L5: ldr r0, .L10 bl func .L6: mov r0, #65 bl func .L7: mov r0, #8 bl func .L8: mov r0, #15 ldmea fp, {fp, sp, lr} b func .L1: ldmea fp, {fp, sp, pc}