Open AGPX opened 2 months ago
It couldn't be reduced to that, at least not trivially. llvm-mos doesn't have an interprocedural register allocator; the set of registers used by Actor's constructor aren't available when Player's constructor is being compiled. To make that information available is actually pretty tricky if you think about it, since it would mean compiling functions in a very specific order. (There's a way to do this in LLVM, but it isn't very well maintained, and we haven't been able to turn it on yet.)
Accordingly, Player's constructor must assume Actor can clobber any caller-saved register, including rc2. It's thus not legal to refer to rc2 after the call. That's the reason for the spill.
As for why the spill does a redundant copy through rc4 and rc5, I'd suspect it's the usual "register allocation weirdness", but it's hard to tell. I'm admittedly not spending much time on most optimization issues these days; code gen quality isn't the most reported reason why llvm-mos is unsuitable for a given kind of project anymore. But eventually that will once again be the case, so I'll leave this open until I or someone else can get around to cleaning up all of these cases (as far as is possible).
Hi, I'm playing with the following C++code:
Compiled with -O3 and with the latest version of the compiler:
It could be hugely reduced to:
Is there some way to avoid this?