Why does gcc suck at switch()?

law@redhat.com law@redhat.com
Sun Oct 12 05:49:00 GMT 2003


In message <20031003145614.GP24824@parcelfarce.linux.theplanet.co.uk>, Matthew 
Wilcox writes:
 >
 >Why does gcc generate worse code for switch() statements than for
 >multiple-if?
Because it apparently is trying to do the tests in range form rather
than naively generating a simple test for each case in the switch
(there's no way to actually verify that since you didn't provide a
complete testcase).


The range-forms can be more effective in some cases or at least that's
the claim.  I'm not particularly familiar with that code so I've never
tried to re-tune it.  [ I have noticed it generating spectacularly bad
code in certain circumstances, yours may just be another of those cases. ]


jeff




More information about the Gcc mailing list