Skip to content

cmd/compile: early loop rotation #77089

@Jorropo

Description

@Jorropo
go version go1.26-devel_e7c0b74a97 Tue Jan 6 20:29:01 2026 +0100 linux/amd64

We do loop rotation extremely late.
Consider this loop:

 for range c {
  a()
 }

We will compile to this (pseudo-code):

 i := c
goto check
loop:
 a()
 i--
check:
 if i != 0 { goto loop }

The "classical" form would be*:

 if c == 0 { goto skip }
 i := c
loop:
 a()
 i--
 if i != 0 { goto loop }
skip:

*reversing iteration order of loops isn't classic, but it's not what I want to point out.

Metadata

Metadata

Assignees

Labels

ImplementationIssues describing a semantics-preserving change to 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.

Type

No type

Projects

Status

Todo

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions