[AVX-512] Moving from a GPR to a k-register just to spill to memory should just spill via mov
, or just stay in a k-register
#110626
Labels
mov
, or just stay in a k-register
#110626
My real code compiles like so on Zen 4 and Zen 5: (Godbolt link, line 3158 in the source code, line 5165 in the assembly)
As you can see, we move
rcx
tok1
, and then spill that toqword ptr [rsp + 16]
, which we then immediately read back intok2
. Obviouslykmovq k1, rcx
+kmovq qword ptr [rsp + 16], k1
=>mov qword ptr [rsp + 16], rcx
, or, even better,kmovq k1, rcx
+kmovq qword ptr [rsp + 16], k1
+kmovq k2, qword ptr [rsp + 16]
=>kmovq k2, rcx
Then we do it again with a newer version of
rcx
that we did anand
with. 🤦It should just be:
I also think the GPR's that spilled to
qword ptr [rsp + 56]
andqword ptr [rsp + 72]
could probably have been spilled to a k-register instead.Could be:
Then we do:
Unfortunately I don't think I can make a small reproduction, because register spilling does not happen in trivial code.
Here is the unoptimized LLVM IR dump: https://gist.github.com/Validark/a19d2babb7955a54a456d0683e95f7d4
Here is the optimized LLVM IR dump: https://gist.github.com/Validark/fd231af0b28cf1bea193d07a18b6d52c
Thank you to whoever helps fix the register allocator!
‒ Validark
The text was updated successfully, but these errors were encountered: