Skip to content

cmd/compile: bounds check not needed #61333

Open
@KaurkerDevourer

Description

@KaurkerDevourer

https://godbolt.org/z/EW16jnEG7
As you can see, there is panicIndex, on s[I + j]. But in golang, for i := 0; I < len(s); I++ doesn't go into panicIndex. Why does

for i := 0; i < len(s) - len(t); i++ {
    for j := 0; j < len(t); j++ {
         s[i + j]
    }
}

calls panicIndex? There is no need in this. Compiler sees that i + j is always in range [0, len(s)). Easy optimisation, probably not only in this case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Performancecompiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions