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: missed phi elim opportunity using result of function call #47023

Open
josharian opened this issue Jul 2, 2021 · 2 comments
Open

cmd/compile: missed phi elim opportunity using result of function call #47023

josharian opened this issue Jul 2, 2021 · 2 comments

Comments

@josharian
Copy link
Contributor

@josharian josharian commented Jul 2, 2021

This is a reasonably common piece of code:

func isClosed(c chan struct{}) bool {
	select {
	case <-c:
		return true
	default:
		return false
	}
}

The core of it compiles to:

CALL	runtime.selectnbrecv(SB)
CMPB	16(SP), $0
JEQ	74
MOVB	$1, "".~r1+48(SP)
RET
MOVB	$0, "".~r1+48(SP)
RET

We should be able to use the result directly rather than branching.

@dmitshur
Copy link
Contributor

@dmitshur dmitshur commented Jul 2, 2021

@mdempsky
Copy link
Member

@mdempsky mdempsky commented Jul 2, 2021

I don't think it's specific to function calls. Even a function like:

func f(x bool) bool {
	if x {
		return true
	}
	return false
}

gets compiled with a branch.

Off hand, I don't know how to solve this. I suspect it needs a generalized form of common-tail merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants