From 56e0ecc5ea67c4cd71fe894bf9745f35273bcdea Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Tue, 15 Mar 2016 20:45:50 -0700 Subject: cmd/compile: keep value use counts in SSA Keep track of how many uses each Value has. Each appearance in Value.Args and in Block.Control counts once. The number of uses of a value is generically useful to constrain rewrite rules. For instance, we might want to prevent merging index operations into loads if the same index expression is used lots of times. But I have one use in particular for which the use count is required. We must make sure we don't combine ops with loads if the load has more than one use. Otherwise, we may split a single load into multiple loads and that breaks perceived behavior in the presence of races. In particular, the load of m.state in sync/mutex.go:Lock can't be done twice. (I have a separate CL which triggers the mutex failure. This CL has a test which demonstrates a similar failure.) Change-Id: Icaafa479239f48632a069d0c3f624e6ebc6b1f0e Reviewed-on: https://go-review.googlesource.com/20790 Run-TryBot: Keith Randall TryBot-Result: Gobot Gobot Reviewed-by: Todd Neal --- src/cmd/compile/internal/ssa/deadcode.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/cmd/compile/internal/ssa/deadcode.go') diff --git a/src/cmd/compile/internal/ssa/deadcode.go b/src/cmd/compile/internal/ssa/deadcode.go index 819f6de247..ae990026f5 100644 --- a/src/cmd/compile/internal/ssa/deadcode.go +++ b/src/cmd/compile/internal/ssa/deadcode.go @@ -164,6 +164,18 @@ func deadcode(f *Func) { } f.Names = f.Names[:i] + // Unlink values. + for _, b := range f.Blocks { + if !reachable[b.ID] { + b.SetControl(nil) + } + for _, v := range b.Values { + if !live[v.ID] { + v.resetArgs() + } + } + } + // Remove dead values from blocks' value list. Return dead // values to the allocator. for _, b := range f.Blocks { @@ -231,6 +243,7 @@ func (b *Block) removePred(p *Block) { if v.Op != OpPhi { continue } + v.Args[i].Uses-- v.Args[i] = v.Args[n] v.Args[n] = nil // aid GC v.Args = v.Args[:n] -- cgit v1.3