cmd/compile: unnecessary bounds check for global slices #30529
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Performance
Milestone
Using
go1.12
Suppose we have a unexported global variable:
and none of the operations performed on this slice:
For example, operations like element assignment (e.g.,
mySlice[3] = ...
) and element addressing (e.g.,&mySlice[3]
) are permitted.If the above conditions are met, I believe that indexes into the slice below the initial size could have the bounds check elided since the index is provably not going to exceed the bounds.
The use case for this is code like:
We could use an array instead to avoid the bounds check, but that has other issues (see #30528).
The text was updated successfully, but these errors were encountered: