Open xTachyon opened 1 month ago
For the first idea, I'd expect codegen similar to this: https://godbolt.org/z/5M8jG5orf
I think what happens is that at the MIR level each call argument is a const operand and never stored into a temporary variable. As such no StorageLive and StorageDead MIR statements are emitted, which then results in LLVM never being told that the lifetime of the stack slots doesn't overlap.
Rustc emiting lifetime start/end would be great, but even without, I don't see why LLVM can't figure out by itself it can merge them. The function argument is nocapture, so the alloca should be dead after each call. At least that's my understanding of it.
Turns out LLVM does actually infer lifetime start/end intrinsics, yet still fails to overlap the stack slots.
I’m not sure if this is what you’re looking for: https://godbolt.org/z/qh8ov63hb. I don't know if this is an optimization.
https://godbolt.org/z/1foPhW5PT
Relevant bits:
I think all the allocas should've been merged in one, or be able to pass a pointer to a global const with the slice.