From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 45DE73858010; Wed, 23 Feb 2022 22:35:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 45DE73858010 From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/104665] Failure to recognize memcpy Date: Wed, 23 Feb 2022 22:35:16 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: unknown X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: pinskia at gcc dot gnu.org 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: bug_status cf_reconfirmed_on bug_severity everconfirmed 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Feb 2022 22:35:16 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104665 Andrew Pinski changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Last reconfirmed| |2022-02-23 Severity|normal |enhancement Ever confirmed|0 |1 --- Comment #3 from Andrew Pinski --- A couple of reasons. First is store merging happens too late. Second reason is store merging does not work in the loop case. Take: #if 1 enum b : unsigned char{}; #else typedef unsigned char b; #endif void serialize_le(b* __restrict dst, const unsigned* __restrict src) { // for (int i =3D 0; i < 128; ++i, ++src) { unsigned t =3D *src; *dst++ =3D static_cast((t >> 0) & 0xff); *dst++ =3D static_cast((t >> 8) & 0xff); *dst++ =3D static_cast((t >> 16) & 0xff); *dst++ =3D static_cast((t >> 24) & 0xff); } } This gets optimized to one load followed by one store. But once you add the loop, and use -fno-tree-vectorize (because GCC's vectorizer gets kicked in which causes other issues), the stores are not merged into one. Also store merging happens way after loop distrubution happens so ...=