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 target/43462] New: Suboptimal switch table jump generation


code:

extern int a;
void b();
main()
{
        switch (a & 7) {
        case 0: b(); break;
        case 1: b(); break;
        case 2: b(); break;
        case 3: b(); break;
        case 4: b(); break;
        case 5: b(); break;
        case 6: b(); break;
        case 7: b(); break;
        }
}

generates:
[...]
        and     r3, r3, #7
        subs    r3, r3, #1
        cmp     r3, #6
        bhi     .L9
        tbb     [pc, r3]
.L10:  
        .byte   (.L9-.L10)/2
        .byte   (.L9-.L10)/2
        .byte   (.L9-.L10)/2
        .byte   (.L9-.L10)/2
        .byte   (.L9-.L10)/2
        .byte   (.L9-.L10)/2
        .byte   (.L9-.L10)/2
        .align  1
.L9:
[...]

This could be better implemented as:

        and     r3, r3, #7
        tbb     [pc, r3]
        (jump table with 8 entries)
[...]

Please ignore that all branches are the same in this example.


-- 
           Summary: Suboptimal switch table jump generation
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: target
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: mirq-gccboogs at rere dot qmqm dot pl
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: arm-none-eabi


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


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