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: cannot elim binary search typeHash on a type switch for a known type #48220

Open
wdvxdr1123 opened this issue Sep 7, 2021 · 0 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Performance
Milestone

Comments

@wdvxdr1123
Copy link
Contributor

wdvxdr1123 commented Sep 7, 2021

In cmd/compile/internal/walk/switch.go, gc rewrites type switch into a binary search for typeHash and some type assertions.
The SSA backend can correctly eliminate the type assertions for a known type, but can't eliminate the binary search.

What did you do?

package a

func test(y int) int {
	var x = interface{}(y)
	var a = 1
	switch x.(type) {
	case int:
		a = 2
	case string:
		a = 3
	case int32:
		a = 4
	default:
		a = 5
	}
	return a
}

What did you expect to see?

00000 (3) TEXT "".test(SB), ABIInternal
    MOVL $2, AX
    RET

What did you see instead?

00000 (3) TEXT "".test(SB), ABIInternal
00001 (3) FUNCDATA $0, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
00002 (3) FUNCDATA $1, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
00003 (3) FUNCDATA $5, "".test.arginfo1(SB)
00004 (+6) MOVL type.int+16(SB), CX
00005 (6) CMPL CX, $-1146273534
00006 (6) JEQ 13
00007 (6) CMPL CX, $-520135500
00008 (6) JEQ 13
00009 (6) CMPL CX, $-145526278
00010 (6) JNE 13
00011 (+6) MOVL $2, AX
00012 (6) JMP 14
00013 (6) MOVL $5, AX
00014 (+16) RET
00015 (?) END
@ALTree ALTree changed the title cmd/compile: cannot elim binary search typeHash on a type switch for a known type. cmd/compile: cannot elim binary search typeHash on a type switch for a known type Sep 7, 2021
@thanm thanm added this to the Backlog milestone Sep 7, 2021
@cagedmantis cagedmantis added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 13, 2021
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or 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 Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Performance
Projects
Status: Triage Backlog
Development

No branches or pull requests

4 participants