]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: don't let spills clobber arguments
authorKeith Randall <khr@google.com>
Tue, 23 Jan 2018 21:06:21 +0000 (13:06 -0800)
committerKeith Randall <khr@golang.org>
Tue, 23 Jan 2018 21:51:55 +0000 (21:51 +0000)
commit7eaa8efbe4bb63ca486aab61f83287dd4bf1d609
tree14a8b608e3707d249e7edd4f28f38f8d3005e31f
parentf27a1ff2c8ba1dce874e76d0b82c059b38a731d3
cmd/compile: don't let spills clobber arguments

The compiler allows code to have multiple differently-typed views of a
single argument. For instance, if we have

func f(x float64) {
   y := *(*int64)(unsafe.Pointer(&x))
   ...
}

Then in SSA we get two OpArg ops, one with float64 type and one with
int64 type.

The compiler will try to reuse argument slots for spill slots. It
checks that the argument slot is dead by consulting an interference
graph.

When building the interference graph, we normally ignore cross-type
edges because the values on either end of that edge can't be allocated
to the same slot. (This is just a space-saving optimization.) This
rule breaks down when one of the values is an argument, because of the
multiple views described above. If we're spilling a float64, it is not
enough that the float64 version of x is dead; the int64 version of x
has to be dead also.

Remove the optimization of not recording interference edges if types
don't match. That optimization is incorrect if one of the values
connected by the edge is an argument.

Fixes #23522

Change-Id: I361f85d80fe3bc7249014ca2c3ec887c3dc30271
Reviewed-on: https://go-review.googlesource.com/89335
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
src/cmd/compile/internal/ssa/stackalloc.go
test/fixedbugs/issue23522.go [new file with mode: 0644]