From e46d586eddfdd2186d77a5e996bbd6415cfcf2f5 Mon Sep 17 00:00:00 2001 From: thepudds Date: Sat, 28 Jun 2025 16:53:37 -0400 Subject: cmd/compile/internal/escape: add debug hash for literal allocation optimizations Several CLs earlier in this stack added optimizations to reduce user allocations by recognizing and taking advantage of literals, including CL 649555, CL 649079, and CL 649035. This CL adds debug hashing of those changes, which enables use of the bisect tool, such as 'bisect -compile=literalalloc go test -run=Foo'. This also allows these optimizations to be manually disabled via '-gcflags=all=-d=literalallochash=n'. Updates #71359 Change-Id: I854f7742a6efa5b17d914932d61a32b2297f0c88 Reviewed-on: https://go-review.googlesource.com/c/go/+/675415 LUCI-TryBot-Result: Go LUCI Reviewed-by: David Chase Reviewed-by: Cherry Mui --- src/cmd/compile/internal/walk/order.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/cmd/compile/internal/walk') diff --git a/src/cmd/compile/internal/walk/order.go b/src/cmd/compile/internal/walk/order.go index 8ba8dd96cc..cb022faddf 100644 --- a/src/cmd/compile/internal/walk/order.go +++ b/src/cmd/compile/internal/walk/order.go @@ -246,14 +246,18 @@ func (o *orderState) addrTemp(n ir.Node) ir.Node { if v == nil { v = n } + optEnabled := func(n ir.Node) bool { + // Do this optimization only when enabled for this node. + return base.LiteralAllocHash.MatchPos(n.Pos(), nil) + } if (v.Op() == ir.OSTRUCTLIT || v.Op() == ir.OARRAYLIT) && !base.Ctxt.IsFIPS() { - if ir.IsZero(v) && 0 < v.Type().Size() && v.Type().Size() <= abi.ZeroValSize { + if ir.IsZero(v) && 0 < v.Type().Size() && v.Type().Size() <= abi.ZeroValSize && optEnabled(n) { // This zero value can be represented by the read-only zeroVal. zeroVal := ir.NewLinksymExpr(v.Pos(), ir.Syms.ZeroVal, n.Type()) vstat := typecheck.Expr(zeroVal).(*ir.LinksymOffsetExpr) return vstat } - if isStaticCompositeLiteral(v) { + if isStaticCompositeLiteral(v) && optEnabled(n) { // v can be directly represented in the read-only data section. lit := v.(*ir.CompLitExpr) vstat := readonlystaticname(n.Type()) -- cgit v1.3-5-g45d5