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
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FeatureRequest NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. ToolSpeed
Milestone

Comments

@josharian
Copy link
Contributor

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 dmitshur added FeatureRequest NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. ToolSpeed labels Jul 2, 2021
@dmitshur dmitshur added this to the Backlog milestone Jul 2, 2021
@dmitshur
Copy link
Contributor

dmitshur commented Jul 2, 2021

CC @randall77, @mdempsky via owners.

@mdempsky
Copy link
Member

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.

@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. FeatureRequest NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. ToolSpeed
Projects
Status: Triage Backlog
Development

No branches or pull requests

4 participants