From 6f5d77454e31be8af11a7e2bcda36d200fda07c5 Mon Sep 17 00:00:00 2001 From: David Chase Date: Thu, 29 Feb 2024 15:02:44 -0500 Subject: cmd/compile: add 0-sized-value simplification to copyelim The problem was caused by faulty handling of unSSA-able operations on zero-sized data in expand calls, but there is no point to operations on zero-sized data. This CL adds a simplify step to the first place in SSA where all values are processed and replaces anything producing a 0-sized struct/array with the corresponding Struct/Array Make0 operation (of the appropriate type). I attempted not generating them in ssagen, but that was a larger change, and also had bugs. This is simple and obvious. The only question is whether it would be worthwhile to do it earlier (in numberlines or phielem). Fixes #65808. Change-Id: I0a596b3d272798015e7bb6b1a20411241759fe0e Reviewed-on: https://go-review.googlesource.com/c/go/+/568258 Reviewed-by: Cuong Manh Le Reviewed-by: Keith Randall Reviewed-by: Keith Randall LUCI-TryBot-Result: Go LUCI --- src/cmd/compile/internal/ssa/copyelim.go | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src') diff --git a/src/cmd/compile/internal/ssa/copyelim.go b/src/cmd/compile/internal/ssa/copyelim.go index 17f65127ee..17471e3b5f 100644 --- a/src/cmd/compile/internal/ssa/copyelim.go +++ b/src/cmd/compile/internal/ssa/copyelim.go @@ -11,6 +11,17 @@ func copyelim(f *Func) { // of OpCopy) is a copy. for _, b := range f.Blocks { for _, v := range b.Values { + + // This is an early place in SSA where all values are examined. + // Rewrite all 0-sized Go values to remove accessors, dereferences, loads, etc. + if t := v.Type; (t.IsStruct() || t.IsArray()) && t.Size() == 0 { + if t.IsStruct() { + v.reset(OpStructMake0) + } else { + v.reset(OpArrayMake0) + } + } + copyelimValue(v) } } -- cgit v1.3-5-g9baa