Open
Description
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.