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: prove bounds for & of positive values #38717

Closed
bmkessler opened this issue Apr 28, 2020 · 3 comments
Closed

cmd/compile: prove bounds for & of positive values #38717

bmkessler opened this issue Apr 28, 2020 · 3 comments
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done. Performance
Milestone

Comments

@bmkessler
Copy link
Contributor

What version of Go are you using (go version)?

$ go version
go version go1.14.2 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

What did you do?

Compile

package main

func test(foo []byte, i int) {
	_ = foo[63]
	r := i & 63
	_ = foo[r]
}

func main() {}

go build -gcflags="-d=ssa/check_bce/debug=1"

What did you expect to see?

Just the first bounds check for the initial length of the slice

./test.go:4:9: Found IsInBounds

Because prove should be able to deduce that the masked value is bounded by 63 and so is already in bounds.

r := i&m && m >= 0 --> 0 <= r <= m

What did you see instead?

Both accesses require a bounds check.

./test.go:4:9: Found IsInBounds
./test.go:6:9: Found IsInBounds

This is related to #38476

@rasky @josharian @zdjones

@zdjones
Copy link
Contributor

zdjones commented Apr 28, 2020

I think this is because prove doesn't make inferences inolving bitwise operations. I have some CLs I've neglected, to which I could hope to someday add inference over bitwise operations (my employer eliminated our 20% time).

@andybons andybons added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 28, 2020
@andybons andybons added this to the Unplanned milestone Apr 28, 2020
@andybons andybons added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Apr 28, 2020
@randall77 randall77 added NeedsFix The path to resolution is known, but the work has not been done. Performance labels Apr 26, 2022
@gopherbot gopherbot removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 26, 2022
@greatroar
Copy link

@randall77 I suppose this is fixed by 1efe387?

@randall77
Copy link
Contributor

Yes, I believe it is.

@golang golang locked and limited conversation to collaborators May 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done. Performance
Projects
None yet
Development

No branches or pull requests

6 participants