This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug rtl-optimization/17343] New: a dispatch table can be shortened for certain switch statements


Consider:

void foo0(void);
void foo1(void);
void foo2(void);
void foo3(void);

void
foo (int a)
{
  switch (a)
    {
    case 10:
    case 11:
    case 12:
    case 13:
      goto ddd;
    case 14:
      foo1();
      break;
    case 15:
      foo2();
      break;
    case 16:
      foo3();
      break;
    default:
    ddd:
      foo0();
      break;
    }
}

On i686-pc-linux-gnu with -O2 -fomit-frame-pointer, the above code
turns into:

foo:
        movl    4(%esp), %eax
        subl    $10, %eax
        cmpl    $6, %eax
        ja      .L2
        jmp     *.L6(,%eax,4)
        .section        .rodata
        .align 4
        .align 4
.L6:
        .long   .L2
        .long   .L2
        .long   .L2
        .long   .L2
        .long   .L3
        .long   .L4
        .long   .L5
        .text
        .p2align 2,,3
.L2:
        jmp     foo0
        .p2align 2,,3
.L5:
        jmp     foo3
        .p2align 2,,3
.L3:
        jmp     foo1
        .p2align 2,,3
.L4:
        jmp     foo2

Note that the function subtracts 10 from the argument and that the
first four entries of the dispatch table are the same as the default
case.

Therefore, if we subtracted 14, we could make the dispatch table
shorter, effectively treating cases 10 .. 13 as the default case.

-- 
           Summary: a dispatch table can be shortened for certain switch
                    statements
           Product: gcc
           Version: 3.5.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P2
         Component: rtl-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: kazu at cs dot umass dot edu
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17343


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]