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

Closed
dsnet opened this issue Mar 11, 2022 · 2 comments
Closed

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

dsnet opened this issue Mar 11, 2022 · 2 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Performance
Milestone

Comments

@dsnet
Copy link
Member

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 Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 14, 2022
@heschi heschi added this to the Backlog milestone Mar 14, 2022
@gopherbot
Copy link

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

@gopherbot
Copy link

Change https://go.dev/cl/402815 mentions this issue: cmd/compile: Rules to prove for better bound check elimination

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 13, 2022
@golang golang locked and limited conversation to collaborators Aug 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Performance
Projects
None yet
Development

No branches or pull requests

3 participants