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