• Michael Munday's avatar
    cmd/compile: add some generic composite type optimizations · f31a18de
    Michael Munday authored
    Propagate values through some wide Zero/Move operations. Among
    other things this allows us to optimize some kinds of array
    initialization. For example, the following code no longer
    requires a temporary be allocated on the stack. Instead it
    writes the values directly into the return value.
    
    func f(i uint32) [4]uint32 {
        return [4]uint32{i, i+1, i+2, i+3}
    }
    
    The return value is unnecessarily cleared but removing that is
    probably a task for dead store analysis (I think it needs to
    be able to match multiple Store ops to wide Zero ops).
    
    In order to reliably remove stack variables that are rendered
    unnecessary by these new rules I've added a new generic version
    of the unread autos elimination pass.
    
    These rules are triggered more than 5000 times when building and
    testing the standard library.
    
    Updates #15925 (fixes for arrays of up to 4 elements).
    Updates #24386 (fixes for up to 4 kept elements).
    Updates #24416.
    
    compilebench results:
    
    name       ol...
    f31a18de
stack.go 2.32 KB