Skip to content

inconsistent copy propagation for aggregates across calls with local alloc #141309

Open
@pinskia

Description

@pinskia

Take:

struct f {
    int a[1024];
};

void g();
struct f hh();

struct f h(float *fp) {
    struct f a;
    a = hh();
    struct f b = a;
    g();
    *fp = 1;
    a = b;
    return a;
}

struct f h1(float *fp) {
    struct f a = hh();
    struct f b = a;
    g();
    *fp = 1;
    a = b;
    return a;
}

These 2 functions should produce the exact same code generation. The only difference between then is where the assignment to a happens; on the decl initializer or outside of it.
h produces better code generation than h1; h1 has 2 calls to memcpy while h has 0.
https://godbolt.org/z/GfMq96rTY for reference.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions