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: unnecessary bounds check when indexing relative to the end #51622

Open
dsnet opened this issue Mar 11, 2022 · 1 comment
Open

cmd/compile: unnecessary bounds check when indexing relative to the end #51622

dsnet opened this issue Mar 11, 2022 · 1 comment
Labels
NeedsInvestigation Performance
Milestone

Comments

@dsnet
Copy link
Member

@dsnet dsnet commented Mar 11, 2022

Using go1.17.5

Consider the following:

len(b) >= 3 && b[len(b)-3] == '#'

Part of the assembly includes:

0x002f 00047 (main.go:6)	CALL	runtime.panicIndex(SB)

This should be unnecessary since the previous len(b) >= 3 check ensures that the buffer must contain the len(b)-3 element. Thus, there is no possibility of the index panicking.

\cc @martisch @randall77

@heschi heschi added the NeedsInvestigation label Mar 14, 2022
@heschi heschi added this to the Backlog milestone Mar 14, 2022
@gopherbot
Copy link

@gopherbot gopherbot commented May 14, 2022

Change https://go.dev/cl/406175 mentions this issue: cmd/compile: derive relation between x+delta and x in prove

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Performance
Projects
None yet
Development

No branches or pull requests

3 participants