Skip to content

Store to potentially aliasing pointer causes LLVM to forget previously stored value #145399

Open
@Kmeakin

Description

@Kmeakin

The second load of x is redundant because, even if y aliases with x, the final value will still be z

https://godbolt.org/z/GKdPrPj6T

int src(int* x, int* y, int z) {
    *x = z;
    *y = z;
    return *x;
}

int tgt(int* x, int* y, int z) {
    *x = z;
    *y = z;
    return z;
}
src:
        str     w2, [x0]
        str     w2, [x1]
        ldr     w0, [x0]
        ret

tgt:
        str     w2, [x0]
        mov     w0, w2
        str     w2, [x1]
        ret

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions