2 ms·
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 a
by thayne 4y ago
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.
- codeflo 4y agoThe 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.