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: teach prove about arguments of & expressions #40083

Open
randall77 opened this issue Jul 6, 2020 · 0 comments
Open

cmd/compile: teach prove about arguments of & expressions #40083

randall77 opened this issue Jul 6, 2020 · 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

@randall77
Copy link
Contributor

package main

import "math/bits"

func f(x, y uint64) int {
	if x&y != 0 {
		return bits.TrailingZeros64(x)
	}
	return 0
}

The compiler could infer from x&y != 0 that x != 0 (and y != 0). It can use that here, for example, to get rid of the code that deals with the x==0 special case on x86.

This currently generates

	0x0000 00000 (/Users/khr/gowork/tmp1.go:6)	MOVQ	"".x+8(SP), AX
	0x0005 00005 (/Users/khr/gowork/tmp1.go:6)	MOVQ	"".y+16(SP), CX
	0x000a 00010 (/Users/khr/gowork/tmp1.go:6)	TESTQ	AX, CX
	0x000d 00013 (/Users/khr/gowork/tmp1.go:6)	JEQ	34
	0x000f 00015 (/Users/khr/gowork/tmp1.go:7)	BSFQ	AX, AX
	0x0013 00019 (/Users/khr/gowork/tmp1.go:7)	MOVL	$64, CX
	0x0018 00024 (/Users/khr/gowork/tmp1.go:7)	CMOVQEQ	CX, AX
	0x001c 00028 (/Users/khr/gowork/tmp1.go:7)	MOVQ	AX, "".~r2+24(SP)
	0x0021 00033 (/Users/khr/gowork/tmp1.go:7)	RET
	0x0022 00034 (/Users/khr/gowork/tmp1.go:9)	MOVQ	$0, "".~r2+24(SP)
	0x002b 00043 (/Users/khr/gowork/tmp1.go:9)	RET

We could get rid of the MOVL $64/CMOVQEQ pair.

@zdjones @rasky @josharian

@randall77 randall77 added this to the Unplanned milestone Jul 6, 2020
@dmitshur dmitshur added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 7, 2020
@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
None yet
Development

No branches or pull requests

3 participants