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: tighten CFG as well as values #24177

Open
josharian opened this issue Feb 28, 2018 · 0 comments
Open

cmd/compile: tighten CFG as well as values #24177

josharian opened this issue Feb 28, 2018 · 0 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. Performance
Milestone

Comments

@josharian
Copy link
Contributor

func f(x int, b bool) int {
	if x < 0 {
		x *= -1
	}
	if b {
		return x
	}
	return 0
}

The compiled code for f matches the input closely: It checks x < 0, negates it if so, then checks b.

But we only need to check and modify x if b is true. The compiler should rewrite this code into:

func f(x int, b bool) int {
	if b {
		if x < 0 {
			x *= -1
		}
		return x
	}
	return 0
}

This is similar to the tighten pass, but instead of operating on values, it should operate on subsections of the CFG. Similar to the tighten pass, it should avoid moving work into a loop.

Among other things, this would help avoid doing needless work when the return value of copy is unused; see https://go-review.googlesource.com/c/go/+/94596.

Marking 1.11 optimistically, although I have no plans to work on this myself.

cc @randall77 @dr2chase @cherrymui

@josharian josharian added this to the Go1.11 milestone Feb 28, 2018
@bradfitz bradfitz modified the milestones: Go1.11, Unplanned May 18, 2018
@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. Performance
Projects
None yet
Development

No branches or pull requests

3 participants