public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug optimization/11822] New: Formulated jumps for switch
@ 2003-08-06  8:19 alga at rgai dot hu
  2003-08-06 20:01 ` [Bug optimization/11822] " pinskia at physics dot uc dot edu
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: alga at rgai dot hu @ 2003-08-06  8:19 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=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}


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug optimization/11822] Formulated jumps for switch
  2003-08-06  8:19 [Bug optimization/11822] New: Formulated jumps for switch alga at rgai dot hu
@ 2003-08-06 20:01 ` pinskia at physics dot uc dot edu
  2003-08-06 20:02 ` pinskia at physics dot uc dot edu
  2003-08-07 17:40 ` pinskia at physics dot uc dot edu
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at physics dot uc dot edu @ 2003-08-06 20:01 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=11822


pinskia at physics dot uc dot edu changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|minor                       |enhancement
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
 GCC target triplet|arm-unknown-elf             |
   Last reconfirmed|0000-00-00 00:00:00         |2003-08-06 20:01:29
               date|                            |


------- Additional Comments From pinskia at physics dot uc dot edu  2003-08-06 20:01 -------
I agruee with this except ...


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug optimization/11822] Formulated jumps for switch
  2003-08-06  8:19 [Bug optimization/11822] New: Formulated jumps for switch alga at rgai dot hu
  2003-08-06 20:01 ` [Bug optimization/11822] " pinskia at physics dot uc dot edu
@ 2003-08-06 20:02 ` pinskia at physics dot uc dot edu
  2003-08-07 17:40 ` pinskia at physics dot uc dot edu
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at physics dot uc dot edu @ 2003-08-06 20:02 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=11822


pinskia at physics dot uc dot edu changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |SUSPENDED


------- Additional Comments From pinskia at physics dot uc dot edu  2003-08-06 20:02 -------
The current infrostructor in gcc will not be able to handle this so suspending.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug optimization/11822] Formulated jumps for switch
  2003-08-06  8:19 [Bug optimization/11822] New: Formulated jumps for switch alga at rgai dot hu
  2003-08-06 20:01 ` [Bug optimization/11822] " pinskia at physics dot uc dot edu
  2003-08-06 20:02 ` pinskia at physics dot uc dot edu
@ 2003-08-07 17:40 ` pinskia at physics dot uc dot edu
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at physics dot uc dot edu @ 2003-08-07 17:40 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=11822


pinskia at physics dot uc dot edu changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|3.4                         |---


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-08-07 17:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-08-06  8:19 [Bug optimization/11822] New: Formulated jumps for switch alga at rgai dot hu
2003-08-06 20:01 ` [Bug optimization/11822] " pinskia at physics dot uc dot edu
2003-08-06 20:02 ` pinskia at physics dot uc dot edu
2003-08-07 17:40 ` pinskia at physics dot uc dot edu

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).