Day 4 of Advent of Compiler Optimisations!

Multiply by 2, 3, 4, 16, 25—which ones use the actual multiply instruction? Spoiler: fewer than you think! The compiler has a bag of tricks for avoiding multiplication, using shifts, adds, and that versatile LEA instruction. But when you outsmart it with your own shift-and-add... it un-optimises you right back!

Read more: xania.org/202512/04-multiplyin
Watch: youtu.be/1X88od0miHs

0

If you have a fediverse account, you can quote this note from your own instance. Search https://hachyderm.io/users/mattgodbolt/statuses/115661217585809139 on your instance and quote it. (Note that quoting is not supported in Mastodon.)