From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 2B99F3858D35; Mon, 27 May 2024 03:07:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2B99F3858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1716779259; bh=ImsWtQZ192oU4+DJB2Xy8Y7fDeqeMF3lALOC8yZiAek=; h=From:To:Subject:Date:In-Reply-To:References:From; b=NuJc5wNqXeP5fTgl9oSDgXOPk0PckPMZEB1zZIFWAIYJfoz5VpsHQROw6YpW0LNd6 pNljyXHqL/Nv/ZMnZZLLtr+wJhBgwNpi+3tVuFT2aG8iCrT3rhcH13q5aap1BXPVYC qcTDebYnsXUhxVJ1ph5IhGhV6BcXqzSJBuZi5sEc= From: "user202729 at protonmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/110137] implement clang -fassume-sane-operator-new Date: Mon, 27 May 2024 03:07:38 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: user202729 at protonmail dot com X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc attachments.created Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D110137 user202729 changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |user202729 at protonmail d= ot com --- Comment #6 from user202729 --- Created attachment 58293 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D58293&action=3Dedit Proposed implementation. I've implement it. (Attached patch) It would be helpful if someone can revi= ew it. Some notes: 1. Clang's documentation says the effect of `-fassume-sane-operator-new` is= to assume no-alias, but it is pointed out that Clang also assumes no-side-effe= ct. So I explicitly state that in the documentation. 2. The original intent is to fix https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D110035 . While this patch alone is insufficient to fix that (as explained in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D110035#c17 ), it would be sufficient to improve the performance of the following (to only load from global memory once): ``` int a; // Prevent optimization void sink(void *m) { asm volatile("" : : "g"(m) : "memory"); } int f(){ int x=3Da; float* z=3Dnew float; int y=3Da; int result=3Dx+y; sink(z); return result; } ``` 3. I'm not sure which additional optimizations can be done if we know somet= hing is pure, but this would improve that one case. Other cases can be added lat= er on.=