public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "user202729 at protonmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/110035] Missed optimization for dependent assignment statements
Date: Fri, 24 May 2024 07:50:02 +0000	[thread overview]
Message-ID: <bug-110035-4-27PZBiQvjt@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-110035-4@http.gcc.gnu.org/bugzilla/>

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.

      parent reply	other threads:[~2024-05-24  7:50 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-30  8:35 [Bug tree-optimization/110035] New: " ptk.prasertsuk at gmail dot com
2023-05-30 11:55 ` [Bug tree-optimization/110035] " rguenth at gcc dot gnu.org
2023-05-30 16:45 ` pinskia at gcc dot gnu.org
2023-05-30 17:22 ` pinskia at gcc dot gnu.org
2023-05-31  1:20 ` ptk.prasertsuk at gmail dot com
2023-05-31  1:46 ` ptk.prasertsuk at gmail dot com
2023-05-31  6:34 ` rguenther at suse dot de
2023-06-03  0:23 ` ptk.prasertsuk at gmail dot com
2023-06-05  7:16 ` rguenth at gcc dot gnu.org
2023-06-05  7:58 ` ptk.prasertsuk at gmail dot com
2023-06-05  8:11 ` rguenther at suse dot de
2023-06-06  5:46 ` ptk.prasertsuk at gmail dot com
2023-06-06  5:49 ` ptk.prasertsuk at gmail dot com
2023-06-06  8:17 ` rguenther at suse dot de
2023-06-06  8:29 ` rguenth at gcc dot gnu.org
2023-06-06  9:12 ` amonakov at gcc dot gnu.org
2023-06-06 11:54 ` rguenther at suse dot de
2024-05-24  7:50 ` user202729 at protonmail dot com [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-110035-4-27PZBiQvjt@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).