Issue 129233
Summary [clang] reference gets unnecessarily loaded twice
Labels clang
Assignees
Reporter M-Kusumgar
    test assembly: https://godbolt.org/z/TWdvPPGYs

```c++
#include <stdint.h>
struct foo {
    const uint64_t& x;
    void f();

 uint64_t g() {
        uint64_t y = x;
        f();
        return y * x;
    }
};

uint64_t h(foo* x) {
    return x->g();
}
```

the reference to x gets loaded twice vs

expected assembly: https://godbolt.org/z/rW39W6h1e

```c++
#include <stdint.h>

struct foo {
    const uint64_t& x;
    void f();

    uint64_t g() {
        auto& tmp = x;
        uint64_t y = tmp;
        f();
        return y * tmp;
 }
};

uint64_t h(foo* x) {
    return x->g();
}
```
the reference to x gets loaded once. shouldn't the compiler be able to optimise the first code block into the assembly produced by the second code block?
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to