Skip to content

cmd/compile: more boolean optimizations #17905

@randall77

Description

@randall77
func f(a *int, b *int) bool {
	if (a == nil) != (b == nil) {
		return false
	}
	return true
}

Compiles to:

	0x0000 00000 (tmp1.go:4)	MOVQ	"".a+8(FP), AX
	0x0005 00005 (tmp1.go:4)	TESTQ	AX, AX
	0x0008 00008 (tmp1.go:4)	SETNE	AL
	0x000b 00011 (tmp1.go:4)	XORL	$1, AX
	0x000e 00014 (tmp1.go:4)	MOVQ	"".b+16(FP), CX
	0x0013 00019 (tmp1.go:4)	TESTQ	CX, CX
	0x0016 00022 (tmp1.go:4)	SETNE	CL
	0x0019 00025 (tmp1.go:4)	XORL	$1, CX
	0x001c 00028 (tmp1.go:4)	CMPB	AL, CL
	0x001e 00030 (tmp1.go:4)	JEQ	38

SETNE/XORL can be replaced with SETEQ.
It might also be worthwhile to rewrite NeqB to XOR instead of SETNE/CMPB. Not sure it would help here, but it may in other places.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgePerformanceSuggestedIssues that may be good for new contributors looking for work to do.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions