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: sometimes issue rematerializable values early #24930

josharian opened this issue Apr 18, 2018 · 0 comments

cmd/compile: sometimes issue rematerializable values early #24930

josharian opened this issue Apr 18, 2018 · 0 comments


Copy link

@josharian josharian commented Apr 18, 2018

package p

var (
	s *int
	b bool

func f() {
	var q *int
	if b {
		q = new(int)
	} else {
		q = new(int)
	s = q

This code is a bit silly, but it's the smallest reproduction I have handy. :)

When compiled, this code tests b, and on each branch it contains an LEAQ of The LEAQ should be hoisted above the branch, since it is needed immediately in each case, and there are registers to spare.

The CSE pass does its work, and there is a single LEAQ instruction going into regalloc. However, early in regalloc, we decide to issue it every place we need it:

			if s.values[v.ID].rematerializeable {
				// Value is rematerializeable, don't issue it here.
				// It will get issued just before each use (see
				// allocValueToReg).
				for _, a := range v.Args {

This is usually the right decision--disabling this bit of code causes an overall regression. But as the initial code shows, there are instances in which it'd be better to issue the rematerializable value right away. I'm not sure exactly what the right set of conditions is, though.

cc @cherrymui @randall77

@josharian josharian added this to the Unplanned milestone Apr 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant