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: extra "xchgl al, al" instructions #38255

Closed
egonelbre opened this issue Apr 5, 2020 · 2 comments
Closed

cmd/compile: extra "xchgl al, al" instructions #38255

egonelbre opened this issue Apr 5, 2020 · 2 comments

Comments

@egonelbre
Copy link
Contributor

Noticed a case where compiler produces a repeated sequence of XCHGL AX, AX.

https://go.godbolt.org/z/_yJaga

What version of Go are you using (go version)?

$ go version
go version go1.14.1 windows/amd64

But also happens on

  • go1.13.9 and
  • go version devel +e31d741801 Fri Apr 3 17:51:12 2020 +0000 windows/amd64

What did you see?

Compiling https://play.golang.org/p/HfxglRpLB4A with go tool compile -S shows that the output contains a sequence:

        0x008c 00140 ($GOROOT\src\io\io.go:329) CALL    io.ReadAtLeast(SB)
        0x0091 00145 ($GOROOT\src\io\io.go:329) CMPQ    56(SP), $0
        0x0097 00151 (main.go:10)       JEQ     169
        0x0099 00153 (main.go:11)       PCDATA  $0, $-1
        0x0099 00153 (main.go:11)       PCDATA  $1, $-1
        0x0099 00153 (main.go:11)       MOVQ    144(SP), BP
        0x00a1 00161 (main.go:11)       ADDQ    $152, SP
        0x00a8 00168 (main.go:11)       RET
        0x00a9 00169 (main.go:16)       XCHGL   AX, AX
        0x00aa 00170 (main.go:19)       XCHGL   AX, AX
        0x00ab 00171 (main.go:22)       XCHGL   AX, AX
        0x00ac 00172 (main.go:25)       XCHGL   AX, AX
        0x00ad 00173 (main.go:28)       XCHGL   AX, AX
        0x00ae 00174 (main.go:31)       XCHGL   AX, AX
        0x00af 00175 (main.go:34)       XCHGL   AX, AX
        0x00b0 00176 (main.go:37)       XCHGL   AX, AX
        0x00b1 00177 ($GOROOT\src\encoding\binary\binary.go:78) PCDATA  $0, $1
        0x00b1 00177 ($GOROOT\src\encoding\binary\binary.go:78) PCDATA  $1, $3
        0x00b1 00177 ($GOROOT\src\encoding\binary\binary.go:78) MOVQ    ""..autotmp_80+136(SP), AX

I would expect that a single XCHGL AX, AX is sufficient.

@egonelbre
Copy link
Contributor Author

egonelbre commented Apr 5, 2020

It seems these are generated due to InlMark and are left together after "lowered deadcode for cse" pass.

Possibly related #29571

@randall77
Copy link
Contributor

Those are just the inline marks. We need so many because each represents a different inlining at a different source line.

Yes, this is a dup of #29571.

There are things we could do here, like put the inline marks out-of-line. But let's discuss that over at #29571.

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

3 participants