At least for those two examples it works, but perhaps you have other constraints that weren’t expressed in the original post.
Back to the allocations, I had a look at both the generated Julia and LLVM IR with Cthulhu. It appears that replacing -x
with a different operation (e.g. sin(x)
) has the same outcome. Yet I’m only able to see one allocation at either the Julia or LLVM level. It feels like this is somehow hitting some compiler heuristic, but I can’t figure out what.