Skip to content

cmd/compile: redundant branch #22025

@randall77

Description

@randall77
func f(x interface{}) bool {
	if x == nil {
		return false
	}
	switch x.(type) {
	case bool:
		return true
	default:
		return false
	}
}

Compiles to

	0x0000 00000 (/Users/khr/go/tmp4.go:3)	MOVQ	"".x+8(SP), AX
	0x0005 00005 (/Users/khr/go/tmp4.go:4)	TESTQ	AX, AX
	0x0008 00008 (/Users/khr/go/tmp4.go:4)	JEQ	47
	0x000a 00010 (/Users/khr/go/tmp4.go:7)	JEQ	41
        ...

That second branch is useless. We should get rid of it somehow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions