Skip to content

Commit

Permalink
cmd/compile: free value earlier in nilcheck
Browse files Browse the repository at this point in the history
When we remove a nil check, add it back to the free Value pool immediately.

Fixes #18732

Change-Id: I8d644faabbfb52157d3f2d071150ff0342ac28dc
Reviewed-on: https://go-review.googlesource.com/58810
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
  • Loading branch information
randall77 committed Aug 25, 2017
1 parent 3723d08 commit 770d8d8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/cmd/compile/internal/ssa/func.go
Expand Up @@ -175,14 +175,17 @@ func (f *Func) LogStat(key string, args ...interface{}) {
f.Warnl(f.Entry.Pos, "\t%s\t%s%s\t%s", n, key, value, f.Name)
}

// freeValue frees a value. It must no longer be referenced.
// freeValue frees a value. It must no longer be referenced or have any args.
func (f *Func) freeValue(v *Value) {
if v.Block == nil {
f.Fatalf("trying to free an already freed value")
}
if v.Uses != 0 {
f.Fatalf("value %s still has %d uses", v, v.Uses)
}
if len(v.Args) != 0 {
f.Fatalf("value %s still has %d args", v, len(v.Args))
}
// Clear everything but ID (which we reuse).
id := v.ID

Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/ssa/nilcheck.go
Expand Up @@ -126,7 +126,7 @@ func nilcheckelim(f *Func) {
f.Warnl(v.Pos, "removed nil check")
}
v.reset(OpUnknown)
// TODO: f.freeValue(v)
f.freeValue(v)
i--
continue
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/ssa/regalloc.go
Expand Up @@ -1569,7 +1569,7 @@ func (s *regAllocState) regalloc(f *Func) {
if s.f.pass.debug > regDebug {
fmt.Printf("delete copied value %s\n", c.LongString())
}
c.Args[0].Uses--
c.RemoveArg(0)
f.freeValue(c)
delete(s.copies, c)
progress = true
Expand Down

0 comments on commit 770d8d8

Please sign in to comment.