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/compile: reduce unnecessary register copies in regalloc #53599

Open
erifan opened this issue Jun 29, 2022 · 0 comments
Open

cmd/compile: reduce unnecessary register copies in regalloc #53599

erifan opened this issue Jun 29, 2022 · 0 comments
Labels
compiler/runtime NeedsInvestigation Performance
Milestone

Comments

@erifan
Copy link
Contributor

erifan commented Jun 29, 2022

The instructions generated by the Go compiler for the code below contain too many unnecessary register copies.

//go:noinline
func swap(x, y float64) (float64, float64) {
        if y > x {
                x, y = y, x
        }
        return x, y
}

The assembly instructions:

0x0000 00000 (p.go:9)   TEXT    main.swap(SB), LEAF|NOFRAME|ABIInternal, $0-16
0x0000 00000 (p.go:10)  FCMPD   F1, F0
0x0004 00004 (p.go:10)  BMI     20
0x0008 00008 (p.go:13)  FMOVD   F1, F2
0x000c 00012 (p.go:13)  FMOVD   F0, F1
0x0010 00016 (p.go:13)  FMOVD   F2, F0
0x0014 00020 (p.go:13)  FMOVD   F0, F2 
0x0018 00024 (p.go:13)  FMOVD   F1, F0
0x001c 00028 (p.go:13)  FMOVD   F2, F1
0x0020 00032 (p.go:13)  RET     (R30)

The expected instruction sequence:

0x0000 00000 (p.go:9)   TEXT    main.swap(SB), LEAF|NOFRAME|ABIInternal, $0-16
0x0000 00000 (p.go:10)  FCMPD   F1, F0
0x0004 00004 (p.go:10)  BPL     20
0x0008 00008 (p.go:13)  FMOVD   F1, F2
0x000c 00012 (p.go:13)  FMOVD   F0, F1
0x0010 00016 (p.go:13)  FMOVD   F2, F0
0x0020 00020 (p.go:13)  RET     (R30)
@cherrymui cherrymui added Performance NeedsInvestigation labels Jun 29, 2022
@cherrymui cherrymui added this to the Unplanned milestone Jun 29, 2022
@cherrymui cherrymui changed the title runtime: reduce unnecessary register copies in regalloc cmd/compile: reduce unnecessary register copies in regalloc Jun 29, 2022
@gopherbot gopherbot added the compiler/runtime label Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime NeedsInvestigation Performance
Projects
None yet
Development

No branches or pull requests

3 participants