Skip to content

cmd/compile: some subsequent bounds checks are not eliminated #50365

@ghost

Description

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

$ go version
go version devel go1.18-088bb4b Tue Nov 2 06:25:39 2021 +0000 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?

https://go.dev/play/p/eyem-XNTdye
https://go.godbolt.org/z/bMTGW9E7W

What did you expect to see?

Since i and size are always positive numbers,

i*size+1 is not equal to zero and will be always greater than i*size, so

data[i*size]

check can be eliminated.

If i*size+1 overflows or i*size+1 >= len(data), data[i*size+1] will panic before accessing data[i*size].

What did you see instead?

Compiler emits two checks.

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

    Status

    Triage Backlog

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions