cmd/compile: weird asymmetry in when constants get registers #33580
Labels
FrozenDueToAge
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Performance
Milestone
What version of Go are you using (
go version
)?1.12.
Does this issue reproduce with the latest release?
Seems to.
What operating system and processor architecture are you using (
go env
)?amd64
What did you do?
STUPID THINGS. I got hypnotized by trying to mess with the code for a bit of bit-swizzling in order to improve compiler output. A helpful person in #performance on gopher slack pointed out that the compiler did a better job with constants if you assigned them to variables, and indeed, this is so.
Sometimes.
https://godbolt.org/z/ISgMpH
In this code, the relevant bits are four constants:
and some assignments to them:
and then a bunch of code using those values.
The code ends at line 174 of the assembly with both lines uncommented, or only the second uncommented. If the first is uncommented, it ends at line 160. But what's going on appears to be non-obvious; uncommenting that line isn't necessarily replacing instances of that value in the code with register references. If you split it out, each of the two "hi" values appears to cause a reduction of about 7 lines of code. Uncommenting the "lo" values has no effect.
Changing which value is which, or which kinds of shifts each value is used with, doesn't seem to change this, nor does changing the order they're used in. So it's not the sign bit, it's not "is used with left (or right) shifts", it's not "the one that gets used first gets priority"... I have no idea why they behave differently.
What did you expect to see?
I would expect the lines to have essentially interchangeable effects.
What did you see instead?
Lots of repeated loads of some values but not others.
The text was updated successfully, but these errors were encountered: