Optimizing switch statements: Overview and what's new

Day 1 | 17:20 | 00:20 | K.3.201 | Filip Kastl


Note: I'm reworking this at the moment, some things won't work.

The stream isn't available yet! Check back at 17:20.
Get involved in the conversation!Join the chat

During compilation, GCC breaks down switch statements into simpler statements. If a switch has a specific structure, GCC may use techniques that result in faster code. We call these techniques "switch optimizations".

In this talk we'll overview switch optimizations in GCC. Then we'll go into more detail on turning switches into array lookups. In GCC this is called "switch conversion". I'll introduce a new method called "exponential transformation" that I recently contributed to switch conversion. If time permits, we will also discuss potential future work on switch optimizations.

I plan to make this talk beginner-friendly. I myself have started working on GCC just 2 years ago. The talk should however give the audience a good idea about what switch optimizations are available and what they do.

Expected prior knowledge: What is a C switch statement. What is an intermediate representation (or intermediate language).