Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
cmd/compile: weird asymmetry in when constants get registers #33580
What version of Go are you using (
Looks like this kind of depends on luck of the draw. The results of the ANDQ must go into one of the input registers. If the register allocator picks the constant input, then that constant must be reloaded when it is used again. If it picks the variable input, then the constant is still in a register for the next use.
There's code in there to pick the input that is dead over the one that isn't. For some reason that code isn't doing the right thing. We'll look at this for 1.14.
Ohhh, interesting. I had been thinking of this as two separate issues -- one being reloading the constant for each set of uses, one being reloading it immediately for two consecutive uses -- but if the constant were inclined to stick around, it'd probably end up getting loaded once and used eight times, which would presumably affect performance at all.
Some of what's happening seems to be that the two sets of operations (one on the first four words, one on the second four words) are written interleaved, but the compiler quite reasonably collates them. Which I assume reduces register pressure, but also means that all the uses of a given constant aren't together.
There's some other weird stuff in here; moving the constant declarations to right above where they're used almost always makes them not get registers. I doubt that's related, but who knows, maybe it is.