News for hackers. Stuff that matters.
Re:Speedup from switch to += by thayne on Sunday September 11, 2022 @11:45PM (#32805861)
For composite structures that isn't too surprising, but for scalars, I would have expected llvm to optimize the addition and assignment into a single in place addition.
Re:Speedup from switch to += by codeflo on Monday September 12, 2022 @02:47AM (#32806833)
The short answer is yes.

The long answer is that it’s not so clear what an “in place addition” even means at the level of CPU instructions after you consider register allocation. For example, if you have

    v = x;
    v += y;
    f(v);
and the never mention v again, then the whole operation is performed directly in the register that is specified to receive the first argument in a function call, not in whatever register might have been allocated for v.

That’s because, with some complications I don’t want to go into, compilers look at the dependency graph of values rather than at the variable names.