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 min #30584

Open
josharian opened this issue Mar 5, 2019 · 1 comment

Comments

@josharian
Copy link
Contributor

commented Mar 5, 2019

package p

func f(x, y []int) {
	n := len(x)
	if len(y) < n {
		n = len(y)
	}
	for i := 0; i < n; i++ {
		_ = x[i]
		_ = y[i]
	}
}

Ideally there would be no bounds checks in the loop. Right now there are.

This grew out of a conversation in CL 164966.

cc @rasky @aclements @zdjones

@josharian josharian added this to the Unplanned milestone Mar 5, 2019
@zdjones

This comment has been minimized.

Copy link
Contributor

commented Mar 26, 2019

I just took a preliminary peek, @josharian I think this may relate to #25086. Information from a non-control op (Phi) in a non-branching block is required to complete the inference from i back to len(x) and len(y).

This code:

n := len(x)
if len(y) < n {
	n = len(y)
}

concludes with a Plain SSA block containing just a Phi Op

b2: ← b3 b4
    v47 = Phi <int> v9 v8 (n[int])
Plain → b5

where v8/v9 are len(x)/len(y). This block doesn't branch, so prove doesn't use it. Without the relationship between v47 and len(x)/len(y), the inferential chain from i back to len(x) and len(y) is broken.

v8 = SliceLen <int> v6 (n[int])
v9 = SliceLen <int> v7
...
v47 = Phi <int> v9 v8 (n[int])
...
v16 = Less64 <bool> v14 v47
...
    v20 = IsInBounds <bool> v14 v8
...
    v30 = IsInBounds <bool> v14 v9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.