https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123212

--- Comment #3 from Filip Kastl <pheeck at gcc dot gnu.org> ---
(In reply to Sam James from comment #1)
> The algorithm was changed for switch conversion in 15 and then in
> r15-4756-g06bc3a734e8890, it was made to only be at >= -O1 (but not -Og)
> because of it being too expensive at -O0.

Indeed.  It was a reaction to pr17091 where the bit test algorithm took
particularly long to finish.  The worst-case asymptotic complexity of the bit
test algorithm has since improved to linear.  The jump table algorithm is most
likely still asymptotically slow (as tracked in pr118353).  But that is only
because it tries to do fancy things!  If it doesn't manage to convert the whole
switch into a single jump table, it tries to convert just parts of the switch. 
That can be done in many ways and that's where the slowness comes in.

So how about at -O0/-Og we tell GCC to just try to convert the whole switch
into a single jump table?  And if that fails GCC would fall back to the "horrid
codegen" (search tree :)).  That way we avoid both being slow and generating
counter-intuitive code.

Reply via email to