• Keith Randall's avatar
    cmd/compile: don't let spills clobber arguments · 7eaa8efb
    Keith Randall authored
    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: 's avatarDavid Chase <drchase@google.com>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    7eaa8efb
issue23522.go 724 Bytes