Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/internal: add align directive to enhance performance #14935

Closed
laboger opened this issue Mar 23, 2016 · 7 comments
Closed

cmd/internal: add align directive to enhance performance #14935

laboger opened this issue Mar 23, 2016 · 7 comments

Comments

@laboger
Copy link
Contributor

laboger commented Mar 23, 2016

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)?
    go version devel +baec148 Wed Mar 23 14:21:15 2016 +0000 linux/ppc64
  2. What operating system and processor architecture are you using (go env)?
    linux ppc64le
  3. What did you do?
    If possible, provide a recipe for reproducing the error.
    A complete runnable program is good.
    A link on play.golang.org is best.

As a result of some performance analysis it was found that some code generated
as a result of plan9 asm does not perform as well as it could because the high use
loops do not have the preferred alignment with respect to the icache.

I have a change to add a new opcode(a directive actually) to indicate that the code stream should be aligned to a certain value at that point. That way the directive can be inserted before a significant loop and allow the loop body to remain in the icache during execution resulting in better performance.

@minux
Copy link
Member

minux commented Mar 23, 2016 via email

@dr2chase
Copy link
Contributor

Note that current SSA policy for judged-rare if-thens is (I am pretty sure, been looking at code just today) is to branch to the end, then branch back, which would introduce a lot of alignments where they'd not be that profitable and might just take up space. (This might have an annoying effect on linear-scan register allocation, I need to look into that).

@ianlancetaylor
Copy link
Contributor

I note for the record that GCC has the following options:

  • -falign-functions aligns the start of functions
  • -falign-labels aligns all labels
  • -falign-loops aligns the start of loops
  • -falign-jumps aligns labels that can only be reached by jumps

Surprisingly, GCC does not have -falign-likely-jumps, which would align all labels that can be reached only by jumps, ignoring jumps considered to be unlikely. That is probably the option we want by default, along with -falign-loops.

@laboger
Copy link
Contributor Author

laboger commented Mar 24, 2016

I agree with the previous concern about backward branches. Perhaps there is a way to mark the branch targets that were the result of backward branches before any kind of code straightening or rearranging was done by SSA?

.

@dr2chase
Copy link
Contributor

I think the original suggestion of a new opcode is not a bad one. The SSA code that does the (de-)straightening knows where the loops are. If we do profiling, that will be even better information (that will be useful for everything from block ordering to register allocation, never mind label alignment).

@laboger
Copy link
Contributor Author

laboger commented Mar 24, 2016

With an opcode/directive there could be a field that specified the alignment, which would make it more flexible.

@gopherbot
Copy link

Change https://golang.org/cl/144218 mentions this issue: cmd/asm/internal,cmd/internal/obj: add alignment directive to asm for ppc64x

@golang golang locked and limited conversation to collaborators Oct 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants