Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/goPublic

cmd/compile: no BCE due to missing limits when comparing against len with delta=0 #76429

Labels
BugReportIssues describing a possible bug in the Go implementation.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.help wanted
Milestone
@fice-t

Description

@fice-t

Go version

go version go1.26-devel_337f7b1 Sat Nov 22 06:13:24 2025 -0800 linux/amd64

Output ofgo env in your module/workspace:

Workspace is`go.godbolt.org` on`x86-64 gc (tip)` as above.

What did you do?

[Code+output testedhere]

Compile these simplified examples:

functestReslice0(s []byte,kint)byte {ifk<0||k>=len(s) {return0    }s=s[k:]// Proved IsSliceInBoundsreturns[0]// bounds check!}functestReslice1(s []byte,kint)byte {ifk<0||k>len(s)-1 {return0    }s=s[k:]// Proved IsSliceInBounds + slicemask not needed (by limit)returns[0]// Proved IsInBounds}

What did you see happen?

testReslice0 has an extra bounds check (and slice mask) thattestReslice1 does not have.

What did you expect to see?

testReslice0 should not contain an extra bounds check, as0 <= k < len(s), meanings after slicing offk elements must still contain an element left fors[0] to succeed.

testReslice1 contains the following debug prove output thattestReslice0 does not have:

<source>:4:30: x+d >= w; x:v13 b2 delta:-1 w:-1 d:signed<source>:4:30: x+d >= w; x:v13 b2 delta:-1 w:0 d:signed<source>:7:10: Proved slicemask not needed (by limit)

It appears that when there is no subtraction involved, the limits are not detected and propagated to the slice mask operation and later. This may be due to optimizations added by the recently introduceddetectSliceLenRelation (@dr2chase) and/ordetectSubRelations (@randall77) that don't have an equivalent without the subtraction fromlen(s).

Solving this would, for example, eliminate an extra bounds check in the runtime'sdecoderune.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.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.help wanted

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp