cmd/compile: inefficient code generation on amd64 #40426
Labels
FrozenDueToAge
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Performance
Probably, inefficient code generation on amd64.
Probably a slight regression in the performance of the resulting code beetween g.14.6 and master (8696ae8).
Preface
Examining the assembly code listing, I found out that the compiler generates sub-optimal code for some part of the code.
I will not describe the whole journey. I found a code (code from benchmark game) illustrating the problem and will use it for an example.
All source code: https://benchmarksgame-team.pages.debian.net/benchmarksgame/program/nbody-go-3.html
Let's pay attention to these lines (60, 61, 62), it's "advance" func:
Let's take a look at the result of the code generation:
We need one instruction to load the value of the left operand and two to calculate the address of the right one.
I rolled back to version go1.14 and found that the codegen there is different. For the same lines, the following code will be generated:
It uses one instruction to load both the left and right side of the expression.
How does it affect code performance?
It depends on how often such a code generation pattern is used in the code and in how hot the pieces of code are.
But we can write benchmark:
Results:
When did the issue start?
git bisect report beetween master(8696ae8) and go1.14:
Issue linked with changes - #36468
/cc @randall77
The text was updated successfully, but these errors were encountered: