Skip to content
0:00 / 0:00

#llvm#clang#switchstatements

Hans Wennborg: C++ switch statements under the hood in LLVM

SwedenCpp

4.8K subscribers • 2 videos on Hallway

YouTube
  • Recommended by 2 people: 2 in engineering communities.
  • Presented by Hans Wennborg

Advanced. Deep dive for people who know the field.

4.3K views1 year ago2 recommendations

Systems programmingProgramming languagesCompilers and interpretersC++Performance and optimization

Hans Wennborg explores how Clang and LLVM optimize and compile C++ switch statements into lookup tables, bitmasks, and decision trees.

Are switch statements more efficient than if-else chains? How do they get optimized? This deep dive into Clang/LLVM's handling of the switch construct will tell you everything you wanted to know, and probably more. The event was kindly hosted by think-cell, think-cell.com Event page: meetup.com/stockholmcpp/events/304293099/ More information about C++ in Sweden and around the world at swedencpp.se

Why it's here

2 people recommend this

What people say. Recommended as an interesting deep dive into compiler optimizations for switch statements.

u/mttdin r/Compilers • Recommends

C++ Switch Statements Under the Hood in LLVM - Hans Wennborg

u/PeanutHungry5293in r/C_Programming • Recommends

On “Are switch statements faster than if statements?”

Very true! Because of the compiler optimizations like using lookup tables, bitmasking, and BSTs for switch statements, they are relatively faster than if-else statements most of the time. Also, depending on the compiler optimizations set, it might convert the if-else statements to switch statements if it thinks the switch statement is faster. [video An interesting video explaining a bunch of these compiler optimizations for the switch statement in the LLVM.