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: unnecessary zero-extension of booleans on arm64 #21445

philhofer opened this issue Aug 14, 2017 · 1 comment

cmd/compile: unnecessary zero-extension of booleans on arm64 #21445

philhofer opened this issue Aug 14, 2017 · 1 comment


Copy link

@philhofer philhofer commented Aug 14, 2017

Given the following Go code

func f(c int) int {
    ret := 0
    if c < 0 {
        ret = 1
    return ret

the compiler generates

genssa f
        00000 (/home/phil/test.go:7)    TEXT    "".f(SB)
        00001 (/home/phil/test.go:7)    FUNCDATA        $0, gclocals·f207267fbf96a0178e8758c6e3e0ce28(SB)
        00002 (/home/phil/test.go:7)    FUNCDATA        $1, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
v7      00003 (/home/phil/test.go:7)    MOVD    "".c(RSP), R0
v9      00004 (/home/phil/test.go:9)    CMP     $0, R0
v8      00005 (/home/phil/test.go:9)    CSET    LT, R0
v10     00006 (/home/phil/test.go:12)   MOVBU   R0, R0
v13     00007 (/home/phil/test.go:12)   MOVD    R0, "".~r1+8(RSP)
b3      00008 (/home/phil/test.go:12)   RET
        00009 (<unknown line number>)   END

The MOVBU after the CSET is unnecessary. CSET sets the whole register.

This is an easy rewrite rule fix.


This comment has been minimized.

Copy link

@gopherbot gopherbot commented Aug 15, 2017

Change mentions this issue: cmd/compile: emit unnecessary boolean zero extension on arm64

philhofer added a commit to philhofer/go that referenced this issue Aug 15, 2017
On arm64, all boolean-generating instructions (CSEL, etc.) set the upper
63 bits of the destination register to zero, so there is no need
to zero-extend the lower 8 bits again.

Fixes golang#21445

Change-Id: I3b176baab706eb684105400bacbaa24175f721f3
@dsnet dsnet added the Performance label Aug 15, 2017
@gopherbot gopherbot closed this in 07ec438 Aug 21, 2017
@golang golang locked and limited conversation to collaborators Aug 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.