]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: add "deadlocals" pass to remove unused locals
authorDavid Chase <drchase@google.com>
Wed, 22 May 2024 21:00:43 +0000 (14:00 -0700)
committerDavid Chase <drchase@google.com>
Tue, 30 Jul 2024 15:46:27 +0000 (15:46 +0000)
commitcc258e6785060345a497d44b6073c91b81e32576
tree4bdb034ed97cf4566d521a55868c332f0df28905
parent7b867b9bb7e7c20803a7168faaf9c87e11f88cef
cmd/compile: add "deadlocals" pass to remove unused locals

This CL adds a "deadlocals" pass, which runs after inlining and before
escape analysis, to prune any unneeded local variables and
assignments. In particular, this helps avoid unnecessary Addrtaken
markings from unreachable closures.

Deadlocals is sensitive to "_ = ..." as a signal of explicit
use for testing.  This signal occurs only if the entire
left-hand-side is "_" targets; if it is
  `_, ok := someInlinedFunc(args)`
then the first return value is eligible for dead code elimination.

Use this (`_ = x`) to fix tests broken by deadlocals elimination.

Includes a test, based on one of the tests that required modification.

Matthew Dempsky wrote this, changing ownership to allow rebases, commits, tweaks.

Fixes #65158.

Old-Change-Id: I723fb69ccd7baadaae04d415702ce6c8901eaf4e
Change-Id: I1f25f4293b19527f305c18c3680b214237a7714c
Reviewed-on: https://go-review.googlesource.com/c/go/+/600498
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: David Chase <drchase@google.com>
Commit-Queue: David Chase <drchase@google.com>
src/cmd/compile/internal/base/debug.go
src/cmd/compile/internal/deadlocals/deadlocals.go [new file with mode: 0644]
src/cmd/compile/internal/gc/main.go
src/runtime/race/testdata/mop_test.go
test/closure3.dir/main.go
test/fixedbugs/issue54159.go
test/inline.go
test/newinline.go