]> Cypherpunks repositories - gostls13.git/commit
cmd/compile/internal: merge stack slots for selected local auto vars
authorThan McIntosh <thanm@google.com>
Thu, 28 Dec 2023 14:26:34 +0000 (14:26 +0000)
committerThan McIntosh <thanm@google.com>
Fri, 29 Mar 2024 23:09:29 +0000 (23:09 +0000)
commit89f7805c2e1ec3a1f708957ca8f43b04f3f2834f
tree45654419d3718cddbd87cb6bbb9c7e569f0a5f16
parent754f870381ef5e2c60c0edd4f902e7063ffb4452
cmd/compile/internal: merge stack slots for selected local auto vars

Preliminary compiler support for merging/overlapping stack
slots of local variables whose access patterns are disjoint.

This patch includes changes in AllocFrame to do the actual
merging/overlapping based on information returned from a new
liveness.MergeLocals helper. The MergeLocals helper identifies
candidates by looking for sets of AUTO variables that either A) have
the same size and GC shape (if types contain pointers), or B) have the
same size (but potentially different types as long as those types have
no pointers). Variables must be greater than (3*types.PtrSize) in size
to be considered for merging.

After forming candidates, MergeLocals collects variables into "can be
overlapped" equivalence classes or partitions; this process is driven
by an additional liveness analysis pass. Ideally it would be nice to
move the existing stackmap liveness pass up before AllocFrame
and "widen" it to include merge candidates so that we can do just a
single liveness as opposed to two passes, however this may be difficult
given that the merge-locals liveness has to take into account
writes corresponding to dead stores.

This patch also required a change to the way ssa.OpVarDef pseudo-ops
are generated; prior to this point they would only be created for
variables whose type included pointers; if stack slot merging is
enabled then the ssagen code creates OpVarDef ops for all auto vars
that are merge candidates.

Note that some temporaries created late in the compilation process
(e.g. during ssa backend) are difficult to reason about, especially in
cases where we take the address of a temp and pass it to the runtime.
For the time being we mark most of the vars created post-ssagen as
"not a merge candidate".

Stack slot merging for locals/autos is enabled by default if "-N" is
not in effect, and can be disabled via "-gcflags=-d=mergelocals=0".

Fixmes/todos/restrictions:
- try lowering size restrictions
- re-evaluate the various skips that happen in SSA-created autotmps

Fixes #62737.
Updates #65532.
Updates #65495.

Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest
Change-Id: Ibc22e8a76c87e47bc9fafe4959804d9ea923623d
Reviewed-on: https://go-review.googlesource.com/c/go/+/553055
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
14 files changed:
src/cmd/compile/internal/base/debug.go
src/cmd/compile/internal/base/flag.go
src/cmd/compile/internal/base/hashdebug.go
src/cmd/compile/internal/ir/name.go
src/cmd/compile/internal/liveness/mergelocals.go [new file with mode: 0644]
src/cmd/compile/internal/liveness/plive.go
src/cmd/compile/internal/ssa/check.go
src/cmd/compile/internal/ssa/func.go
src/cmd/compile/internal/ssagen/pgen.go
src/cmd/compile/internal/ssagen/ssa.go
src/cmd/compile/internal/test/mergelocals_test.go [new file with mode: 0644]
src/cmd/compile/internal/test/testdata/mergelocals/integration.go [new file with mode: 0644]
src/cmd/compile/internal/walk/temp.go
test/fixedbugs/bug385_64.go