Aliasing
xania.org·12h·
Discuss: Hacker News
🚀Compiler Optimizations
Preview
Report Post

Written by me, proof-read by an LLM. Details at end.

Yesterday we ended on a bit of a downer: aliasing stopped optimisations dead in their tracks. I know this is supposed to be the Advent of Compiler Optimisations, not the Advent of Compiler Giving Up! Knowing why your compiler can’t optimise is just as important as knowing all the clever tricks it can pull off.

Let’s take a simple example of a counter class1. It accumulates integers into a member variable total. I’ve used C++ templates to show two versions of the code: one that accumulates in an int and one that accumulates in an long.

At first glance, the two loop bodies look almost identical, as you might expect. In one case we’ll accumulate in `e…

Similar Posts

Loading similar posts...