Skip to content

air, codegen: copy elision #64

@coderkalyan

Description

@coderkalyan

Currently, air supports any type (including aggregates) as temporaries. Codegen lowers all aggregates to the stack, which results in some redundant intermediates being created.

For example, the code let mut slice = array[start..end] creates two allocas: the first one is the temporary to store the slicing result of array[start..end], and the second is the mutable stack slot for the slice variable. The backend then generates a copy (unrolled gep + load + store for slices, memcpy for arrays) between the two allocas. This problem doesn't currently happen when slice is constant, because no stack slot is created. However, for mut slices, we should find a way to elide the copy, and intialize the rvalue directly into the mut variable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions