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: missed shift optimizations on amd64 #19681

Closed
brtzsnr opened this issue Mar 23, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@brtzsnr
Copy link
Contributor

commented Mar 23, 2017

Please answer these questions before submitting your issue. Thanks!

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

go version devel +ee80afe326 Tue Mar 21 21:19:47 2017 +0000 linux/amd64

What operating system and processor architecture are you using (go env)?

linux amd64

What did you do?

Compiled the following functions

func blah8a(s uint8) uint64 {
        return 1 << (s&63)
}

func blah8b(s uint8) uint64 {
        return 1 << uint(s&63)
}

func blah64(s uint64) uint64 {
        return 1 << uint(s&63)
}

What did you expect to see?

Same assembly code.

What did you see instead?

Assembly differs wildly. Only blah64 is completely optimized.

TEXT ·blah8a(SB), $0-16 // a.go:3
        MOVBLZX    s+0(FP), CX  // a.go:4
        ANDL       $63, CX
        MOVQ       $1, AX
        SHLQ       CX, AX
        MOVQ       AX, _r1+8(FP)
        RET

TEXT ·blah8b(SB), $0-16 // a.go:7
        MOVBLZX    s+0(FP), CX  // a.go:8
        ANDL       $63, CX
        MOVQ       $1, AX
        SHLQ       CX, AX
        CMPQ       CX, $64
        SBBQ       DX, DX
        ANDQ       DX, AX
        MOVQ       AX, _r1+8(FP)
        RET

TEXT ·blah64(SB), $0-16 // a.go:11
        MOVQ       s+0(FP), CX  // a.go:12
        MOVQ       $1, AX
        SHLQ       CX, AX
        MOVQ       AX, _r1+8(FP)
        RET

@gopherbot

This comment has been minimized.

Copy link

commented Mar 23, 2017

CL https://golang.org/cl/38550 mentions this issue.

@gopherbot gopherbot closed this in 3e63cdf Mar 24, 2017

@golang golang locked and limited conversation to collaborators Mar 24, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.