Skip to content

cmd/compile: constant indexing to private array should be folded #43403

Open
@egonelbre

Description

@egonelbre

Lookup tables are quite common, as in https://golang.org/src/math/bits/bits_tables.go. However none of functions that rely on those tables can be constant folded.

Simplest example is https://go.godbolt.org/z/MhMTqb which compiles to:

movblzx math/bits.rev8tab+12(SB), AX
movb    AL, "".~r0+8(SP)

The rev8tab only contains indexing to that table, so it should be possible to prove that the array is not being modified. Of course that only holds, when assignment, slicing or addressing operator is not used.

If such table is replaced with a string, then the constant folding does work. However, that seems like an ugly hack to have.

Related Issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsFixThe path to resolution is known, but the work has not been done.Performancecompiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions