]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: add recursive-invalidate Value method, use in expand_calls
authorDavid Chase <drchase@google.com>
Thu, 8 Apr 2021 16:44:05 +0000 (12:44 -0400)
committerDavid Chase <drchase@google.com>
Thu, 8 Apr 2021 20:26:47 +0000 (20:26 +0000)
This removes more unused values during transformation.
Leaving them in the tree can create type conflicts in OpArg* references.

Updates #40724.
Updates #44816.
Fixes #45417.

Change-Id: I07dcb7b4b2bf8d79e22e0543cb2fb52c2ececb96
Reviewed-on: https://go-review.googlesource.com/c/go/+/308589
Trust: David Chase <drchase@google.com>
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
src/cmd/compile/internal/ssa/expand_calls.go
src/cmd/compile/internal/ssa/value.go

index ede713f22ac2b8fcdef63b9e61abfc13498625f2..cb8b2eeec883e4f194145ee039cedeb571fc10ea 100644 (file)
@@ -1015,7 +1015,7 @@ func (x *expandState) rewriteArgs(v *Value, firstArg int) {
                        if x.debug {
                                x.Printf("...marking %v unused\n", a.LongString())
                        }
-                       a.reset(OpInvalid)
+                       a.invalidateRecursively()
                }
        }
 
@@ -1140,7 +1140,7 @@ func expandCalls(f *Func) {
                                        if x.debug {
                                                x.Printf("...marking %v unused\n", a.LongString())
                                        }
-                                       a.reset(OpInvalid)
+                                       a.invalidateRecursively()
                                }
                        }
                        if x.debug {
@@ -1343,6 +1343,9 @@ func expandCalls(f *Func) {
                if dupe == nil {
                        x.commonSelectors[sk] = v
                } else if x.sdom.IsAncestorEq(dupe.Block, v.Block) {
+                       if x.debug {
+                               x.Printf("Duplicate, make %s copy of %s\n", v, dupe)
+                       }
                        v.copyOf(dupe)
                } else {
                        // Because values are processed in dominator order, the old common[s] will never dominate after a miss is seen.
@@ -1361,7 +1364,7 @@ func expandCalls(f *Func) {
                        x.Printf("allOrdered[%d] = b%d, %s, uses=%d\n", i, b.ID, v.LongString(), v.Uses)
                }
                if v.Uses == 0 {
-                       v.reset(OpInvalid)
+                       v.invalidateRecursively()
                        continue
                }
                if v.Op == OpCopy {
@@ -1456,7 +1459,7 @@ func expandCalls(f *Func) {
                                v.SetArg(i, aa)
                                for a.Uses == 0 {
                                        b := a.Args[0]
-                                       a.reset(OpInvalid)
+                                       a.invalidateRecursively()
                                        a = b
                                }
                        }
index ba7f8c0300541c32a716eecb90ab8e67d28884d2..630e4814b99f1b38c182d684bb2b6c16f30de704 100644 (file)
@@ -348,6 +348,35 @@ func (v *Value) reset(op Op) {
        v.Aux = nil
 }
 
+// invalidateRecursively marks a value as invalid (unused)
+// and after decrementing reference counts on its Args,
+// also recursively invalidates any of those whose use
+// count goes to zero.
+//
+// BEWARE of doing this *before* you've applied intended
+// updates to SSA.
+func (v *Value) invalidateRecursively() {
+       if v.InCache {
+               v.Block.Func.unCache(v)
+       }
+       v.Op = OpInvalid
+
+       for _, a := range v.Args {
+               a.Uses--
+               if a.Uses == 0 {
+                       a.invalidateRecursively()
+               }
+       }
+
+       v.argstorage[0] = nil
+       v.argstorage[1] = nil
+       v.argstorage[2] = nil
+       v.Args = v.argstorage[:0]
+
+       v.AuxInt = 0
+       v.Aux = nil
+}
+
 // copyOf is called from rewrite rules.
 // It modifies v to be (Copy a).
 //go:noinline