https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110035

user202729 <user202729 at protonmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |user202729 at protonmail dot 
com

--- Comment #17 from user202729 <user202729 at protonmail dot com> ---
Created attachment 58280
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58280&action=edit
Possible patch to address the issue in case the intervening function is pure
instead of `operator new`.

I wrote a patch (attached) that allows the optimization to be performed if the
intervening function is pure instead of `operator new`.

With this patch, each of the functions in the following code will use only one
memory store instead of two.

```
#include <array>
#include <cstdint>

struct MyClass
{
        std::array<uint64_t, 2> arr;
};

// Prevent optimization
void sink(void *m) {
        asm volatile("" : : "g"(m) : "memory");
}

__attribute__((pure)) int f();

int g1(MyClass a)
{
        MyClass b;
        MyClass c = a;
        int result=f();
        b = c;
        sink(&b);
        return result;
}

int g2(MyClass a)
{
        MyClass b;
        MyClass c = a;
        int result=f();
        b = c;
        sink(&b);
        return result;
}

int g3(MyClass&& a)
{
        MyClass b;
        MyClass c = a;
        int result=f();
        b = c;
        sink(&b);
        return result;
}
```

It would be helpful if someone can review the patch.

Reply via email to