Skip to content
0:00 / 0:00

#llvm#switchlowering#clang

2015 LLVM Developers’ Meeting: Hans Wennborg "The recent switch lowering improvements"

LLVM

18K subscribers • 15 videos on Hallway

YouTube
  • Recommended by 2 people: 2 in engineering communities.
  • A classic. People kept recommending it from 2017 to 2024.
  • Presented by Hans Wennborg, Google
  • Linked in the descriptionSlides on llvm.org

Advanced. Deep dive for people who know the field.

847 views11 years ago2 recommendations

Systems programmingCompilers and interpretersPerformance and optimization

Hans Wennborg explains how LLVM's switch lowering was rewritten to generate balanced trees, find jump tables, and use profile information.

LLVM.org — The recent switch lowering improvements - Hans Wennborg, Google Slides: llvm.org/devmtg/2015-10/slides/Wennborg-SwitchLowering.pdf — Lightning Talk Earlier this year, the DAG switch lowering was rewritten to improve the performance of code generated for switches. The new algorithm always generates balanced trees, is better at finding jump tables, and can exploit profile information. This lightning talk would give a walk-through of the new switch lowering. — Videos Filmed & Edited by Bash Films: BashFilms.com

Why it's here

2 people recommend this

What people say. Recommended for details on how LLVM and Clang optimize switch statements under the hood.

u/mttdin r/ProgrammingLanguages • Recommends

On “CppCon 2017: Matt Godbolt “What Has My Compiler Done for Me Lately? Unbolting the Compiler's Lid” [video]”

…sented in this talk is broadly applicable / generally not specific to just the Mill architecture): http://millcomputing.com/docs/switches/ > If anyone knows any details about Clang/GCC internals I'm curious! I have honestly have very little idea what algorithms are used. - GCC: https://slideslive.com/38902416/switch-lowering-improvements - LLVM: link to this video / http://llvm.org/devmtg/2015-10/slides/Wennborg-SwitchLowering.pdf…

u/oilshellin r/ProgrammingLanguages • Recommends

On “Flexible and Economical UTF-8 Decoder”

Yes, search for "switch lowering" in LLVM. It's been done for a long time, though there is more going on in this code -- the human-optimized versions are very clever. https://llvm.org/pubs/2007-05-31-Switch-Lowering.html link to this video So I think the experiment you can do is go to https://godbolt.org/, and then type in a bunch of patterns like switch (byte) { case 0: return true; ... case 255: return false; } If you type in some "known patterns", it should eliminate all the branches and reduce to a closed-form formula e.g. it could be `bool(byte & 0x01)` or `bool(byte & 0xf)` for some simple cases. If you return integers, I think it should work too

u/_youtubot_in r/ProgrammingLanguages • Mentions

On “CppCon 2017: Matt Godbolt “What Has My Compiler Done for Me Lately? Unbolting the Compiler's Lid” [video]”

Video linked by /u/mttd: Title|Channel|Published|Duration|Likes|Total Views :----------:|:----------:|:----------:|:----------:|:----------:|:----------: [2015 LLVM Developers’ Meeting: Hans Wennborg "The recent switch lowering improvements"]|LLVM|2015-11-04|0:04:22|9+ (100%)|393 > http://www.LLVM.org — The recent switch lowering... --- ^Info ^| ^/u/mttd ^can ^delete ^| ^v2.0.0