golang/go

cmd/compile: x86-64: sub-optimal codegen less-than-int sized index from structured slice/array

Open

#74,489 建立於 2025年7月7日

在 GitHub 查看
 (6 留言) (0 反應) (0 負責人)Go (133,883 star) (19,008 fork)batch import
BugReportNeedsInvestigationPerformancecompiler/runtimehelp wanted

描述

Go version

go version go1.25-devel_6c3b5a2 Thu Jul 3 18:43:56 2025 -0700 linux/amd64

Output of go env in your module/workspace:

Using service on https://go.godbolt.org/
Selected "x86-64 gc (tip)"

What did you do?

I entered following program

package main

func Foo(a [][4]byte, b []int, i int) int {
	return b[a[i][1]]
}

func main() {
}

https://go.godbolt.org/z/hfvezofxf

What did you see happen?

Codegen for a[i][1] part was following:

        LEAQ    (AX)(R9*4), DX
        LEAQ    1(DX), DX
        MOVBLZX (DX), AX

What did you expect to see?

One-line codegen like MOVBLZX 1(AX)(R9*4), AX was expected

The compiler really worked very hard to optimize codegen regarding various element size of slice a. However, it seems that it missed simple case - when the element size is 2, 4 or 8.

貢獻者指南

cmd/compile: x86-64: sub-optimal codegen less-than-int sized index from structured slice/array · golang/go#74489 | Good First Issue